prom 0.1.0
Client-independent C++23 Prometheus/OpenMetrics metric abstraction
Loading...
Searching...
No Matches
Namespaces | Classes | Concepts | Typedefs | Enumerations | Functions | Variables
prom Namespace Reference

Namespaces

namespace  detail
 Portable atomic shared_ptr<const T> exposing just load()/store().
 
namespace  prometheus_cpp
 

Classes

class  Adapter
 The pluggable backend. More...
 
class  AdapterCell
 A swappable adapter slot shared by every metric that reads from it. More...
 
class  AdapterSource
 The source a metric reads its current adapter from, decoupled from Registry so that metric_base can resolve a binding without depending on the registry layer (which would be an include cycle), mirroring ScopeState. More...
 
class  CompositeAdapter
 A backend that forwards every call to a fixed set of child adapters. More...
 
class  CompositeState
 Backend state for a composite family or child: the index-aligned bundle of the handles each wrapped adapter returned. More...
 
class  Counter
 A counter. More...
 
struct  CounterSpec
 Declarative description of a counter, for Registry::counter / Counter::Counter. More...
 
struct  Error
 A validation failure: a machine code plus a human message. More...
 
class  Exception
 Thrown by the throwing Registry factories when a spec fails validation. More...
 
class  Gauge
 A gauge. More...
 
struct  GaugeSpec
 Declarative description of a gauge. More...
 
class  Histogram
 A histogram. More...
 
struct  HistogramSpec
 Declarative description of a histogram. More...
 
class  Info
 An info metric: a single sample whose labels carry the payload (build version, commit, ...). More...
 
struct  InfoSpec
 Declarative description of an info metric. More...
 
struct  Label
 A single name="value" label pair. More...
 
class  Labels
 An immutable-by-convention set of labels, kept sorted by name with duplicates collapsed last-wins. More...
 
class  MetricBase
 CRTP base shared by every metric type. More...
 
struct  MetricCore
 Shared, reference-counted state behind every metric handle. More...
 
struct  MetricInfo
 A read-only snapshot describing one registered metric, returned by the enumeration APIs (Registry::metrics, Scope::metrics). More...
 
struct  MetricMeta
 The complete, backend-agnostic description of a metric family handed to Adapter::register_metric. More...
 
class  MetricState
 Opaque backend state for a registered family or a labeled child. More...
 
struct  NormalizedValue
 A plain magnitude paired with the unit it was carrying (empty for raw arithmetic). More...
 
class  NullAdapter
 A backend that records nothing. More...
 
class  Registry
 Creates registered metrics against a single adapter cell. More...
 
struct  RegistryConfig
 The decoration a Registry applies to every metric created through it: a name prefix, default constant labels, and default display metadata. More...
 
class  Scope
 A named, reconfigurable metrics instance for one library. More...
 
struct  ScopeConfig
 The configuration a Scope applies to every metric created through it. More...
 
class  ScopeState
 Read-only view a scoped metric uses to re-resolve its name, constant labels, and display metadata against the live scope configuration on every use. More...
 
class  StateSet
 A state set: each declared state is a boolean, exposed as one series per state with value 0 or 1. More...
 
struct  StateSetSpec
 Declarative description of a state set. More...
 
class  Summary
 A summary. Like a histogram but tracks quantiles instead of fixed buckets. More...
 
struct  SummarySpec
 Declarative description of a summary. More...
 
struct  Unit
 OpenMetrics unit suffix plus optional dimensional metadata. More...
 
class  Untyped
 An untyped metric: just a settable value. More...
 
struct  UntypedSpec
 Declarative description of an untyped metric. More...
 

Concepts

concept  DimensionalValue
 Satisfied by a dimval-like value: it exposes a value_t, reports its magnitude through numeric_as_double(), and carries unit metadata through either unit_descriptor() (measures) or descriptor() (units).
 

Typedefs

template<class T >
using expected = std::expected< T, Error >
 std::expected<T, Error> — the result type of the Registry::try_* family.
 
using MetricHandle = std::shared_ptr< MetricState >
 Opaque, backend-owned handle to a registered metric family or a labeled child series.
 
using AdapterPtr = std::shared_ptr< Adapter >
 Shared ownership of an Adapter.
 

