Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Prometheus API

Data Structures

struct  prometheus_collector
 Prometheus collector definition. More...
 
struct  prometheus_counter
 Type used to represent a Prometheus counter metric. More...
 
struct  prometheus_gauge
 Type used to represent a Prometheus gauge metric. More...
 
struct  prometheus_histogram_bucket
 Prometheus histogram bucket definition. More...
 
struct  prometheus_histogram
 Type used to represent a Prometheus histogram metric. More...
 
struct  prometheus_label
 Prometheus label definition. More...
 
struct  prometheus_metric
 Type used to represent a Prometheus metric base. More...
 
struct  prometheus_summary_quantile
 Prometheus summary quantile definition. More...
 
struct  prometheus_summary
 Type used to represent a Prometheus summary metric. More...
 

Macros

#define PROMETHEUS_COLLECTOR_DEFINE(_name)
 Prometheus Collector definition.
 
#define PROMETHEUS_COUNTER_DEFINE(_name, _detail)
 Prometheus Counter definition.
 
#define PROMETHEUS_GAUGE_DEFINE(_name, _detail)
 Prometheus Gauge definition.
 
#define PROMETHEUS_HISTOGRAM_DEFINE(_name, _detail)
 Prometheus Histogram definition.
 
#define MAX_PROMETHEUS_LABEL_KEY_LENGTH   16
 
#define MAX_PROMETHEUS_LABEL_VALUE_LENGTH   16
 
#define MAX_PROMETHEUS_LABELS_PER_METRIC   5
 
#define MAX_METRIC_NAME_LENGTH   32
 
#define MAX_METRIC_DESCRIPTION_LENGTH   64
 
#define PROMETHEUS_SUMMARY_DEFINE(_name, _detail)
 Prometheus Summary definition.
 

Enumerations

enum  prometheus_metric_type { PROMETHEUS_COUNTER = 0 , PROMETHEUS_GAUGE , PROMETHEUS_SUMMARY , PROMETHEUS_HISTOGRAM }
 Prometheus metric types. More...
 

Functions

int prometheus_collector_register_metric (struct prometheus_collector *collector, struct prometheus_metric *metric)
 Register a metric with a Prometheus collector.
 
const void * prometheus_collector_get_metric (const struct prometheus_collector *collector, const char *name)
 Get a metric from a Prometheus collector.
 
int prometheus_counter_inc (struct prometheus_counter *counter)
 Increment the value of a Prometheus counter metric Increments the value of the specified counter metric by one.
 
int prometheus_format_exposition (const struct prometheus_collector *collector, char *buffer, size_t buffer_size)
 Format exposition data for Prometheus.
 
int prometheus_gauge_set (struct prometheus_gauge *gauge, double value)
 Set the value of a Prometheus gauge metric.
 
int prometheus_histogram_observe (struct prometheus_histogram *histogram, double value)
 Observe a value in a Prometheus histogram metric.
 
int prometheus_summary_observe (struct prometheus_summary *summary, double value)
 Observes a value in a Prometheus summary metric.
 

Detailed Description

Since
4.0
Version
0.1.0

Macro Definition Documentation

◆ MAX_METRIC_DESCRIPTION_LENGTH

#define MAX_METRIC_DESCRIPTION_LENGTH   64

◆ MAX_METRIC_NAME_LENGTH

#define MAX_METRIC_NAME_LENGTH   32

◆ MAX_PROMETHEUS_LABEL_KEY_LENGTH

#define MAX_PROMETHEUS_LABEL_KEY_LENGTH   16

◆ MAX_PROMETHEUS_LABEL_VALUE_LENGTH

#define MAX_PROMETHEUS_LABEL_VALUE_LENGTH   16

◆ MAX_PROMETHEUS_LABELS_PER_METRIC

#define MAX_PROMETHEUS_LABELS_PER_METRIC   5

◆ PROMETHEUS_COLLECTOR_DEFINE

#define PROMETHEUS_COLLECTOR_DEFINE ( _name)

#include <zephyr/net/prometheus/collector.h>

Value:
.name = STRINGIFY(_name), .size = 0, .metric = {0}}
#define STRUCT_SECTION_ITERABLE(struct_type, varname)
Defines a new element for an iterable section.
Definition iterable_sections.h:216
#define STRINGIFY(s)
Definition common.h:134
Prometheus collector definition.
Definition collector.h:32

