Poco::Prometheus

class Gauge

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

Description

A generic gauge supporting labels.

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

Gauge sampleGauge("sample_gauge"s, {
    .help = "A sample gauge"s,
    .labelNames = {"label1"s, "label2"s}
});

To increment a Gauge (with labels):

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

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

Gauge simpleGauge("simple_gauge"s);
simpleGauge.help("A simple gauge"s);

To set the value of a Gauge (without labels):

simpleGauge.set(42);

Inheritance

Direct Base Classes: LabeledMetricImpl < GaugeSample >

All Base Classes: LabeledMetricImpl < GaugeSample >

Member Summary

Member Functions: createSample, dec, exportTo, help, inc, labelNames, set, setToCurrentTime, value, writeSample

Nested Classes

struct Params

 more...

Constructors

Gauge

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

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

Gauge

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

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

Gauge

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

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

Gauge

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

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

Destructor

~Gauge

~Gauge() = default;

Destroys the Gauge.

Member Functions

dec inline

void dec(
    double v = 1.0
);

Decrements the Gauge's current value.

Can only be used if no labels have been defined.

exportTo

void exportTo(
    Exporter & exporter
) const override;

help inline

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

Sets the Gauge's help text.

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

inc inline

void inc(
    double v = 1.0
);

Increments the Gauge's current value.

Can only be used if no labels have been defined.

labelNames inline

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

Sets the Gauge's label names.

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

set inline

void set(
    double v
);

Sets the Gauge's current value.

Can only be used if no labels have been defined.

set

void set(
    Poco::Clock::ClockVal v
);

Sets the Gauge's current value to the given Clock value, converted to seconds.

Can only be used if no labels have been defined.

setToCurrentTime inline

void setToCurrentTime();

Sets the Gauge's current value to the current epoch time (seconds since midnight January 1st 1970).

value

double value() const;

Returns the Gauge's current value.

Can only be used if no labels have been defined.

createSample protected

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

writeSample protected

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