Enumerations

enum class  ErrorCode : std::uint8_t {
  InvalidMetricName , InvalidLabelName , EmptyHelp , InvalidBuckets ,
  InvalidQuantiles , EmptyStateSet , RegistrationFailed
}
 Why a metric definition or registration was rejected. More...
 
enum class  MetricType : std::uint8_t {
  Counter , Gauge , Histogram , Summary ,
  Untyped , Info , StateSet
}
 The OpenMetrics / Prometheus metric kinds prom understands. More...
 

Functions

template<DimensionalValue V>
NormalizedValue normalize (const V &value)
 Reduce a dimval value to a NormalizedValue.
 
template<class T >
requires std::is_arithmetic_v<T>
NormalizedValue normalize (T value) noexcept
 Pass an arithmetic sample straight through with no unit attached.
 
constexpr std::string_view to_string (const ErrorCode code) noexcept
 Human-readable spelling of an ErrorCode.
 
constexpr bool is_valid_metric_name (std::string_view name) noexcept
 A metric name is valid when it matches Prometheus's [a-zA-Z_][a-zA-Z0-9_]*.
 
constexpr bool is_valid_label_name (const std::string_view name) noexcept
 A label name follows the metric-name charset but additionally rejects the __ prefix, which OpenMetrics reserves for internal use.
 
MetricInfo describe (const MetricCore &core)
 Build a MetricInfo from a core, applying scope decoration for a scoped metric's effective name and constant labels.
 
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
 
