6 #ifndef KAGOME_CORE_METRICS_IMPL_PROMETHEUS_REGISTRY_IMPL_HPP 7 #define KAGOME_CORE_METRICS_IMPL_PROMETHEUS_REGISTRY_IMPL_HPP 9 #include <forward_list> 13 #include <type_traits> 15 #include <prometheus/counter.h> 16 #include <prometheus/family.h> 17 #include <prometheus/gauge.h> 18 #include <prometheus/histogram.h> 19 #include <prometheus/registry.h> 20 #include <prometheus/summary.h> 34 using type = prometheus::Counter;
35 using dtype = PrometheusCounter;
36 static const unsigned index = 0;
40 struct MetricInfo<Counter> {
41 using type = prometheus::Counter;
42 using dtype = PrometheusCounter;
43 static const unsigned index = 0;
47 struct MetricInfo<Gauge> {
48 using type = prometheus::Gauge;
49 using dtype = PrometheusGauge;
50 static const unsigned index = 1;
54 struct MetricInfo<Histogram> {
55 using type = prometheus::Histogram;
56 using dtype = PrometheusHistogram;
57 static const unsigned index = 2;
61 struct MetricInfo<Summary> {
62 using type = prometheus::Summary;
63 using dtype = PrometheusSummary;
64 static const unsigned index = 3;
73 std::unordered_map<std::string,
74 std::reference_wrapper<prometheus::Collectable>>
77 std::tuple<std::forward_list<PrometheusCounter>,
78 std::forward_list<PrometheusGauge>,
79 std::forward_list<PrometheusHistogram>,
80 std::forward_list<PrometheusSummary>>
86 const std::string &help =
"",
87 const std::map<std::string, std::string> &labels = {}) {
90 prometheus::detail::Builder<
typename MetricInfo<T>::type>()
94 .Register(*registry().
get()));
97 template <
typename T,
typename... Args>
99 const std::map<std::string, std::string> &labels,
102 dynamic_cast<prometheus::Family<typename MetricInfo<T>::type
> &>(
103 family_.at(name).get())
104 .Add(labels, args...);
105 return &std::get<MetricInfo<T>::index>(metrics_).emplace_front(
109 static std::shared_ptr<prometheus::Registry>
registry() {
110 static auto registry = std::make_shared<prometheus::Registry>();
117 void setHandler(
Handler &handler)
override;
119 void registerCounterFamily(
120 const std::string &name,
121 const std::string &help,
122 const std::map<std::string, std::string> &labels)
override;
124 void registerGaugeFamily(
125 const std::string &name,
126 const std::string &help,
127 const std::map<std::string, std::string> &labels)
override;
129 void registerHistogramFamily(
130 const std::string &name,
131 const std::string &help,
132 const std::map<std::string, std::string> &labels)
override;
134 void registerSummaryFamily(
135 const std::string &name,
136 const std::string &help,
137 const std::map<std::string, std::string> &labels)
override;
139 Counter *registerCounterMetric(
140 const std::string &name,
141 const std::map<std::string, std::string> &labels)
override;
143 Gauge *registerGaugeMetric(
144 const std::string &name,
145 const std::map<std::string, std::string> &labels)
override;
148 const std::string &name,
149 const std::vector<double> &bucket_boundaries,
150 const std::map<std::string, std::string> &labels)
override;
152 Summary *registerSummaryMetric(
153 const std::string &name,
154 const std::vector<std::pair<double, double>> &quantiles,
155 std::chrono::milliseconds max_age,
157 const std::map<std::string, std::string> &labels)
override;
160 template <
typename T>
168 #endif // KAGOME_CORE_METRICS_IMPL_PROMETHEUS_REGISTRY_IMPL_HPP static MetricInfo< T >::type * internalMetric(T *metric)
an interface to add request handler for metrics::Exposer implementation generally will contain metric...
std::tuple< std::forward_list< PrometheusCounter >, std::forward_list< PrometheusGauge >, std::forward_list< PrometheusHistogram >, std::forward_list< PrometheusSummary > > metrics_
static std::shared_ptr< prometheus::Registry > registry()
A histogram metric to represent aggregatable distributions of events.
void registerFamily(const std::string &name, const std::string &help="", const std::map< std::string, std::string > &labels={})
kagome::api::Method< Request, AuthorApi > Handler
A summary metric samples observations over a sliding window of time.
T * registerMetric(const std::string &name, const std::map< std::string, std::string > &labels, Args...args)
std::unordered_map< std::string, std::reference_wrapper< prometheus::Collectable > > family_
A gauge metric to represent a value that can arbitrarily go up and down.
A counter metric to represent a monotonically increasing value.
the class stores metrics, provides interface to create metrics and families of metrics TODO(sanblch) ...