prometheus-client-c  0.1.1
Prometheus client for the C programming language
Typedefs | Functions
prom_counter.h File Reference

https://prometheus.io/docs/concepts/metric_types/#counter More...

#include <stdlib.h>
#include "prom_metric.h"
Include dependency graph for prom_counter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef prom_metric_t prom_counter_t
 A prometheus counter. More...
 

Functions

prom_counter_tprom_counter_new (const char *name, const char *help, size_t label_key_count, const char **label_keys)
 Construct a prom_counter_t*. More...
 
int prom_counter_destroy (prom_counter_t *self)
 Destroys a prom_counter_t*. More...
 
int prom_counter_inc (prom_counter_t *self, const char **label_values)
 Increment the prom_counter_t by 1. More...
 
int prom_counter_add (prom_counter_t *self, double r_value, const char **label_values)
 Add the value to the prom_counter_t*. More...
 

Detailed Description

https://prometheus.io/docs/concepts/metric_types/#counter

Typedef Documentation

◆ prom_counter_t

A prometheus counter.

References

Function Documentation

◆ prom_counter_add()

int prom_counter_add ( prom_counter_t self,
double  r_value,
const char **  label_values 
)

Add the value to the prom_counter_t*.

A non-zero integer value will be returned on failure.

Parameters
selfThe target prom_counter_t*
r_valueThe double to add to the prom_counter_t passed as self. The value MUST be greater than or equal to 0.
label_valuesThe label values associated with the metric sample being updated. The number of labels must match the value passed to label_key_count in the counter's constructor. If no label values are necessary, pass NULL. Otherwise, It may be convenient to pass this value as a literal.
Returns
A non-zero integer value upon failure.

Example

// An example with labels
prom_counter_add(foo_counter, 22, (const char**) { "bar", "bang" });

// An example without labels
prom_counter_add(foo_counter, 22, NULL);

◆ prom_counter_destroy()

int prom_counter_destroy ( prom_counter_t self)

Destroys a prom_counter_t*.

You must set self to NULL after destruction. A non-zero integer value will be returned on failure.

Parameters
selfA prom_counter_t*
Returns
A non-zero integer value upon failure.

◆ prom_counter_inc()

int prom_counter_inc ( prom_counter_t self,
const char **  label_values 
)

Increment the prom_counter_t by 1.

A non-zero integer value will be returned on failure.

Parameters
selfThe target prom_counter_t*
label_valuesThe label values associated with the metric sample being updated. The number of labels must match the value passed to label_key_count in the counter's constructor. If no label values are necessary, pass NULL. Otherwise, It may be convenient to pass this value as a literal.
Returns
A non-zero integer value upon failure.

Example

// An example with labels
prom_counter_inc(foo_counter, (const char**) { "bar", "bang" });

// An example without labels
prom_counter_inc(foo_counter, NULL);

◆ prom_counter_new()

prom_counter_t* prom_counter_new ( const char *  name,
const char *  help,
size_t  label_key_count,
const char **  label_keys 
)

Construct a prom_counter_t*.

Parameters
nameThe name of the metric
helpThe metric description
label_key_countThe number of labels associated with the given metric. Pass 0 if the metric does not require labels.
label_keysA collection of label keys. The number of keys MUST match the value passed as label_key_count. If no labels are required, pass NULL. Otherwise, it may be convenient to pass this value as a literal.
Returns
The constructed prom_counter_t*

Example

// An example with labels
prom_counter_new("foo", "foo is a counter with labels", 2, (const char**) { "one", "two" });

// An example without labels
prom_counter_new("foo", "foo is a counter without labels", 0, NULL);