std::shared_ptr< Scopescope (const std::string_view name, ScopeConfig config)
 Get-or-create the process-wide scope named name, using config only if it does not yet exist (a later call returns the existing scope and ignores config — reconfigure through the returned scope's setters instead).
 
std::shared_ptr< Scopescope (const std::string_view name)
 Get-or-create the scope named name with a default config whose prefix is name + "_".
 
std::shared_ptr< Scopefind_scope (const std::string_view name)
 Return the scope named name, or nullptr if none has been created.
 
std::vector< std::shared_ptr< Scope > > scopes ()
 Every process-wide scope created so far (unordered).
 
std::vector< std::string > scope_names ()
 The names of every process-wide scope created so far (unordered).
 
constexpr std::string_view to_string (const MetricType type) noexcept
 Lower-case OpenMetrics spelling of a MetricType (e.g. "counter").
 

Variables

constexpr std::array< double, 11 > default_histogram_buckets
 The default bucket bounds applied when a histogram spec leaves buckets empty — the canonical Prometheus client default set (seconds-oriented).
 
constexpr std::array< double, 3 > default_summary_quantiles = {0.5, 0.9, 0.99}
 Default quantiles applied when a summary spec leaves quantiles empty.
 

Typedef Documentation

◆ AdapterPtr

using prom::AdapterPtr = typedef std::shared_ptr<Adapter>

Shared ownership of an Adapter.

The process-wide default and every Registry hold one of these.

◆ expected

template<class T >
using prom::expected = typedef std::expected<T, Error>

std::expected<T, Error> — the result type of the Registry::try_* family.

◆ MetricHandle

using prom::MetricHandle = typedef std::shared_ptr<MetricState>

Opaque, backend-owned handle to a registered metric family or a labeled child series.

Always non-null once handed back by an Adapter.

Enumeration Type Documentation

◆ ErrorCode

enum class prom::ErrorCode : std::uint8_t
strong

Why a metric definition or registration was rejected.

Enumerator
InvalidMetricName 

Name violates [a-zA-Z_][a-zA-Z0-9_]*.

InvalidLabelName 

A label name is invalid or uses the reserved __ prefix.

EmptyHelp 

Help text is required but was empty.

InvalidBuckets 

Histogram buckets are unsorted, empty, or non-finite.

InvalidQuantiles 

Summary quantiles fall outside the open interval (0, 1).

EmptyStateSet 

A state set was declared with no states.

RegistrationFailed 

The backend refused to register the metric.

◆ MetricType

enum class prom::MetricType : std::uint8_t
strong

The OpenMetrics / Prometheus metric kinds prom understands.

The numeric values are stable and intended for cheap switch dispatch inside adapters; do not rely on them crossing an ABI boundary.

Enumerator
Counter 

Monotonically increasing cumulative value.

Gauge 

Value that can go up and down.

Histogram 

Bucketed distribution of observations.

Summary 

Quantile summary of observations.

Untyped 

A bare value with no semantic constraints.

Info 

Static key/value metadata (exposed as *_info).

StateSet 

A set of mutually-related boolean states.

Function Documentation

◆ counter()

Counter prom::counter ( const CounterSpec spec)
inline

◆ describe()

MetricInfo prom::describe ( const MetricCore core)
inline

Build a MetricInfo from a core, applying scope decoration for a scoped metric's effective name and constant labels.

◆ find_scope()

std::shared_ptr< Scope > prom::find_scope ( const std::string_view  name)
inline

Return the scope named name, or nullptr if none has been created.

◆ gauge()

Gauge prom::gauge ( const GaugeSpec spec)
inline

◆ histogram()

Histogram prom::histogram ( const HistogramSpec spec)
inline

◆ info()

Info prom::info ( const InfoSpec spec)
inline

◆ is_valid_label_name()

constexpr bool prom::is_valid_label_name ( const std::string_view  name)
constexprnoexcept

A label name follows the metric-name charset but additionally rejects the __ prefix, which OpenMetrics reserves for internal use.

◆ is_valid_metric_name()

constexpr bool prom::is_valid_metric_name ( std::string_view  name)
constexprnoexcept

A metric name is valid when it matches Prometheus's [a-zA-Z_][a-zA-Z0-9_]*.

◆ normalize() [1/2]

template<DimensionalValue V>
NormalizedValue prom::normalize ( const V &  value)

Reduce a dimval value to a NormalizedValue.

Measures expose both descriptor() (the measure descriptor) and unit_descriptor() (the base unit); units expose only descriptor() (which already is a unit descriptor). Either way we want the unit descriptor's long_name, kind, and symbol, so prefer unit_descriptor() when present.

◆ normalize() [2/2]

template<class T >
requires std::is_arithmetic_v<T>
NormalizedValue prom::normalize ( value)
noexcept

Pass an arithmetic sample straight through with no unit attached.

◆ scope() [1/2]

std::shared_ptr< Scope > prom::scope ( const std::string_view  name)
inline

Get-or-create the scope named name with a default config whose prefix is name + "_".

◆ scope() [2/2]

std::shared_ptr< Scope > prom::scope ( const std::string_view  name,
ScopeConfig  config 
)
inline

Get-or-create the process-wide scope named name, using config only if it does not yet exist (a later call returns the existing scope and ignores config — reconfigure through the returned scope's setters instead).

◆ scope_names()

std::vector< std::string > prom::scope_names ( )
inline

The names of every process-wide scope created so far (unordered).

◆ scopes()

std::vector< std::shared_ptr< Scope > > prom::scopes ( )
inline

Every process-wide scope created so far (unordered).

◆ stateset()

StateSet prom::stateset ( const StateSetSpec spec)
inline

◆ summary()

Summary prom::summary ( const SummarySpec spec)
inline

◆ to_string() [1/2]

constexpr std::string_view prom::to_string ( const ErrorCode  code)
constexprnoexcept

Human-readable spelling of an ErrorCode.

◆ to_string() [2/2]

constexpr std::string_view prom::to_string ( const MetricType  type)
constexprnoexcept

Lower-case OpenMetrics spelling of a MetricType (e.g. "counter").

◆ try_counter()

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

◆ try_gauge()

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

◆ try_histogram()

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

◆ try_info()

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

◆ try_stateset()

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

◆ try_summary()

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

◆ try_untyped()

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

◆ untyped()

Untyped prom::untyped ( const UntypedSpec spec)
inline

Variable Documentation

◆ default_histogram_buckets

constexpr std::array<double, 11> prom::default_histogram_buckets
inlineconstexpr
Initial value:
= {
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0}

The default bucket bounds applied when a histogram spec leaves buckets empty — the canonical Prometheus client default set (seconds-oriented).

◆ default_summary_quantiles

constexpr std::array<double, 3> prom::default_summary_quantiles = {0.5, 0.9, 0.99}
inlineconstexpr

Default quantiles applied when a summary spec leaves quantiles empty.