libprom
@VERSION@
C based libraries to expose metrics in Promtheus exposition format
|
The collector registry registers collectors for metric exposition. More...
Go to the source code of this file.
Defines | |
#define | METRIC_LABEL_SCRAPE "libprom" |
Reserved label value for libprom's own scrape duration metrics. | |
#define | METRIC_NAME_SCRAPE "scrape_duration_seconds" |
Reserved name for libprom's own scrape duration metric. | |
#define | COLLECTOR_NAME_DEFAULT "default" |
Reserved name for libprom's own default prom collector, where usually new metrics get attached. | |
#define | COLLECTOR_NAME_PROCESS "process" |
Reserved name for libprom's own process stats prom collector. | |
#define | REGISTRY_NAME_DEFAULT "default" |
Reserved name for libprom's own default prom collector registry. | |
#define | PROM_COLLECTOR_REGISTRY_DEFAULT PROM_COLLECTOR_REGISTRY |
backward compatibility to 0.1.3 - will vanish soon. | |
Typedefs | |
typedef unsigned int | PROM_INIT_FLAGS |
collection of prom collector registry features. | |
typedef struct pcr | pcr_t |
A prom_registry_t is responsible for registering metrics and briding them to the string exposition format. | |
Enumerations | |
enum | prom_init_flag { PROM_NONE = 0, PROM_PROCESS = 1, PROM_SCRAPETIME = 2, PROM_SCRAPETIME_ALL = 4, PROM_COMPACT = 8 } |
flags for the setup of a prom collector registry. More... | |
Functions | |
int | pcr_default_init (void) |
Initializes the default collector registry. | |
int | pcr_init (PROM_INIT_FLAGS features, const char *mprefix) |
Initializes the default collector registry PROM_COLLECTOR_REGISTRY named REGISTRY_NAME_DEFAULT . | |
pcr_t * | pcr_new (const char *name) |
Constructs a registry named default which contains one empty prom collector named default , only. | |
int | pcr_destroy (pcr_t *self) |
Destroy the given collector registry. | |
int | pcr_enable_process_metrics (pcr_t *self) |
Enable process metrics on the given collector registry. | |
int | pcr_enable_scrape_metrics (pcr_t *self) |
Create a scrape duration gauge metric and attach it to the given prom collector registry. | |
prom_metric_t * | pcr_must_register_metric (prom_metric_t *metric) |
Registers a metric with the default collector on PROM_COLLECTOR_REGISTRY. | |
int | pcr_register_metric (prom_metric_t *metric) |
Registers a metric with the default collector on PROM_COLLECTOR_REGISTRY. | |
int | pcr_register_collector (pcr_t *self, prom_collector_t *collector) |
Register a collector with the given registry. | |
prom_collector_t * | pcr_get (pcr_t *self, const char *name) |
Get a reference to the prom collector with the given name from the given prom collector registry. | |
char * | pcr_bridge (pcr_t *self) |
Export all relevant metrics registered with the given registry in the default metric exposition format as a single string. | |
int | pcr_validate_metric_name (pcr_t *self, const char *metric_name) |
Validates that the given metric name complies with the specification: | |
Variables | |
pcr_t * | PROM_COLLECTOR_REGISTRY |
Initialize the default registry by calling pcr_init() within your app. |
The collector registry registers collectors for metric exposition.
#define COLLECTOR_NAME_DEFAULT "default" |
Reserved name for libprom's own default prom collector, where usually new metrics get attached.
#define COLLECTOR_NAME_PROCESS "process" |
Reserved name for libprom's own process stats prom collector.
#define METRIC_LABEL_SCRAPE "libprom" |
Reserved label value for libprom's own scrape duration metrics.
#define METRIC_NAME_SCRAPE "scrape_duration_seconds" |
Reserved name for libprom's own scrape duration metric.
backward compatibility to 0.1.3 - will vanish soon.
#define REGISTRY_NAME_DEFAULT "default" |
Reserved name for libprom's own default prom collector registry.
typedef unsigned int PROM_INIT_FLAGS |
collection of prom collector registry features.
prom_init_flag
enum prom_init_flag |
flags for the setup of a prom collector registry.
pcr_init()
PROM_NONE |
placeholder for |
PROM_PROCESS |
Automatically setup and attach a |
PROM_SCRAPETIME |
Automatically create and use a metric to monitor the time needed to dump all the metrics of all registered collectors in Prometheus exposition format and include it in the dump as well. The metric gets labeled as |
PROM_SCRAPETIME_ALL |
Implies The related metrics get labeled with the name of the collector. |
PROM_COMPACT |
Omit any "# HELP" and These are wrt. the Prometheus exposition format optional and e.g. Victoria-Metrics vmagent as well as timeseries DB ignore them completely because simply not needed. So allows less trash and communication overhead. |
char* pcr_bridge | ( | pcr_t * | self | ) |
Export all relevant metrics registered with the given registry in the default metric exposition format as a single string.
This string MUST be freed to avoid unnecessary heap memory growth.
Reference: https://prometheus.io/docs/instrumenting/exposition_formats/
self | The registry containing the collectors with the relevant metrics. |
NULL
on failure, the export otherwise. int pcr_default_init | ( | void | ) |
Initializes the default collector registry.
PROM_COLLECTOR_REGISTRY
and enables metric collection on the executing process and sets the metric name prefix to METRIC_LABEL_SCRAPE
+ "_". Same as pcr_init
(PROM_PROCESS|PROM_SCRAPETIME, METRIC_LABEL_SCRAPE "_").
0
otherwise. int pcr_destroy | ( | pcr_t * | self | ) |
Destroy the given collector registry.
Before it releases its handles to registered collectors, it calls prom_collector_destroy()
on them, and this in turn calls prom_metric_destroy()
for all the collector's metrics. So keep in mind, that after this call all registered collectors and related metrics will not work anymore.
self | Registry to destroy. |
NULL
because it gets always passed to free()
and thus points to an invalid memory location on return. int pcr_enable_process_metrics | ( | pcr_t * | self | ) |
Enable process metrics on the given collector registry.
self | The registry, where to attach the process metrics. |
0
otherwise. int pcr_enable_scrape_metrics | ( | pcr_t * | self | ) |
Create a scrape duration gauge metric and attach it to the given prom collector registry.
If available, pcr_bridge()
measures the time needed to collect and export all metrics of the registry, updates the metric and appends it to the export.
self | Where to enable scrape duration monitoring. |
NULL
, or the metric could not be added to its default
collector, 0 otherwise. prom_collector_t* pcr_get | ( | pcr_t * | self, |
const char * | name | ||
) |
Get a reference to the prom collector with the given name from the given prom collector registry.
self | Registry to query. |
name | Name of the collector to lookup. |
NULL
if not found, a reference to the related prom collector otherwise. int pcr_init | ( | PROM_INIT_FLAGS | features, |
const char * | mprefix | ||
) |
Initializes the default collector registry PROM_COLLECTOR_REGISTRY
named REGISTRY_NAME_DEFAULT
.
features | If 0 , a prom collector registry gets created, which just contains a single empty collector named COLLECTOR_NAME_DEFAULT where per default all new metrics get attached. |
mprefix | If not NULL , prefix each metric's name with this string when metrics get exposed. E.g. one may use "appname_". |
prom_metric_t* pcr_must_register_metric | ( | prom_metric_t * | metric | ) |
Registers a metric with the default collector on PROM_COLLECTOR_REGISTRY.
The metric to be registered MUST NOT already be registered with the given. If so, the function calls exit() - probably not what you want! NOTE: PROM_COLLECTOR_REGISTRY must be registered via pcr_init() prior to calling this function. The metric will be added to the default registry's default collector.
metric | The metric to register. |
NULL
if registration failed. Constructs a registry named default
which contains one empty prom collector named default
, only.
name | Name of the collector registry. It MUST NOT be default . |
NULL
otherwise. int pcr_register_collector | ( | pcr_t * | self, |
prom_collector_t * | collector | ||
) |
Register a collector with the given registry.
If the registry already contains a collector with the same name, the registration will fail.
self | Where to register the collector. |
collector | The collector to register. |
0
otherwise. int pcr_register_metric | ( | prom_metric_t * | metric | ) |
Registers a metric with the default collector on PROM_COLLECTOR_REGISTRY.
See also: pcr_must_register_metric.
metric | The metric to register on PROM_COLLECTOR_REGISTRY* |
int pcr_validate_metric_name | ( | pcr_t * | self, |
const char * | metric_name | ||
) |
Validates that the given metric name complies with the specification:
Reference: https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels
Returns a non-zero integer value on failure, 0
otherwise.
self | Registry to use. |
metric_name | Name to validate |
0
otherwise. Initialize the default registry by calling pcr_init() within your app.