Loading...
Searching...
No Matches
prometheus::Counter Class Reference

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

`#include <counter.h>`

## 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.
double | Value () const
| Get the current value of the counter.
ClientMetric | Collect () const
| Get the current value of the counter.

## 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:

- the number of requests served
- tasks completed
- errors

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.