Prometheus Client Library for Modern C++
Public Types | Public Member Functions | Friends | List of all members
prometheus::Registry Class Reference

Manages the collection of a number of metrics. More...

Inheritance diagram for prometheus::Registry:
Inheritance graph
[legend]
Collaboration diagram for prometheus::Registry:
Collaboration graph
[legend]

Public Types

enum  InsertBehavior { InsertBehavior::Merge, InsertBehavior::Throw }
 How to deal with repeatedly added family names for a type. More...
 

Public Member Functions

 Registry (InsertBehavior insert_behavior=InsertBehavior::Merge)
 name Create a new registry. More...
 
 Registry (const Registry &)=delete
 Deleted copy constructor.
 
Registryoperator= (const Registry &)=delete
 Deleted copy assignment.
 
 Registry (Registry &&)=delete
 Deleted move constructor.
 
Registryoperator= (Registry &&)=delete
 Deleted move assignment.
 
 ~Registry () override
 name Destroys a registry.
 
std::vector< MetricFamilyCollect () const override
 Returns a list of metrics and their samples. More...
 
template<typename T >
bool Remove (const Family< T > &family)
 Removes a metrics family from the registry. More...
 
template<>
std::vector< std::unique_ptr< Family< Counter > > > & GetFamilies ()
 

Friends

template<typename T >
class detail::Builder
 

Detailed Description

Manages the collection of a number of metrics.

The Registry is responsible to expose data to a class/method/function "bridge", which returns the metrics in a format Prometheus supports.

The key class is the Collectable. This has a method - called Collect() - that returns zero or more metrics and their samples. The metrics are represented by the class Family<>, which implements the Collectable interface. A new metric is registered with BuildCounter(), BuildGauge(), BuildHistogram(), BuildInfo() or BuildSummary().

The class is thread-safe. No concurrent call to any API of this type causes a data race.

Member Enumeration Documentation

◆ InsertBehavior

How to deal with repeatedly added family names for a type.

Adding a family with the same name but different types is always an error and will lead to an exception.

Enumerator
Merge 

If a family with the same name and labels already exists return the existing one. If no family with that name exists create it. Otherwise throw.

Throw 

Throws if a family with the same name already exists.

Constructor & Destructor Documentation

◆ Registry()

prometheus::Registry::Registry ( InsertBehavior  insert_behavior = InsertBehavior::Merge)
explicit

name Create a new registry.

Parameters
insert_behaviorHow to handle families with the same name.

Member Function Documentation

◆ Collect()

std::vector< MetricFamily > prometheus::Registry::Collect ( ) const
overridevirtual

Returns a list of metrics and their samples.

Every time the Registry is scraped it calls each of the metrics Collect function.

Returns
Zero or more metrics and their samples.

Implements prometheus::Collectable.

◆ Remove()

template<typename T >
template bool PROMETHEUS_CPP_CORE_EXPORT prometheus::Registry::Remove ( const Family< T > &  family)

Removes a metrics family from the registry.

Please note that this operation invalidates the previously returned reference to the Family and all of their added metric objects.

Template Parameters
TOne of the metric types Counter, Gauge, Histogram or Summary.
Parameters
familyThe family to remove
Returns
True if the family was found and removed.