3#include "util/log/Logger.hpp"
4#include "util/prometheus/Bool.hpp"
5#include "util/prometheus/Counter.hpp"
6#include "util/prometheus/Gauge.hpp"
7#include "util/prometheus/Histogram.hpp"
8#include "util/prometheus/Label.hpp"
9#include "util/prometheus/MetricBase.hpp"
10#include "util/prometheus/MetricsFamily.hpp"
17#include <unordered_map>
34 : isEnabled_(
isEnabled), compressReplyEnabled_(compressReply)
53 std::optional<std::string> description = std::nullopt
68 std::optional<std::string> description = std::nullopt
83 std::optional<std::string> description = std::nullopt
98 std::optional<std::string> description = std::nullopt
113 std::optional<std::string> description = std::nullopt
129 std::vector<std::int64_t>
const& buckets,
130 std::optional<std::string> description = std::nullopt
146 std::vector<double>
const& buckets,
147 std::optional<std::string> description = std::nullopt
177 return compressReplyEnabled_;
182 bool compressReplyEnabled_;
206 std::optional<std::string> description = std::nullopt
218 counterInt(std::string name,
Labels labels, std::optional<std::string> description)
override;
229 counterDouble(std::string name,
Labels labels, std::optional<std::string> description)
override;
240 gaugeInt(std::string name,
Labels labels, std::optional<std::string> description)
override;
251 gaugeDouble(std::string name,
Labels labels, std::optional<std::string> description)
override;
266 std::vector<std::int64_t>
const& buckets,
267 std::optional<std::string> description = std::nullopt
283 std::vector<double>
const& buckets,
284 std::optional<std::string> description = std::nullopt
298 getMetricsFamily(std::string name, std::optional<std::string> description,
MetricType type);
304 std::optional<std::string> description,
308 template <
typename ValueType>
309 requires std::same_as<ValueType, std::int64_t> || std::same_as<ValueType, double>
314 std::optional<std::string> description,
316 std::vector<ValueType>
const& buckets
319 std::unordered_map<std::string, MetricsFamily> metrics_;
358 std::optional<std::string> description = std::nullopt
373 std::optional<std::string> description = std::nullopt
388 std::optional<std::string> description = std::nullopt
403 std::optional<std::string> description = std::nullopt
418 std::optional<std::string> description = std::nullopt
434 std::vector<std::int64_t>
const& buckets,
435 std::optional<std::string> description = std::nullopt
451 std::vector<double>
const& buckets,
452 std::optional<std::string> description = std::nullopt
487 replaceInstance(std::unique_ptr<util::prometheus::PrometheusInterface> inst);
498 static std::unique_ptr<util::prometheus::PrometheusInterface> impl;
Singleton class to access the PrometheusInterface.
Definition Prometheus.hpp:327
static bool compressReplyEnabled()
Whether to compress the reply.
Definition Prometheus.cpp:289
static void replaceInstance(std::unique_ptr< util::prometheus::PrometheusInterface > inst)
Replace the prometheus object stored in the singleton.
Definition Prometheus.cpp:295
static util::prometheus::CounterInt & counterInt(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get an integer based counter metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:211
static util::prometheus::HistogramDouble & histogramDouble(std::string name, util::prometheus::Labels labels, std::vector< double > const &buckets, std::optional< std::string > description=std::nullopt)
Get a double based histogram metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:264
static util::prometheus::PrometheusInterface & instance()
Get the prometheus object stored in the singleton.
Definition Prometheus.cpp:301
static util::prometheus::CounterDouble & counterDouble(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get a double based counter metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:221
static util::prometheus::Bool boolMetric(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get a bool based metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:201
static bool isInitialised()
Whether the singleton has been already initialised.
Definition Prometheus.cpp:195
static void init(util::config::ClioConfigDefinition const &config)
Initialize the singleton with the given configuration.
Definition Prometheus.cpp:186
static util::prometheus::GaugeDouble & gaugeDouble(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get a double based gauge metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:241
static util::prometheus::HistogramInt & histogramInt(std::string name, util::prometheus::Labels labels, std::vector< std::int64_t > const &buckets, std::optional< std::string > description=std::nullopt)
Get an integer based histogram metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:251
static std::string collectMetrics()
Collect all metrics and return them as a string in Prometheus format.
Definition Prometheus.cpp:277
static bool isEnabled()
Whether prometheus is enabled.
Definition Prometheus.cpp:283
static util::prometheus::GaugeInt & gaugeInt(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get an integer based gauge metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:231
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
Class representing a collection of Prometheus labels.
Definition Label.hpp:41
Base class for a Prometheus metric containing a name and labels.
Definition MetricBase.hpp:12
Class representing a collection of Prometheus metric with the same name and type.
Definition MetricsFamily.hpp:20
Implementation of PrometheusInterface.
Definition Prometheus.hpp:190
CounterInt & counterInt(std::string name, Labels labels, std::optional< std::string > description) override
Get an integer based counter metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:46
HistogramInt & histogramInt(std::string name, Labels labels, std::vector< std::int64_t > const &buckets, std::optional< std::string > description=std::nullopt) override
Get an integer based histogram metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:85
GaugeInt & gaugeInt(std::string name, Labels labels, std::optional< std::string > description) override
Get an integer based gauge metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:68
GaugeDouble & gaugeDouble(std::string name, Labels labels, std::optional< std::string > description) override
Get a double based gauge metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:76
std::string collectMetrics() override
Collect all metrics and return them as a string in Prometheus format.
Definition Prometheus.cpp:121
Bool boolMetric(std::string name, Labels labels, std::optional< std::string > description=std::nullopt) override
Get a bool based metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:39
HistogramDouble & histogramDouble(std::string name, Labels labels, std::vector< double > const &buckets, std::optional< std::string > description=std::nullopt) override
Get a double based histogram metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:103
PrometheusInterface(bool isEnabled, bool compressReply)
Construct a new Prometheus Interface object.
Definition Prometheus.hpp:33
CounterDouble & counterDouble(std::string name, Labels labels, std::optional< std::string > description) override
Get a double based counter metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:55
Interface for prometheus (https://prometheus.io/).
Definition Prometheus.hpp:25
virtual std::string collectMetrics()=0
Collect all metrics and return them as a string in Prometheus format.
bool isEnabled() const
Whether prometheus is enabled.
Definition Prometheus.hpp:164
virtual Bool boolMetric(std::string name, Labels labels, std::optional< std::string > description=std::nullopt)=0
Get a bool based metric. It will be created if it doesn't exist.
virtual CounterInt & counterInt(std::string name, Labels labels, std::optional< std::string > description=std::nullopt)=0
Get an integer based counter metric. It will be created if it doesn't exist.
bool compressReplyEnabled() const
Whether to compress the reply.
Definition Prometheus.hpp:175
virtual CounterDouble & counterDouble(std::string name, Labels labels, std::optional< std::string > description=std::nullopt)=0
Get a double based counter metric. It will be created if it doesn't exist.
virtual GaugeDouble & gaugeDouble(std::string name, Labels labels, std::optional< std::string > description=std::nullopt)=0
Get a double based gauge metric. It will be created if it doesn't exist.
virtual GaugeInt & gaugeInt(std::string name, Labels labels, std::optional< std::string > description=std::nullopt)=0
Get an integer based gauge metric. It will be created if it doesn't exist.
virtual HistogramInt & histogramInt(std::string name, Labels labels, std::vector< std::int64_t > const &buckets, std::optional< std::string > description=std::nullopt)=0
Get an integer based histogram metric. It will be created if it doesn't exist.
PrometheusInterface(bool isEnabled, bool compressReply)
Construct a new Prometheus Interface object.
Definition Prometheus.hpp:33
virtual HistogramDouble & histogramDouble(std::string name, Labels labels, std::vector< double > const &buckets, std::optional< std::string > description=std::nullopt)=0
Get a double based histogram metric. It will be created if it doesn't exist.
Prometheus metrics: counters, gauges, histograms and their registry and serialization.
Definition Bool.hpp:12
AnyCounter< std::uint64_t > CounterInt
A prometheus counter metric implementation with a value of type std::int64_t.
Definition Counter.hpp:114
AnyCounter< double > CounterDouble
A prometheus counter metric implementation with a value of type double.
Definition Counter.hpp:119
AnyBool< GaugeInt > Bool
Alias for Prometheus bool metric with GaugeInt implementation.
Definition Bool.hpp:74
AnyGauge< std::int64_t > GaugeInt
Alias for a gauge with a 64-bit integer value.
Definition Gauge.hpp:127
MetricType
The kind and value type of a Prometheus metric.
Definition MetricBase.hpp:72
AnyHistogram< double > HistogramDouble
Histogram of floating point values.
Definition Histogram.hpp:135
AnyGauge< double > GaugeDouble
Alias for a gauge with a double value.
Definition Gauge.hpp:132
AnyHistogram< std::int64_t > HistogramInt
Histogram of integer values.
Definition Histogram.hpp:134