Prometheus Collector definition.

This macro defines a Collector.

Parameters
_nameThe collector's name.

◆ PROMETHEUS_COUNTER_DEFINE

#define PROMETHEUS_COUNTER_DEFINE ( _name,
_detail )

#include <zephyr/net/prometheus/counter.h>

Value:
static STRUCT_SECTION_ITERABLE(prometheus_counter, _name) = {.base = (void *)(_detail), \
.value = 0}
Type used to represent a Prometheus counter metric.
Definition counter.h:30

Prometheus Counter definition.

This macro defines a Counter metric.

Parameters
_nameThe channel's name.
_detailThe metric base.

Example usage:

struct prometheus_metric http_request_counter = {
.name = "http_request_counter",
.description = "HTTP request counter",
.num_labels = 1,
.labels = {
{ .key = "http_request", .value = "request_count",}
},
};
PROMETHEUS_COUNTER_DEFINE(test_counter, &test_counter_metric);
#define PROMETHEUS_COUNTER_DEFINE(_name, _detail)
Prometheus Counter definition.
Definition counter.h:61
@ PROMETHEUS_COUNTER
Prometheus Counter.
Definition metric.h:30
Type used to represent a Prometheus metric base.
Definition metric.h:48

◆ PROMETHEUS_GAUGE_DEFINE

#define PROMETHEUS_GAUGE_DEFINE ( _name,
_detail )

#include <zephyr/net/prometheus/gauge.h>

Value:
static STRUCT_SECTION_ITERABLE(prometheus_gauge, _name) = {.base = (void *)(_detail), \
.value = 0}
Type used to represent a Prometheus gauge metric.
Definition gauge.h:28

Prometheus Gauge definition.

This macro defines a Gauge metric.

Parameters
_nameThe channel's name.
_detailThe metric base.

Example usage:

struct prometheus_metric http_request_gauge = {
.name = "http_request_gauge",
.description = "HTTP request gauge",
.num_labels = 1,
.labels = {
{ .key = "http_request", .value = "request_count",}
},
};
PROMETHEUS_GAUGE_DEFINE(test_gauge, &test_gauge_metric);
#define PROMETHEUS_GAUGE_DEFINE(_name, _detail)
Prometheus Gauge definition.
Definition gauge.h:60
@ PROMETHEUS_GAUGE
Prometheus Gauge.
Definition metric.h:32

◆ PROMETHEUS_HISTOGRAM_DEFINE

#define PROMETHEUS_HISTOGRAM_DEFINE ( _name,
_detail )

#include <zephyr/net/prometheus/histogram.h>

Value:
static STRUCT_SECTION_ITERABLE(prometheus_histogram, _name) = {.base = (void *)(_detail), \
.buckets = NULL, \
.num_buckets = 0, \
.sum = 0, \
.count = 0}
Type used to represent a Prometheus histogram metric.
Definition histogram.h:42

Prometheus Histogram definition.

This macro defines a Histogram metric.

Parameters
_nameThe channel's name.
_detailThe metric base.

Example usage:

struct prometheus_metric http_request_gauge = {
.name = "http_request_histograms",
.description = "HTTP request histogram",
.num_labels = 1,
.labels = {
{ .key = "request_latency", .value = "request_latency_seconds",}
},
};
PROMETHEUS_HISTOGRAM_DEFINE(test_histogram, &test_histogram_metric);
#define PROMETHEUS_HISTOGRAM_DEFINE(_name, _detail)
Prometheus Histogram definition.
Definition histogram.h:80
@ PROMETHEUS_HISTOGRAM
Prometheus Histogram.
Definition metric.h:36

◆ PROMETHEUS_SUMMARY_DEFINE

#define PROMETHEUS_SUMMARY_DEFINE ( _name,
_detail )

#include <zephyr/net/prometheus/summary.h>

Value:
static STRUCT_SECTION_ITERABLE(prometheus_summary, _name) = {.base = (void *)(_detail), \
.quantiles = NULL, \
.num_quantiles = 0, \
.sum = 0, \
.count = 0}
Type used to represent a Prometheus summary metric.
Definition summary.h:42

Prometheus Summary definition.

