Prometheus Client Library for Modern C++
Public Member Functions | Static Public Attributes | List of all members
prometheus::Counter Class Reference

A counter metric to represent a monotonically increasing value. More...

Public Member Functions

 Counter ()=default
 Create a counter that starts at 0.
 
void Increment ()
 Increment the counter by 1.
 
void Increment (double)
 Increment the counter by a given amount. More...
 
void Reset ()
 Reset the counter to 0.
 
double Value () const
 Get the current value of the counter.
 
ClientMetric Collect () const
 Get the current value of the counter. More...
 

Static Public Attributes

static const MetricType metric_type {MetricType::Counter}
 

Detailed Description

A counter metric to represent a monotonically increasing value.

This class represents the metric type counter: https://prometheus.io/docs/concepts/metric_types/#counter

The value of the counter can only increase. Example of counters are:

Do not use a counter to expose a value that can decrease - instead use a Gauge.

The class is thread-safe. No concurrent call to any API of this type causes a data race.

Member Function Documentation

◆ Collect()

ClientMetric prometheus::Counter::Collect ( ) const

Get the current value of the counter.

Collect is called by the Registry when collecting metrics.

◆ Increment()

void prometheus::Counter::Increment ( double  val)

Increment the counter by a given amount.

The counter will not change if the given amount is negative.