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

Creates registered metrics against a single adapter cell. More...

#include <registry.hpp>

Public Member Functions

 Registry (const Registry &)=delete
 
Registryoperator= (const Registry &)=delete
 
 Registry (Registry &&)=delete
 
Registryoperator= (Registry &&)=delete
 
 ~Registry ()=default
 
AdapterPtr adapter () const
 The adapter this registry binds metrics to.
 
void set_adapter (AdapterPtr adapter) const
 Install adapter (or reset to a fresh NullAdapter when null) as this registry's backend.
 
std::string prefix () const
 
void set_prefix (std::string prefix)
 
Labels const_labels () const
 
void set_const_labels (Labels labels)
 
void add_const_label (std::string name, std::string value)
 
comms::DisplayInfo display () const
 
void set_display (comms::DisplayInfo display)
 
RegistryConfig config () const
 A snapshot of the whole decoration.
 
void configure (RegistryConfig config)
 Replace the whole decoration at once (single reconfiguration).
 
std::vector< MetricInfometrics () const
 Snapshots describing every (still-alive) metric created from this registry, including declared-but-unused ones.
 
Counter counter (const CounterSpec &spec)
 
Gauge gauge (const GaugeSpec &spec)
 
Histogram histogram (const HistogramSpec &spec)
 
Summary summary (const SummarySpec &spec)
 
Untyped untyped (const UntypedSpec &spec)
 
Info info (const InfoSpec &spec)
 
StateSet stateset (const StateSetSpec &spec)
 
expected< Countertry_counter (const CounterSpec &spec) noexcept
 
expected< Gaugetry_gauge (const GaugeSpec &spec) noexcept
 
expected< Histogramtry_histogram (const HistogramSpec &spec) noexcept
 
expected< Summarytry_summary (const SummarySpec &spec) noexcept
 
expected< Untypedtry_untyped (const UntypedSpec &spec) noexcept
 
expected< Infotry_info (const InfoSpec &spec) noexcept
 
expected< StateSettry_stateset (const StateSetSpec &spec) noexcept
 

Static Public Member Functions

static std::shared_ptr< Registrycreate (AdapterPtr adapter=nullptr)
 Create a registry with its own cell holding adapter (a fresh NullAdapter when null).
 
static std::shared_ptr< Registrycreate (AdapterPtr adapter, RegistryConfig config)
 Create a decorating registry: every metric built from it gets config's prefix, default constant labels, and default display, all live- reconfigurable through the registry's setters (mutating them re-registers existing metrics on next use, just like a Scope).
 
static std::shared_ptr< Registryglobal ()
 The process-wide registry, sharing the global adapter cell and the global decoration.
 
static std::shared_ptr< Scopescope (std::string_view name)
 Get-or-create the process-wide, named Scope (a per-library metrics instance with a shared prefix / default labels / display).
 
static std::shared_ptr< Scopescope (std::string_view name, ScopeConfig config)
 

Detailed Description

Creates registered metrics against a single adapter cell.

The adapter lives on the registry's AdapterCell. set_adapter swaps it and every metric created from the registry re-registers against the new backend on its next use (the previous backend's series are left behind). The process-wide Registry::global() shares the global cell — the same one standalone and scoped metrics read — so installing a backend with Registry::global()->set_adapter(...) reconfigures everything at once.

Non-copyable and shared_ptr-managed: use Registry::create(...) / Registry::global() and call through ->.

Constructor & Destructor Documentation

◆ Registry() [1/2]

prom::Registry::Registry ( const Registry )
delete

◆ Registry() [2/2]

prom::Registry::Registry ( Registry &&  )
delete

◆ ~Registry()

prom::Registry::~Registry ( )
default

Member Function Documentation

◆ adapter()

AdapterPtr prom::Registry::adapter ( ) const
inline

The adapter this registry binds metrics to.

◆ add_const_label()

void prom::Registry::add_const_label ( std::string  name,
std::string  value 
)
inline

◆ config()

RegistryConfig prom::Registry::config ( ) const
inline

A snapshot of the whole decoration.

◆ configure()

void prom::Registry::configure ( RegistryConfig  config)
inline

