lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Pds::MetricExporter Class Reference

Prometheus collectable holding named metrics whose values come from callbacks evaluated at each scrape (Collect()). More...

#include <MetricExporter.hh>

Inherits prometheus::Collectable.

Public Member Functions

int find (const std::string &name) const
 Return the index of the metric named name, or -1.
 
void add (const std::string &name, const std::map< std::string, std::string > &labels, MetricType type, std::function< int64_t()> value)
 Register metric name with labels, of the given type, whose value is read by calling value; an existing metric with that name is replaced.
 
void addFloat (const std::string &name, const std::map< std::string, std::string > &labels, std::function< bool(double &)> value)
 Register a Float gauge name whose callback stores a double and returns whether it is valid; an existing metric with that name is replaced.
 
void constant (const std::string &name, const std::map< std::string, std::string > &labels, int64_t value)
 Register a Constant metric name exported as a counter with the fixed value value.
 
std::shared_ptr< PromHistogram > histogram (const std::string &name, const std::map< std::string, std::string > &labels, unsigned numBins, double binWidth=1.0, double binMin=0.0)
 Register a histogram metric name with numBins buckets of width binWidth starting at binMin and return it for observe() calls.
 
std::vector< prometheus::MetricFamily > Collect () const override
 Update every metric (rates, histograms, valid floats and callback values; constants unchanged) and return the metric families.
 

Detailed Description

Prometheus collectable holding named metrics whose values come from callbacks evaluated at each scrape (Collect()).

Adding a metric with an existing name replaces it.

Member Function Documentation

◆ add()

void Pds::MetricExporter::add ( const std::string &  name,
const std::map< std::string, std::string > &  labels,
MetricType  type,
std::function< int64_t()>  value 
)

Register metric name with labels, of the given type, whose value is read by calling value; an existing metric with that name is replaced.

For Rate, value is called once now to set the starting point.

◆ addFloat()

void Pds::MetricExporter::addFloat ( const std::string &  name,
const std::map< std::string, std::string > &  labels,
std::function< bool(double &)>  value 
)

Register a Float gauge name whose callback stores a double and returns whether it is valid; an existing metric with that name is replaced.

◆ Collect()

std::vector< prometheus::MetricFamily > Pds::MetricExporter::Collect ( ) const
override

Update every metric (rates, histograms, valid floats and callback values; constants unchanged) and return the metric families.

◆ constant()

void Pds::MetricExporter::constant ( const std::string &  name,
const std::map< std::string, std::string > &  labels,
int64_t  value 
)

Register a Constant metric name exported as a counter with the fixed value value.

◆ find()

int Pds::MetricExporter::find ( const std::string &  name) const

Return the index of the metric named name, or -1.

◆ histogram()

std::shared_ptr< PromHistogram > Pds::MetricExporter::histogram ( const std::string &  name,
const std::map< std::string, std::string > &  labels,
unsigned  numBins,
double  binWidth = 1.0,
double  binMin = 0.0 
)

Register a histogram metric name with numBins buckets of width binWidth starting at binMin and return it for observe() calls.

Note that, unlike add() and addFloat(), this does not append a Float callback slot, so the internal per-metric vectors can get out of step.


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