prometheus-client-c
0.1.1
Prometheus client for the C programming language
|
prometheus-client-c is a small suite of Prometheus client libraries targeted for the C programming language. In this brief tutorial you will learn how to create and register metrics, update metric samples, and expose metrics over HTTP.
prometheus-client-c supports the following metric types:
To get started using one of the metric types, declare the metric at file scope. For example:
Next, create a metric initialization function. You can create the metric and register it with the default metric collector registry in one chain of functions. A metric collector is responsible for collecting metrics and returning them. A metric collector registry is declared in global scope and contains metric collectors. More on this later...
To create a metric and register it with the default metric collector registry in one shot, you may chain the metric constructor into the prom_collector_registry_must_register_metric function. For example:
The first argument to prom_counter_new is the counter name. The second argument is the counter description. The third argument is the number of metric labels. In this case, we will only have one metric sample for this metric so we pass 0 to specify that no labels will be used. The 4th argument is an array of strings storing the metric labels. Since we have none, we pass NULL. A call to foo_metric_init within the program's main function will initialize the metrics for the file we just created to the default prometheus metric collector registery called PROM_COLLECTOR_REGISTRY_DEFAULT
Now that we have a metric configured for creation and registration, we can update our metric within any of the functions of the file in which it was declared. For example:
This function will increment the default metric sample for my_counter. Since we are not using metric labels, we pass NULL as the second argument.
At the start of the program's main function you need to do two things:
After initialization is complete, you may proceed to do work and update your metrics.
Take a look at the Files tab in this documentation site for more information about the public API available to you. Also, you can take a look at the examples directory at the Github repository for inspiration.