22#include "util/Assert.hpp"
23#include "util/prometheus/MetricBase.hpp"
24#include "util/prometheus/OStream.hpp"
25#include "util/prometheus/impl/AnyCounterBase.hpp"
32namespace util::prometheus {
39template <SomeNumberType NumberType>
41 using ValueType = NumberType;
51 template <impl::SomeCounterImpl ImplType = impl::CounterImpl<ValueType>>
52 requires std::same_as<ValueType, typename std::remove_cvref_t<ImplType>::ValueType>
55 , impl::AnyCounterBase<ValueType>(std::forward<ImplType>(impl))
67 this->pimpl_->add(ValueType{1});
81 ASSERT(
value >= 0,
"Cannot decrease a counter");
82 this->pimpl_->add(
value);
94 ASSERT(
value >= this->
value(),
"Cannot decrease a counter {}", this->
name());
95 this->pimpl_->set(
value);
104 this->pimpl_->set(ValueType{0});
115 return this->pimpl_->value();
133using CounterInt = AnyCounter<std::uint64_t>;
138using CounterDouble = AnyCounter<double>;
Base class for a Prometheus metric containing a name and labels.
Definition MetricBase.hpp:31
std::string const & name() const
Get the name of the metric.
Definition MetricBase.cpp:67
std::string const & labelsString() const
Get the labels of the metric in serialized format, e.g. {name="value",name2="value2"}...
Definition MetricBase.cpp:73
A stream that can optionally compress its data.
Definition OStream.hpp:31
Definition AnyCounterBase.hpp:32
A prometheus counter metric implementation. It can only be increased or be reset to zero.
Definition Counter.hpp:40
void reset()
Reset the counter to zero.
Definition Counter.hpp:102
ValueType value() const
Get the value of the counter.
Definition Counter.hpp:113
void set(ValueType value)
Set the value of the counter.
Definition Counter.hpp:92
AnyCounter & operator++()
Increase the counter by one.
Definition Counter.hpp:65
void serializeValue(OStream &stream) const override
Serialize the counter to a string in prometheus format (i.e. name{labels} value)
Definition Counter.hpp:124
AnyCounter(std::string name, std::string labelsString, ImplType &&impl=ImplType{})
Construct a new AnyCounter object.
Definition Counter.hpp:53
AnyCounter & operator+=(ValueType const value)
Increase the counter by the given value.
Definition Counter.hpp:79