This macro defines a Summary metric.

Parameters
_nameThe channel's name.
_detailThe metric base.

Example usage:

struct prometheus_metric http_request_gauge = {
.name = "http_request_summary",
.description = "HTTP request summary",
.num_labels = 1,
.labels = {
{ .key = "request_latency", .value = "request_latency_seconds",}
},
};
PROMETHEUS_SUMMARY_DEFINE(test_summary, &test_summary_metric);
#define PROMETHEUS_SUMMARY_DEFINE(_name, _detail)
Prometheus Summary definition.
Definition summary.h:81
@ PROMETHEUS_SUMMARY
Prometheus Summary.
Definition metric.h:34

Enumeration Type Documentation

◆ prometheus_metric_type

#include <zephyr/net/prometheus/metric.h>

Prometheus metric types.

Enumerator
PROMETHEUS_COUNTER 

Prometheus Counter.

PROMETHEUS_GAUGE 

Prometheus Gauge.

PROMETHEUS_SUMMARY 

Prometheus Summary.

PROMETHEUS_HISTOGRAM 

Prometheus Histogram.

Function Documentation

◆ prometheus_collector_get_metric()

const void * prometheus_collector_get_metric ( const struct prometheus_collector * collector,
const char * name )

#include <zephyr/net/prometheus/collector.h>

Get a metric from a Prometheus collector.

Retrieves the metric with the specified name from the given collector.

Parameters
collectorPointer to the collector to retrieve the metric from.
nameName of the metric to retrieve.
Returns
Pointer to the retrieved metric, or NULL if not found.

◆ prometheus_collector_register_metric()

int prometheus_collector_register_metric ( struct prometheus_collector * collector,
struct prometheus_metric * metric )

#include <zephyr/net/prometheus/collector.h>

Register a metric with a Prometheus collector.

Registers the specified metric with the given collector.

Parameters
collectorPointer to the collector to register the metric with.
metricPointer to the metric to register.
Returns
0 if successful, otherwise a negative error code.
Return values
-EINVALInvalid arguments.
-ENOMEMNot enough memory to register the metric.

◆ prometheus_counter_inc()

int prometheus_counter_inc ( struct prometheus_counter * counter)

#include <zephyr/net/prometheus/counter.h>

Increment the value of a Prometheus counter metric Increments the value of the specified counter metric by one.

Parameters
counterPointer to the counter metric to increment.
Returns
0 on success, negative errno on error.

◆ prometheus_format_exposition()

int prometheus_format_exposition ( const struct prometheus_collector * collector,
char * buffer,
size_t buffer_size )

#include <zephyr/net/prometheus/formatter.h>

Format exposition data for Prometheus.

Formats the exposition data collected by the specified collector into the provided buffer. Function to format metric data according to Prometheus text-based format

Parameters
collectorPointer to the collector containing the data to format.
bufferPointer to the buffer where the formatted exposition data will be stored.
buffer_sizeSize of the buffer.
Returns
0 on success, negative errno on error.

◆ prometheus_gauge_set()

int prometheus_gauge_set ( struct prometheus_gauge * gauge,
double value )

#include <zephyr/net/prometheus/gauge.h>

Set the value of a Prometheus gauge metric.

Sets the value of the specified gauge metric to the given value.

Parameters
gaugePointer to the gauge metric to set.
valueValue to set the gauge metric to.
Returns
0 on success, -EINVAL if the value is negative.

◆ prometheus_histogram_observe()

int prometheus_histogram_observe ( struct prometheus_histogram * histogram,
double value )

#include <zephyr/net/prometheus/histogram.h>

Observe a value in a Prometheus histogram metric.

Observes the specified value in the given histogram metric.

Parameters
histogramPointer to the histogram metric to observe.
valueValue to observe in the histogram metric.
Returns
0 on success, -EINVAL if the value is negative.

◆ prometheus_summary_observe()

int prometheus_summary_observe ( struct prometheus_summary * summary,
double value )

#include <zephyr/net/prometheus/summary.h>

Observes a value in a Prometheus summary metric.

Observes the specified value in the given summary metric.

Parameters
summaryPointer to the summary metric to observe.
valueValue to observe in the summary metric.
Returns
0 on success, -EINVAL if the value is negative.