Loading...
Searching...
No Matches
prometheus::Registry Class Reference

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

`#include <registry.h>`

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

## Public Types

enum class | InsertBehavior { Merge , 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.
| Registry (const Registry &)=delete
| Deleted copy constructor.
Registry & | operator= (const Registry &)=delete
| Deleted copy assignment.
| Registry (Registry &&)=delete
| Deleted move constructor.
Registry & | operator= (Registry &&)=delete
| Deleted move assignment.
| ~Registry () override
| name Destroys a registry.
std::vector< MetricFamily > | Collect () const override
| Returns a list of metrics and their samples.
template<typename T >
bool | Remove (const Family< T > &family)
| Removes a metrics family from the registry.
template<>
std::vector< std::unique_ptr< Family< Counter > > > & | GetFamilies ()
template<>
std::vector< std::unique_ptr< Family< Gauge > > > & | GetFamilies ()
template<>
std::vector< std::unique_ptr< Family< Histogram > > > & | GetFamilies ()
template<>
std::vector< std::unique_ptr< Family< Summary > > > & | 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() or BuildSummary().

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

## Member Enumeration Documentation

## InsertBehavior

enum class prometheus::Registry::InsertBehavior

strong

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_behavior | How to handle families with the same name.

## Member Function Documentation

## Collect()

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

override virtual

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

  T | One of the metric types Counter, Gauge, Histogram or Summary.

Parameters

  family | The family to remove

Returns
  True if the family was found and removed.