Poco::Prometheus

template < typename S >

class LabeledMetricImpl

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 inline

LabeledMetricImpl(
    Type type,
    const std::string & name
);

LabeledMetricImpl inline

LabeledMetricImpl(
    Type type,
    const std::string & name,
    Registry * pRegistry
);

Destructor

~LabeledMetricImpl protected virtual

~LabeledMetricImpl() = default;

Destroys the LabeledMetricImpl.

Member Functions

clear inline

void clear();

Removes all samples.

exportTo virtual inline

void exportTo(
    Exporter & exporter
) const override;

forEach inline

template < typename Fn > void forEach(
    ProcessingFunction func
) const;

Calls the given function for each Sample.

labels inline

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 inline

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 inline

void remove(
    const std::vector < std::string > & labelValues
);

Removes the sample associated with the given label values.

sampleCount inline

std::size_t sampleCount() const;

Returns the number of samples.

createSample protected virtual

virtual std::unique_ptr < Sample > createSample() const = 0;

Creates a new Sample. Must be overridden by subclasses.

writeSample protected virtual inline

virtual void writeSample(
    Exporter & exporter,
    const std::vector < std::string > & labelValues,
    const Sample & sample
) const;

Writes a Sample to the Exporter.

Must be overridden by subclasses, unless the subclass overrides the exportTo() method.

The default implementation does nothing.