8#ifndef ZEPHYR_INCLUDE_PROMETHEUS_COLLECTOR_H_
9#define ZEPHYR_INCLUDE_PROMETHEUS_COLLECTOR_H_
76#define PROMETHEUS_COLLECTOR_DEFINE(_name, ...) \
77 STRUCT_SECTION_ITERABLE(prometheus_collector, _name) = { \
78 .name = STRINGIFY(_name), \
79 .metrics = SYS_SLIST_STATIC_INIT(&_name.metrics), \
80 .lock = Z_MUTEX_INITIALIZER(_name.lock), \
81 .user_cb = COND_CODE_0( \
83 LIST_DROP_EMPTY(__VA_ARGS__, _)), \
85 (GET_ARG_N(1, __VA_ARGS__))), \
86 .user_data = COND_CODE_0( \
87 NUM_VA_ARGS_LESS_1(__VA_ARGS__), (NULL), \
89 GET_ARGS_LESS_N(1, __VA_ARGS__)))), \
121enum prometheus_walk_state {
122 PROMETHEUS_WALK_START,
123 PROMETHEUS_WALK_CONTINUE,
124 PROMETHEUS_WALK_STOP,
127struct prometheus_collector_walk_context {
131 enum prometheus_walk_state
state;
148 uint8_t *buffer,
size_t buffer_size);
166 ctx->state = PROMETHEUS_WALK_START;
int prometheus_collector_walk_metrics(struct prometheus_collector_walk_context *ctx, uint8_t *buffer, size_t buffer_size)
Walk through all metrics in a Prometheus collector and format them into a buffer.
static int prometheus_collector_walk_init(struct prometheus_collector_walk_context *ctx, struct prometheus_collector *collector)
Initialize the walker context to walk through all metrics.
Definition collector.h:158
int(* prometheus_scrape_cb_t)(struct prometheus_collector *collector, struct prometheus_metric *metric, void *user_data)
Callback used to scrape a collector for a specific metric.
Definition collector.h:41
const void * prometheus_collector_get_metric(struct prometheus_collector *collector, const char *name)
Get a metric from a Prometheus collector.
int prometheus_collector_register_metric(struct prometheus_collector *collector, struct prometheus_metric *metric)
Register a metric with a Prometheus collector.
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
#define EINVAL
Invalid argument.
Definition errno.h:60
Prometheus metric interface.
state
Definition parser_state.h:29
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Mutex Structure.
Definition kernel.h:3004
Prometheus collector definition.
Definition collector.h:50
const char * name
Name of the collector.
Definition collector.h:52
sys_slist_t metrics
Array of metrics associated with the collector.
Definition collector.h:54
struct k_mutex lock
Mutex to protect the metrics list manipulation.
Definition collector.h:56
void * user_data
User data.
Definition collector.h:62
prometheus_scrape_cb_t user_cb
User callback function.
Definition collector.h:60
Type used to represent a Prometheus metric base.
Definition metric.h:47
struct prometheus_collector * collector
Back pointer to the collector that this metric belongs to.
Definition metric.h:51
void * metric
Back pointer to the actual metric (counter, gauge, etc.).
Definition metric.h:56
void * user_data
User defined data.
Definition metric.h:68