Replace the whole decoration at once (single reconfiguration).

◆ const_labels()

Labels prom::Registry::const_labels ( ) const
inline

◆ counter()

Counter prom::Registry::counter ( const CounterSpec spec)
inline

◆ create() [1/2]

static std::shared_ptr< Registry > prom::Registry::create ( AdapterPtr  adapter,
RegistryConfig  config 
)
inlinestatic

Create a decorating registry: every metric built from it gets config's prefix, default constant labels, and default display, all live- reconfigurable through the registry's setters (mutating them re-registers existing metrics on next use, just like a Scope).

◆ create() [2/2]

static std::shared_ptr< Registry > prom::Registry::create ( AdapterPtr  adapter = nullptr)
inlinestatic

Create a registry with its own cell holding adapter (a fresh NullAdapter when null).

◆ display()

comms::DisplayInfo prom::Registry::display ( ) const
inline

◆ gauge()

Gauge prom::Registry::gauge ( const GaugeSpec spec)
inline

◆ global()

static std::shared_ptr< Registry > prom::Registry::global ( )
inlinestatic

The process-wide registry, sharing the global adapter cell and the global decoration.

Lets callers create metrics without threading a Registry through their code — see the free prom::counter(...) helpers, which delegate here. Install a backend with prom::Registry::global()->set_adapter(...); install a process-wide prefix / labels with prom::Registry::global()->set_prefix(...) (which reaches standalone and scoped metrics too).

◆ histogram()

Histogram prom::Registry::histogram ( const HistogramSpec spec)
inline

◆ info()

Info prom::Registry::info ( const InfoSpec spec)
inline

◆ metrics()

std::vector< MetricInfo > prom::Registry::metrics ( ) const
inline

Snapshots describing every (still-alive) metric created from this registry, including declared-but-unused ones.

Expired entries are pruned.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ prefix()

std::string prom::Registry::prefix ( ) const
inline

◆ scope() [1/2]

std::shared_ptr< Scope > prom::Registry::scope ( std::string_view  name)
inlinestatic

Get-or-create the process-wide, named Scope (a per-library metrics instance with a shared prefix / default labels / display).

Defined in <prom/scope.hpp> — include it to use these. The two-argument form's config applies only when the scope is first created.

◆ scope() [2/2]

std::shared_ptr< Scope > prom::Registry::scope ( std::string_view  name,
ScopeConfig  config 
)
inlinestatic

◆ set_adapter()

void prom::Registry::set_adapter ( AdapterPtr  adapter) const
inline

Install adapter (or reset to a fresh NullAdapter when null) as this registry's backend.

Metrics already created from the registry migrate to it on their next use; series already written to the previous backend stay there (backends cannot move a registered series).

◆ set_const_labels()

void prom::Registry::set_const_labels ( Labels  labels)
inline

◆ set_display()

void prom::Registry::set_display ( comms::DisplayInfo  display)
inline

◆ set_prefix()

void prom::Registry::set_prefix ( std::string  prefix)
inline

◆ stateset()

StateSet prom::Registry::stateset ( const StateSetSpec spec)
inline

◆ summary()

Summary prom::Registry::summary ( const SummarySpec spec)
inline

◆ try_counter()

expected< Counter > prom::Registry::try_counter ( const CounterSpec spec)
inlinenoexcept

◆ try_gauge()

expected< Gauge > prom::Registry::try_gauge ( const GaugeSpec spec)
inlinenoexcept

◆ try_histogram()

expected< Histogram > prom::Registry::try_histogram ( const HistogramSpec spec)
inlinenoexcept

◆ try_info()

expected< Info > prom::Registry::try_info ( const InfoSpec spec)
inlinenoexcept

◆ try_stateset()

expected< StateSet > prom::Registry::try_stateset ( const StateSetSpec spec)
inlinenoexcept

◆ try_summary()

expected< Summary > prom::Registry::try_summary ( const SummarySpec spec)
inlinenoexcept

◆ try_untyped()

expected< Untyped > prom::Registry::try_untyped ( const UntypedSpec spec)
inlinenoexcept

◆ untyped()

Untyped prom::Registry::untyped ( const UntypedSpec spec)
inline

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