libprom  1.2.0
C based libraries to expose metrics in Promtheus exposition format
prom_collector_registry.h
Go to the documentation of this file.
1 /*
2 Copyright 2019-2020 DigitalOcean Inc.
3 Copyright 2021 Jens Elkner <jel+libprom@cs.uni-magdeburg.de>
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */
17 
23 #ifndef PROM_REGISTRY_H
24 #define PROM_REGISTRY_H
25 
26 #include <stdbool.h>
27 #include "prom_collector.h"
28 #include "prom_metric.h"
29 
32 #define METRIC_LABEL_SCRAPE "libprom"
33 
35 #define METRIC_NAME_SCRAPE "scrape_duration_seconds"
36 
39 #define COLLECTOR_NAME_DEFAULT "default"
40 
42 #define COLLECTOR_NAME_PROCESS "process"
43 
45 #define REGISTRY_NAME_DEFAULT "default"
46 
53  PROM_NONE = 0,
73 };
74 
78 typedef unsigned int PROM_INIT_FLAGS;
79 
83 typedef struct pcr pcr_t;
84 
91 #define PROM_COLLECTOR_REGISTRY_DEFAULT PROM_COLLECTOR_REGISTRY
92 
100 int pcr_default_init(void);
101 
112 int pcr_init(PROM_INIT_FLAGS features, const char *mprefix);
113 
120 pcr_t *pcr_new(const char *name);
121 
134 int pcr_destroy(pcr_t *self);
135 
142 
153 
168 
179 
187 int pcr_register_collector(pcr_t *self, prom_collector_t *collector);
188 
197 prom_collector_t *pcr_get(pcr_t *self, const char *name);
198 
209 char *pcr_bridge(pcr_t *self);
210 
225 int pcr_validate_metric_name(pcr_t *self, const char *metric_name);
226 
237 int pcr_check_name(const char *name, bool is_label);
238 
239 #endif // PROM_H
pcr_enable_process_metrics
int pcr_enable_process_metrics(pcr_t *self)
Enable process metrics on the given collector registry.
PROM_NONE
@ PROM_NONE
placeholder for 0 - implies nothing
Definition: prom_collector_registry.h:53
prom_metric.h
Functions for retrieving metric samples from metrics given an ordered set of labels.
prom_metric_t
struct prom_metric prom_metric_t
A prometheus metric.
Definition: prom_metric.h:43
PROM_SCRAPETIME_ALL
@ PROM_SCRAPETIME_ALL
Implies PROM_SCRAPETIME, but measures and dumps the dump time of every single collector as well.
Definition: prom_collector_registry.h:67
pcr_t
struct pcr pcr_t
A prom_registry_t is responsible for registering metrics and briding them to the string exposition fo...
Definition: prom_collector_registry.h:83
pcr_get
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.
PROM_COMPACT
@ PROM_COMPACT
Omit any "# HELP" and "# TYPE" lines in metric exports.
Definition: prom_collector_registry.h:72
pcr_enable_scrape_metrics
int pcr_enable_scrape_metrics(pcr_t *self)
Create a scrape duration gauge metric and attach it to the given prom collector registry.
PROM_COLLECTOR_REGISTRY
pcr_t * PROM_COLLECTOR_REGISTRY
Initialize the default registry by calling pcr_init() within your app.
pcr_init
int pcr_init(PROM_INIT_FLAGS features, const char *mprefix)
Initializes the default collector registry PROM_COLLECTOR_REGISTRY named REGISTRY_NAME_DEFAULT.
prom_collector.h
A prom_collector is used to collect metrics.
pcr_bridge
char * pcr_bridge(pcr_t *self)
Export all relevant metrics registered with the given registry in the default metric exposition forma...
PROM_INIT_FLAGS
unsigned int PROM_INIT_FLAGS
collection of prom collector registry features.
Definition: prom_collector_registry.h:78
pcr_register_metric
int pcr_register_metric(prom_metric_t *metric)
Registers a metric with the default collector on PROM_COLLECTOR_REGISTRY.
pcr_default_init
int pcr_default_init(void)
Initializes the default collector registry.
prom_init_flag
prom_init_flag
flags for the setup of a prom collector registry.
Definition: prom_collector_registry.h:51
PROM_PROCESS
@ PROM_PROCESS
Automatically setup and attach a process collector, which collects stats of this process on pcr_bridg...
Definition: prom_collector_registry.h:57
pcr_destroy
int pcr_destroy(pcr_t *self)
Destroy the given collector registry.
pcr_validate_metric_name
int pcr_validate_metric_name(pcr_t *self, const char *metric_name)
Validates that the given metric name complies with the specification:
prom_collector_t
struct prom_collector prom_collector_t
A prom collector calls collect to prepare metrics and return them to the registry to which it is regi...
Definition: prom_collector.h:34
pcr_register_collector
int pcr_register_collector(pcr_t *self, prom_collector_t *collector)
Register a collector with the given registry.
pcr_new
pcr_t * pcr_new(const char *name)
Constructs a registry named default which contains one empty prom collector named default ,...
pcr_check_name
int pcr_check_name(const char *name, bool is_label)
Check whether the given label | metric name complies with the specification:
PROM_SCRAPETIME
@ PROM_SCRAPETIME
Automatically create and use a metric to monitor the time needed to dump all the metrics of all regis...
Definition: prom_collector_registry.h:63
pcr_must_register_metric
prom_metric_t * pcr_must_register_metric(prom_metric_t *metric)
Registers a metric with the default collector on PROM_COLLECTOR_REGISTRY.