Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
PrometheusService Class Reference

Singleton class to access the PrometheusInterface. More...

#include <Prometheus.hpp>

Static Public Member Functions

static void init (util::config::ClioConfigDefinition const &config)
 Initialize the singleton with the given configuration.
 
static util::prometheus::Bool boolMetric (std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
 Get a bool based metric. It will be created if it doesn't exist.
 
static util::prometheus::CounterIntcounterInt (std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
 Get an integer based counter metric. It will be created if it doesn't exist.
 
static util::prometheus::CounterDoublecounterDouble (std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
 Get a double based counter metric. It will be created if it doesn't exist.
 
static util::prometheus::GaugeIntgaugeInt (std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
 Get an integer based gauge metric. It will be created if it doesn't exist.
 
static util::prometheus::GaugeDoublegaugeDouble (std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
 Get a double based gauge metric. It will be created if it doesn't exist.
 
static util::prometheus::HistogramInthistogramInt (std::string name, util::prometheus::Labels labels, std::vector< std::int64_t > const &buckets, std::optional< std::string > description=std::nullopt)
 Get an integer based histogram metric. It will be created if it doesn't exist.
 
static util::prometheus::HistogramDoublehistogramDouble (std::string name, util::prometheus::Labels labels, std::vector< double > const &buckets, std::optional< std::string > description=std::nullopt)
 Get a double based histogram metric. It will be created if it doesn't exist.
 
static std::string collectMetrics ()
 Collect all metrics and return them as a string in Prometheus format.
 
static bool isEnabled ()
 Whether prometheus is enabled.
 
static bool compressReplyEnabled ()
 Whether to compress the reply.
 
static void replaceInstance (std::unique_ptr< util::prometheus::PrometheusInterface > inst)
 Replace the prometheus object stored in the singleton.
 
static util::prometheus::PrometheusInterfaceinstance ()
 Get the prometheus object stored in the singleton.
 

Detailed Description

Singleton class to access the PrometheusInterface.

Member Function Documentation

◆ boolMetric()

util::prometheus::Bool PrometheusService::boolMetric ( std::string name,
util::prometheus::Labels labels,
std::optional< std::string > description = std::nullopt )
static

Get a bool based metric. It will be created if it doesn't exist.

Note
Prometheus does not have a native bool type, so we use a counter with a value of 0 or 1
Parameters
nameThe name of the metric
labelsThe labels of the metric
descriptionThe description of the metric
Returns
The bool object

◆ collectMetrics()

std::string PrometheusService::collectMetrics ( )
static

Collect all metrics and return them as a string in Prometheus format.

Returns
The serialized metrics

◆ compressReplyEnabled()

bool PrometheusService::compressReplyEnabled ( )
static

Whether to compress the reply.

Returns
true if the reply should be compressed

◆ counterDouble()

util::prometheus::CounterDouble & PrometheusService::counterDouble ( std::string name,
util::prometheus::Labels labels,
std::optional< std::string > description = std::nullopt )
static

Get a double based counter metric. It will be created if it doesn't exist.

Parameters
nameThe name of the metric
labelsThe labels of the metric
descriptionThe description of the metric
Returns
A reference to the counter object

◆ counterInt()

util::prometheus::CounterInt & PrometheusService::counterInt ( std::string name,
util::prometheus::Labels labels,
std::optional< std::string > description = std::nullopt )
static

Get an integer based counter metric. It will be created if it doesn't exist.

Parameters
nameThe name of the metric
labelsThe labels of the metric
descriptionThe description of the metric
Returns
A reference to the counter object

◆ gaugeDouble()

util::prometheus::GaugeDouble & PrometheusService::gaugeDouble ( std::string name,
util::prometheus::Labels labels,
std::optional< std::string > description = std::nullopt )
static

Get a double based gauge metric. It will be created if it doesn't exist.

Parameters
nameThe name of the metric
labelsThe labels of the metric
descriptionThe description of the metric
Returns
A reference to the gauge object

◆ gaugeInt()

util::prometheus::GaugeInt & PrometheusService::gaugeInt ( std::string name,
util::prometheus::Labels labels,
std::optional< std::string > description = std::nullopt )
static

Get an integer based gauge metric. It will be created if it doesn't exist.

Parameters
nameThe name of the metric
labelsThe labels of the metric
descriptionThe description of the metric
Returns
A reference to the gauge object

◆ histogramDouble()

util::prometheus::HistogramDouble & PrometheusService::histogramDouble ( std::string name,
util::prometheus::Labels labels,
std::vector< double > const & buckets,
std::optional< std::string > description = std::nullopt )
static

Get a double based histogram metric. It will be created if it doesn't exist.

Parameters
nameThe name of the metric
labelsThe labels of the metric
bucketsThe buckets of the metric
descriptionThe description of the metric
Returns
A reference to the histogram object

◆ histogramInt()

util::prometheus::HistogramInt & PrometheusService::histogramInt ( std::string name,
util::prometheus::Labels labels,
std::vector< std::int64_t > const & buckets,
std::optional< std::string > description = std::nullopt )
static

Get an integer based histogram metric. It will be created if it doesn't exist.

Parameters
nameThe name of the metric
labelsThe labels of the metric
bucketsThe buckets of the metric
descriptionThe description of the metric
Returns
A reference to the histogram object

◆ init()

void PrometheusService::init ( util::config::ClioConfigDefinition const & config)
static

Initialize the singleton with the given configuration.

Parameters
configThe configuration to use

◆ instance()

util::prometheus::PrometheusInterface & PrometheusService::instance ( )
static

Get the prometheus object stored in the singleton.

Returns
The prometheus object reference

◆ isEnabled()

bool PrometheusService::isEnabled ( )
static

Whether prometheus is enabled.

Returns
true if prometheus is enabled

◆ replaceInstance()

void PrometheusService::replaceInstance ( std::unique_ptr< util::prometheus::PrometheusInterface > inst)
static

Replace the prometheus object stored in the singleton.

Note
Be careful with this method because there could be hanging references to counters
Parameters
instThe new prometheus object

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