/proc/self/cwd/source/extensions/filters/network/mongo_proxy/mongo_stats.cc
Line | Count | Source |
1 | | #include "source/extensions/filters/network/mongo_proxy/mongo_stats.h" |
2 | | |
3 | | #include <memory> |
4 | | #include <string> |
5 | | #include <vector> |
6 | | |
7 | | #include "envoy/stats/scope.h" |
8 | | |
9 | | #include "source/common/stats/symbol_table.h" |
10 | | |
11 | | namespace Envoy { |
12 | | namespace Extensions { |
13 | | namespace NetworkFilters { |
14 | | namespace MongoProxy { |
15 | | |
16 | | MongoStats::MongoStats(Stats::Scope& scope, absl::string_view prefix, |
17 | | const std::vector<std::string>& commands) |
18 | | : scope_(scope), stat_name_set_(scope.symbolTable().makeSet("Mongo")), |
19 | | prefix_(stat_name_set_->add(prefix)), callsite_(stat_name_set_->add("callsite")), |
20 | | cmd_(stat_name_set_->add("cmd")), collection_(stat_name_set_->add("collection")), |
21 | | multi_get_(stat_name_set_->add("multi_get")), |
22 | | reply_num_docs_(stat_name_set_->add("reply_num_docs")), |
23 | | reply_size_(stat_name_set_->add("reply_size")), |
24 | | reply_time_ms_(stat_name_set_->add("reply_time_ms")), |
25 | | time_ms_(stat_name_set_->add("time_ms")), query_(stat_name_set_->add("query")), |
26 | | scatter_get_(stat_name_set_->add("scatter_get")), total_(stat_name_set_->add("total")), |
27 | 2.62k | unknown_command_(stat_name_set_->add("unknown_command")) { |
28 | | |
29 | 210k | for (const auto& cmd : commands) { |
30 | 210k | stat_name_set_->rememberBuiltin(cmd); |
31 | 210k | } |
32 | 2.62k | } |
33 | | |
34 | 21.6k | Stats::ElementVec MongoStats::addPrefix(const Stats::ElementVec& names) { |
35 | 21.6k | Stats::ElementVec names_with_prefix; |
36 | 21.6k | names_with_prefix.reserve(1 + names.size()); |
37 | 21.6k | names_with_prefix.push_back(prefix_); |
38 | 21.6k | names_with_prefix.insert(names_with_prefix.end(), names.begin(), names.end()); |
39 | 21.6k | return names_with_prefix; |
40 | 21.6k | } |
41 | | |
42 | 17.4k | void MongoStats::incCounter(const Stats::ElementVec& names) { |
43 | 17.4k | Stats::Utility::counterFromElements(scope_, addPrefix(names)).inc(); |
44 | 17.4k | } |
45 | | |
46 | | void MongoStats::recordHistogram(const Stats::ElementVec& names, Stats::Histogram::Unit unit, |
47 | 4.13k | uint64_t sample) { |
48 | 4.13k | Stats::Utility::histogramFromElements(scope_, addPrefix(names), unit).recordValue(sample); |
49 | 4.13k | } |
50 | | |
51 | | } // namespace MongoProxy |
52 | | } // namespace NetworkFilters |
53 | | } // namespace Extensions |
54 | | } // namespace Envoy |