3#include "util/prometheus/MetricBase.hpp"
4#include "util/prometheus/OStream.hpp"
5#include "util/prometheus/impl/AnyCounterBase.hpp"
12namespace util::prometheus {
20template <SomeNumberType NumberType>
22 using ValueType = NumberType;
32 template <impl::SomeCounterImpl ImplType = impl::CounterImpl<ValueType>>
33 requires std::same_as<ValueType, typename std::remove_cvref_t<ImplType>::ValueType>
36 , impl::AnyCounterBase<ValueType>(std::forward<ImplType>(impl))
48 this->pimpl_->add(ValueType{1});
60 this->pimpl_->add(ValueType{-1});
73 this->pimpl_->add(
value);
86 this->pimpl_->add(-
value);
98 this->pimpl_->set(
value);
106 [[nodiscard]] ValueType
109 return this->pimpl_->value();
127using GaugeInt = AnyGauge<std::int64_t>;
132using GaugeDouble = AnyGauge<double>;
Base class for a Prometheus metric containing a name and labels.
Definition MetricBase.hpp:12
MetricBase(std::string name, std::string labelsString)
Construct a new MetricBase object.
Definition MetricBase.cpp:11
std::string const & name() const
Get the name of the metric.
Definition MetricBase.cpp:48
std::string const & labelsString() const
Get the labels of the metric in serialized format, e.g. {name="value",name2="value2"}...
Definition MetricBase.cpp:54
A stream that can optionally compress its data.
Definition OStream.hpp:12
Definition AnyCounterBase.hpp:13
A prometheus gauge metric implementation. It can be increased, decreased or set to a value.
Definition Gauge.hpp:21
void set(ValueType const value)
Set the gauge to the given value.
Definition Gauge.hpp:96
AnyGauge & operator--()
Decrease the gauge by one.
Definition Gauge.hpp:58
AnyGauge & operator++()
Increase the gauge by one.
Definition Gauge.hpp:46
AnyGauge & operator-=(ValueType const value)
Decrease the gauge by the given value.
Definition Gauge.hpp:84
AnyGauge & operator+=(ValueType const value)
Increase the gauge by the given value.
Definition Gauge.hpp:71
void serializeValue(OStream &stream) const override
Serialize the counter to a string in prometheus format (i.e. name{labels} value).
Definition Gauge.hpp:118
ValueType value() const
Definition Gauge.hpp:107
AnyGauge(std::string name, std::string labelsString, ImplType &&impl=ImplType{})
Construct a new AnyGauge object.
Definition Gauge.hpp:34