prom 0.1.0
Client-independent C++23 Prometheus/OpenMetrics metric abstraction
Loading...
Searching...
No Matches
Public Member Functions | List of all members
prom::Counter Class Reference

A counter. More...

#include <counter.hpp>

Inheritance diagram for prom::Counter:
Inheritance graph
[legend]
Collaboration diagram for prom::Counter:
Collaboration graph
[legend]

Public Member Functions

 Counter (const std::string_view name, const std::string_view help)
 Standalone, unbound counter. Binds to the default adapter on first use.
 
 Counter (const CounterSpec &spec)
 Standalone counter from a spec (unbound).
 
 Counter (std::shared_ptr< MetricCore > core)
 Internal: adopt a core prepared by a Registry or labels().
 
void inc () const noexcept
 Increment by one.
 
template<class T >
requires std::is_arithmetic_v<T>
void inc (T amount) noexcept
 Increment by a raw arithmetic amount (must be >= 0 and finite).
 
template<DimensionalValue V>
void inc (const V &amount) noexcept
 Increment by a dimensional amount; its unit is reconciled with the metric's declared/latched unit.
 
Counter labels (const Labels &dynamic) const noexcept
 A same-type child series bound to dynamic labels (overlaid on the family's constant labels by the backend).
 
- Public Member Functions inherited from prom::MetricBase< Counter >
std::string_view name () const noexcept
 The metric's fully-qualified name.
 
MetricType type () const noexcept
 The metric kind.
 

Additional Inherited Members

- Protected Member Functions inherited from prom::MetricBase< Counter >
 MetricBase (const MetricType type, const std::string_view name, const std::string_view help)
 Standalone, unbound construction from a name and help string.
 
 MetricBase (std::shared_ptr< MetricCore > core)
 Adopt an already-populated core (registered metrics and children).
 
 MetricBase (const MetricBase &)=default
 
 MetricBase (MetricBase &&)=default
 
MetricBaseoperator= (const MetricBase &)=default
 
MetricBaseoperator= (MetricBase &&)=default
 
 ~MetricBase ()=default
 
Binding bind () const noexcept
 Resolve the adapter and backend handle this metric should record against.
 
const std::shared_ptr< MetricCore > & core () const noexcept
 
Counter make_child (const Labels &dynamic) const noexcept
 Resolve a labeled child of the same metric type.
 
bool reconcile_unit (const Unit &observed, Adapter &adapter) const noexcept
 Reconcile an observed unit against the family's known unit.
 
bool check_finite (const double value, std::string_view op) const noexcept
 Drop-and-log guard for a non-finite sample.
 
- Static Protected Member Functions inherited from prom::MetricBase< Counter >
static spdlog::logger * logger () noexcept
 The shared per-process metrics logger.
 
- Protected Attributes inherited from prom::MetricBase< Counter >
std::shared_ptr< MetricCorecore_
 

Detailed Description

A counter.

Only ever moves forward; negative or non-finite increments are dropped and logged. Values may be raw arithmetic or dimensional (dimval) quantities — both route through normalize().

Constructor & Destructor Documentation

◆ Counter() [1/3]

prom::Counter::Counter ( const std::string_view  name,
const std::string_view  help 
)
inline

Standalone, unbound counter. Binds to the default adapter on first use.

◆ Counter() [2/3]

prom::Counter::Counter ( const CounterSpec spec)
inlineexplicit

Standalone counter from a spec (unbound).

Convenience mirror of the Registry factory for code that does not hold a registry.

◆ Counter() [3/3]

prom::Counter::Counter ( std::shared_ptr< MetricCore core)
inlineexplicit

Internal: adopt a core prepared by a Registry or labels().

Member Function Documentation

◆ inc() [1/3]

void prom::Counter::inc ( ) const
inlinenoexcept

Increment by one.

◆ inc() [2/3]

template<DimensionalValue V>
void prom::Counter::inc ( const V &  amount)
inlinenoexcept

Increment by a dimensional amount; its unit is reconciled with the metric's declared/latched unit.

◆ inc() [3/3]

template<class T >
requires std::is_arithmetic_v<T>
void prom::Counter::inc ( amount)
inlinenoexcept

Increment by a raw arithmetic amount (must be >= 0 and finite).

◆ labels()

Counter prom::Counter::labels ( const Labels dynamic) const
inlinenoexcept

A same-type child series bound to dynamic labels (overlaid on the family's constant labels by the backend).


The documentation for this class was generated from the following file: