File Information
Library: Prometheus
Package: Core
Header: Poco/Prometheus/LabeledMetricImpl.h
Description
A helper class for implementing LabeledMetric classes such as Counter, Gauge and Histogram.
This class takes care of managing label values and samples.
Inheritance
Direct Base Classes: LabeledMetric
All Base Classes: Collector, LabeledMetric, Metric
Member Summary
Member Functions: clear, createSample, exportTo, forEach, labels, remove, sampleCount, writeSample
Inherited Functions: exportTo, help, labelNames, name, setHelp, setLabelNames, type, validateLabelName, validateName
Types Aliases
ProcessingFunction
using ProcessingFunction = std::function < void (const std::vector < std::string > &, const Sample &)>;
Sample
using Sample = S;
Constructors
LabeledMetricImpl
LabeledMetricImpl(
Type type,
const std::string & name
);
LabeledMetricImpl
LabeledMetricImpl(
Type type,
const std::string & name,
Registry * pRegistry
);
Destructor
~LabeledMetricImpl
~LabeledMetricImpl() = default;
Destroys the LabeledMetricImpl.
Member Functions
clear
void clear();
Removes all samples.
exportTo
void exportTo(
Exporter & exporter
) const override;
See also: Poco::Prometheus::Collector::exportTo()
forEach
template < typename Fn > void forEach(
ProcessingFunction func
) const;
Calls the given function for each Sample.
labels
Sample & labels(
const std::vector < std::string > & labelValues
);
Returns the Sample associated with the given label values.
If the sample does not exist yet, it is created.
The returned reference can be cached by the caller.
labels
const Sample & labels(
const std::vector < std::string > & labelValues
) const;
Returns the Sample associated with the given label values.
If the sample does not exist, a Poco::NotFoundException is thrown.
The returned reference can be cached by the caller.
remove
void remove(
const std::vector < std::string > & labelValues
);
Removes the sample associated with the given label values.
sampleCount
std::size_t sampleCount() const;
Returns the number of samples.
createSample
virtual std::unique_ptr < Sample > createSample() const = 0;
Creates a new Sample. Must be overridden by subclasses.
writeSample
virtual void writeSample(
Exporter & exporter,
const std::vector < std::string > & labelValues,
const Sample & sample
) const;