C++ Actor Framework 1.0.0
Loading...
Searching...
No Matches
caf::telemetry::collector::prometheus Class Reference

Collects system metrics and exports them to the text-based Prometheus format. More...

#include <prometheus.hpp>

Public Types

using char_buffer = std::vector<char>
 A buffer for storing UTF-8 characters.
 

Public Member Functions

timespan min_scrape_interval () const noexcept
 Returns the minimum scrape interval, i.e., the minimum time that needs to pass before collect_from iterates the registry to re-fill the buffer.
 
void min_scrape_interval (timespan value) noexcept
 Sets the minimum scrape interval to value.
 
timestamp last_scrape () const noexcept
 Returns the time point of the last scrape.
 
std::string_view str () const noexcept
 Returns a string view into the internal buffer.
 
void reset ()
 Reverts the collector back to its initial state, clearing all buffers.
 
bool begin_scrape (timestamp now=make_timestamp())
 Begins a new scrape if last_scape() + min_scrape_interval() <= now.
 
void end_scrape ()
 Cleans up any temporary state before accessing str() for obtaining the scrape result.
 
template<class T >
void append_counter (const metric_family *family, const metric *instance, T value)
 
template<class T >
void append_gauge (const metric_family *family, const metric *instance, T value)
 
void append_histogram (const metric_family *family, const metric *instance, span< const int_histogram::bucket_type > buckets, int64_t sum)
 
void append_histogram (const metric_family *family, const metric *instance, span< const dbl_histogram::bucket_type > buckets, double sum)
 
std::string_view collect_from (const metric_registry &registry, timestamp now=make_timestamp())
 Applies this collector to the registry, filling the character buffer while collecting metrics.
 
void operator() (const metric_family *family, const metric *instance, const dbl_counter *counter)
 
void operator() (const metric_family *family, const metric *instance, const int_counter *counter)
 
void operator() (const metric_family *family, const metric *instance, const dbl_gauge *gauge)
 
void operator() (const metric_family *family, const metric *instance, const int_gauge *gauge)
 
void operator() (const metric_family *family, const metric *instance, const dbl_histogram *val)
 
void operator() (const metric_family *family, const metric *instance, const int_histogram *val)
 

Detailed Description

Collects system metrics and exports them to the text-based Prometheus format.

For a documentation of the format, see: https://git.io/fjgDD.

Member Typedef Documentation

◆ char_buffer

A buffer for storing UTF-8 characters.

Using a vector instead of a std::string has slight performance benefits, since the vector does not have to maintain a null-terminator.

Member Function Documentation

◆ begin_scrape()

bool caf::telemetry::collector::prometheus::begin_scrape ( timestamp now = make_timestamp())
nodiscard

Begins a new scrape if last_scape() + min_scrape_interval() <= now.

Returns
true if the collector started a new scrape or false to signal that the caller shall use the last result via str() since it has not expired yet.

◆ collect_from()

std::string_view caf::telemetry::collector::prometheus::collect_from ( const metric_registry & registry,
timestamp now = make_timestamp() )

Applies this collector to the registry, filling the character buffer while collecting metrics.

Automatically calls begin_scrape and end_scrape as needed.

Parameters
registrySource for the metrics.
nowCurrent system time.
Returns
a view into the filled buffer.

◆ str()

std::string_view caf::telemetry::collector::prometheus::str ( ) const
nodiscardnoexcept

Returns a string view into the internal buffer.

Warning
This view may become invalid when calling any non-const member function on the collector object.

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