Poco::Prometheus

class Counter

Library: Prometheus
Package: Core
Header: Poco/Prometheus/Counter.h

Description

A generic counter supporting labels.

To create a Counter with labels and register it with the default Registry:

Counter sampleCounter("sample_counter"s, {
    .help = "A sample counter"s,
    .labelNames = {"label1"s, "label2"s}
});

To increment a Counter (with labels):

sampleCounter.labels({"value1"s, "value2"}).inc();

To create a Counter without labels and register it with the default Registry:

Counter simpleCounter("simple_counter"s);
simpleCounter.help("A simple counter"s);

To increment the value of a Counter (without labels):

simpleCounter.inc(42);

Inheritance

Direct Base Classes: LabeledMetricImpl < CounterSample >

All Base Classes: LabeledMetricImpl < CounterSample >

Member Summary

Member Functions: createSample, exportTo, help, inc, labelNames, value, writeSample

Nested Classes

struct Params

 more...

Constructors

Counter

explicit Counter(
    const std::string & name
);

Creates a Counter with the given name and registers it with the default registry.

Counter

Counter(
    const std::string & name,
    const Params & params
);

Creates a Counter with the given name and parameters registers it with the default registry.

Counter

Counter(
    const std::string & name,
    Registry * pRegistry
);

Creates a Counter with the given name and registers it with the given registry (if not nullptr).

Counter

Counter(
    const std::string & name,
    const Params & params,
    Registry * pRegistry
);

Creates a Counter with the given name and params, and registers it with the given registry (if not nullptr).

Destructor

~Counter

~Counter() = default;

Destroys the Counter.

Member Functions

exportTo

void exportTo(
    Exporter & exporter
) const override;

help inline

Counter & help(
    const std::string & text
);

Sets the Counter's help text.

Must only be set once, immediately after creating the Counter.

inc inline

void inc(
    double v = 1.0
);

Increments the counter's current value.

Can only be used if no labels have been defined.

labelNames inline

Counter & labelNames(
    const std::vector < std::string > & labelNames
);

Sets the Counter's label names.

Must only be set once, immediately after creating the Counter.

value

double value() const;

Returns the counter's current value.

Can only be used if no labels have been defined.

createSample protected

std::unique_ptr < CounterSample > createSample() const override;

writeSample protected

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