prometheus-client-c: prom/include/prom_collector.h File Reference

prometheus-client-c 0.1.1 Prometheus client for the C programming language

Typedefs | Functions
prom_collector.h File Reference

A Prometheus collector returns a collection of metrics. More...

`#include "prom_map.h"`
`#include "prom_metric.h"`
Include dependency graph for prom_collector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Typedefs
typedef struct prom_collector | prom_collector_t
| A prometheus collector calls collect to prepare metrics and return them to the registry to which it is registered.
typedef prom_map_t * | prom_collect_fn(prom_collector_t *self)
| The function responsible for preparing metric data and returning metrics for a given collector. More...

## Functions
prom_collector_t * | prom_collector_new (const char *name)
| Create a collector. More...
prom_collector_t * | prom_collector_process_new (const char *limits_path, const char *stat_path)
| Construct a prom_collector_t* which includes the default process metrics. More...
int | prom_collector_destroy (prom_collector_t *self)
| Destroy a collector. More...
void | prom_collector_free_generic (void *gen)
| Frees a collector passed as a void pointer. More...
int | prom_collector_destroy_generic (void *gen)
| Destroys a collector passed as a void pointer. More...
int | prom_collector_add_metric (prom_collector_t *self, prom_metric_t *metric)
| Add a metric to a collector. More...
int | prom_collector_set_collect_fn (prom_collector_t *self, prom_collect_fn *fn)
| The collect function is responsible for doing any work involving a set of metrics and then returning them for metric exposition. More...

## Detailed Description

A Prometheus collector returns a collection of metrics.

## Typedef Documentation

## ◆ prom_collect_fn

typedef prom_map_t* prom_collect_fn(prom_collector_t *self)

The function responsible for preparing metric data and returning metrics for a given collector.

If you use the default collector registry, this should not concern you. If you are using a custom collector, you may set this function on your collector to do additional work before returning the contained metrics.

Parameters

  self | The target prom_collector_t*

Returns
  The prom_map_t* containing the collected metrics

## Function Documentation

## ◆ prom_collector_add_metric()

int prom_collector_add_metric | ( | prom_collector_t * | self,
|  | prom_metric_t * | metric
| ) |  |

Add a metric to a collector.

Parameters

  self | The target prom_collector_t*
  metric | the prom_metric_t* to add to the prom_collector_t* passed as self.

Returns
  A non-zero integer value upon failure.

## ◆ prom_collector_destroy()

int prom_collector_destroy | ( | prom_collector_t * | self | ) |

Destroy a collector.

You MUST set self to NULL after destruction.

Parameters

  self | The target prom_collector_t*

Returns
  A non-zero integer value upon failure.

## ◆ prom_collector_destroy_generic()

int prom_collector_destroy_generic | ( | void * | gen | ) |

Destroys a collector passed as a void pointer.

You MUST set self to NULL after destruction.

Parameters

  gen | The target prom_collector_t* represented as a void*

Returns
  A non-zero integer value upon failure.

## ◆ prom_collector_free_generic()

void prom_collector_free_generic | ( | void * | gen | ) |

Frees a collector passed as a void pointer.

You MUST set self to NULL after destruction.

Parameters

  gen | The target prom_collector_t* represented as a void*

## ◆ prom_collector_new()

prom_collector_t* prom_collector_new | ( | const char * | name | ) |

Create a collector.

Parameters

  name | The name of the collector. The name MUST NOT be default or process.

Returns
  The constructed prom_collector_t*

## ◆ prom_collector_process_new()

prom_collector_t* prom_collector_process_new | ( | const char * | limits_path,
|  | const char * | stat_path
| ) |  |

Construct a prom_collector_t* which includes the default process metrics.

Parameters

  limits_path | Pass NULL to discover the path to the /proc/[pid]/limits file associated with process ID assigned by the host environment. Otherwise, pass a string to said path.
  stat_path | Pass NULL to discover the path to the /proc/[pid]/stat file associated with process ID assigned by the host environment. Otherwise, pass a string to said path.

Returns
  The constructed prom_collector_t*

## ◆ prom_collector_set_collect_fn()

int prom_collector_set_collect_fn | ( | prom_collector_t * | self,
|  | prom_collect_fn * | fn
| ) |  |

The collect function is responsible for doing any work involving a set of metrics and then returning them for metric exposition.

Parameters

  self | The target prom_collector_t*
  fn | The prom_collect_fn* which will be responsible for handling any metric collection operations before returning the collected metrics for exposition.

Returns
  A non-zero integer value upon failure.