3#include "util/Assert.hpp"
4#include "util/prometheus/MetricBase.hpp"
5#include "util/prometheus/OStream.hpp"
6#include "util/prometheus/impl/AnyCounterBase.hpp"
13namespace 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});
62 ASSERT(
value >= 0,
"Cannot decrease a counter");
63 this->pimpl_->add(
value);
75 ASSERT(
value >= this->
value(),
"Cannot decrease a counter {}", this->
name());
76 this->pimpl_->set(
value);
85 this->pimpl_->set(ValueType{0});
96 return this->pimpl_->value();
114using CounterInt = AnyCounter<std::uint64_t>;
119using CounterDouble = AnyCounter<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 counter metric implementation. It can only be increased or be reset to zero.
Definition Counter.hpp:21
void reset()
Reset the counter to zero.
Definition Counter.hpp:83
ValueType value() const
Definition Counter.hpp:94
void set(ValueType value)
Set the value of the counter.
Definition Counter.hpp:73
AnyCounter & operator++()
Increase the counter by one.
Definition Counter.hpp:46
void serializeValue(OStream &stream) const override
Serialize the counter to a string in prometheus format (i.e. name{labels} value).
Definition Counter.hpp:105
AnyCounter(std::string name, std::string labelsString, ImplType &&impl=ImplType{})
Construct a new AnyCounter object.
Definition Counter.hpp:34
AnyCounter & operator+=(ValueType const value)
Increase the counter by the given value.
Definition Counter.hpp:60