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

The pluggable backend. More...

#include <adapter.hpp>

Inheritance diagram for prom::Adapter:
Inheritance graph
[legend]

Public Member Functions

 Adapter ()=default
 
 Adapter (const Adapter &)=delete
 
Adapteroperator= (const Adapter &)=delete
 
 Adapter (Adapter &&)=delete
 
Adapteroperator= (Adapter &&)=delete
 
virtual ~Adapter ()=default
 
virtual std::string_view backend_name () const noexcept=0
 Stable identifier of the backend (e.g. "null", "prometheus-cpp").
 
virtual MetricHandle register_metric (const MetricMeta &meta) noexcept=0
 Register a metric family.
 
virtual MetricHandle resolve (const MetricHandle &family, const Labels &dynamic) noexcept=0
 Resolve the labeled child of family for the given dynamic labels, creating it on first request.
 
virtual void inc (const MetricHandle &handle, double amount) noexcept=0
 Increase the series behind handle by amount (counter/gauge).
 
virtual void dec (const MetricHandle &handle, double amount) noexcept=0
 Decrease the series behind handle by amount (gauge).
 
virtual void set (const MetricHandle &handle, double value) noexcept=0
 Set the series behind handle to value (gauge/untyped).
 
virtual void observe (const MetricHandle &handle, double value) noexcept=0
 Record an observation against handle (histogram/summary).
 
virtual void set_info (const MetricHandle &handle, std::span< const Label > labels) noexcept=0
 Replace the label set carried by an info metric.
 
virtual void set_state (const MetricHandle &handle, std::string_view state, bool active) noexcept=0
 Set the boolean value of one member of a state set.
 
virtual void set_unit (const MetricHandle &, const Unit &) noexcept
 Late unit inference hook.
 

Detailed Description

The pluggable backend.

Non-copyable, non-movable: an Adapter is owned through a shared_ptr and referenced by every metric bound to it.

Threading contract. Every method may be called concurrently from any thread. Backends are responsible for their own synchronization. No method throws — failures are absorbed (and ideally logged) by the backend.

Constructor & Destructor Documentation

◆ Adapter() [1/3]

prom::Adapter::Adapter ( )
default

◆ Adapter() [2/3]

prom::Adapter::Adapter ( const Adapter )
delete

◆ Adapter() [3/3]

prom::Adapter::Adapter ( Adapter &&  )
delete

◆ ~Adapter()

virtual prom::Adapter::~Adapter ( )
virtualdefault

Member Function Documentation

◆ backend_name()

virtual std::string_view prom::Adapter::backend_name ( ) const
pure virtualnoexcept

Stable identifier of the backend (e.g. "null", "prometheus-cpp").

Implemented in prom::prometheus_cpp::PrometheusCppAdapter, prom::CompositeAdapter, and prom::NullAdapter.

◆ dec()

virtual void prom::Adapter::dec ( const MetricHandle handle,
double  amount 
)
pure virtualnoexcept

Decrease the series behind handle by amount (gauge).

Implemented in prom::NullAdapter, prom::CompositeAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ inc()

virtual void prom::Adapter::inc ( const MetricHandle handle,
double  amount 
)
pure virtualnoexcept

Increase the series behind handle by amount (counter/gauge).

Implemented in prom::NullAdapter, prom::CompositeAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ observe()

virtual void prom::Adapter::observe ( const MetricHandle handle,
double  value 
)
pure virtualnoexcept

Record an observation against handle (histogram/summary).

Implemented in prom::NullAdapter, prom::CompositeAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ operator=() [1/2]

Adapter & prom::Adapter::operator= ( Adapter &&  )
delete

◆ operator=() [2/2]

Adapter & prom::Adapter::operator= ( const Adapter )
delete

◆ register_metric()

virtual MetricHandle prom::Adapter::register_metric ( const MetricMeta meta)
pure virtualnoexcept

Register a metric family.

Must return a non-null handle even on failure (fall back to an inert handle) so callers never have to null-check.

Implemented in prom::CompositeAdapter, prom::NullAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ resolve()

virtual MetricHandle prom::Adapter::resolve ( const MetricHandle family,
const Labels dynamic 
)
pure virtualnoexcept

Resolve the labeled child of family for the given dynamic labels, creating it on first request.

The backend owns the child cache. Must return a non-null handle.

Implemented in prom::NullAdapter, prom::CompositeAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ set()

virtual void prom::Adapter::set ( const MetricHandle handle,
double  value 
)
pure virtualnoexcept

Set the series behind handle to value (gauge/untyped).

Implemented in prom::NullAdapter, prom::CompositeAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ set_info()

virtual void prom::Adapter::set_info ( const MetricHandle handle,
std::span< const Label labels 
)
pure virtualnoexcept

Replace the label set carried by an info metric.

Implemented in prom::NullAdapter, prom::CompositeAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ set_state()

virtual void prom::Adapter::set_state ( const MetricHandle handle,
std::string_view  state,
bool  active 
)
pure virtualnoexcept

Set the boolean value of one member of a state set.

Implemented in prom::NullAdapter, prom::CompositeAdapter, and prom::prometheus_cpp::PrometheusCppAdapter.

◆ set_unit()

virtual void prom::Adapter::set_unit ( const MetricHandle ,
const Unit  
)
inlinevirtualnoexcept

Late unit inference hook.

Called when a metric that declared no unit latches the unit of its first dimensional observation. Optional — backends that cannot rename a registered series may ignore it.

Reimplemented in prom::NullAdapter, and prom::CompositeAdapter.


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