Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Data Fields
prometheus_metric Struct Reference

An actual, honest to god, metric. More...

#include <res_prometheus.h>

Collaboration diagram for prometheus_metric:
Collaboration graph
[legend]

Data Fields

enum prometheus_metric_allocation_strategy allocation_strategy
 How this metric was allocated. More...
 
struct {
   struct prometheus_metric *   first
 
   struct prometheus_metric *   last
 
children
 A list of children metrics. More...
 
struct {
   struct prometheus_metric *   next
 
entry
 
void(* get_metric_value )(struct prometheus_metric *metric)
 Callback function to obtain the metric value. More...
 
const char * help
 Pointer to a static string defining this metric's help text. More...
 
struct prometheus_label labels [PROMETHEUS_MAX_LABELS]
 The metric's labels. More...
 
ast_mutex_t lock
 A lock protecting the metric value. More...
 
char name [PROMETHEUS_MAX_NAME_LENGTH]
 Our metric name. More...
 
enum prometheus_metric_type type
 What type of metric we are. More...
 
char value [PROMETHEUS_MAX_VALUE_LENGTH]
 The current value. More...
 

Detailed Description

An actual, honest to god, metric.

A bit of effort has gone into making this structure as efficient as we possibly can. Given that a lot of metrics can theoretically be dumped out, and that Asterisk attempts to be a "real-time" system, we want this process to be as efficient as possible. Countering that is the ridiculous flexibility that Prometheus allows for (and, to an extent, wants) - namely the notion of families of metrics delineated by their labels.

In order to balance this, metrics have arrays of labels. While this makes for a very large struct (such that loading one of these into memory is probably going to blow your cache), you will at least get the whole thing, since you're going to need those labels to figure out what you're looking like.

A hierarchy of metrics occurs when all metrics have the same name, but different labels.

We manage the hierarchy by allowing a metric to maintain their own list of related metrics. When metrics are registered (/c prometheus_metric_register), the function will automatically determine the hierarchy and place them into the appropriate lists. When you are creating metrics on the fly in a callback (prometheus_callback_register), you have to manage this hierarchy yourself, and only print out the first metric in a chain.

Note that EVERYTHING in a metric is immutable once registered, save for its value. Modifying the hierarchy, labels, name, help, whatever is going to result in a "bad time", and is also expressly against Prometheus law. (Don't get your liver eaten.)

Definition at line 193 of file res_prometheus.h.

Field Documentation

◆ allocation_strategy

enum prometheus_metric_allocation_strategy allocation_strategy

How this metric was allocated.

Definition at line 201 of file res_prometheus.h.

Referenced by prometheus_metric_create(), and prometheus_metric_free().

◆ 

struct { ... } children

A list of children metrics.

Children metrics have the same name but different label.

Registration of a metric will automatically nest the metrics; otherwise they are treated independently.

The help of the first metric in a chain of related metrics is the only one that will be printed.

For metrics output during a callback, the handler is responsible for managing the children. For metrics that are registered, the registration automatically nests the metrics.

Referenced by AST_TEST_DEFINE(), channels_scrape_cb(), prometheus_metric_free(), prometheus_metric_register(), prometheus_metric_to_string(), and prometheus_metric_unregister().

◆ 

struct { ... } entry

◆ first

struct prometheus_metric* first

Definition at line 249 of file res_prometheus.h.

◆ get_metric_value

void(* get_metric_value) (struct prometheus_metric *metric)

Callback function to obtain the metric value.

If updates need to happen when the metric is gathered, provide the callback function. Otherwise, leave it NULL.

Definition at line 233 of file res_prometheus.h.

Referenced by channels_scrape_cb(), and scrape_metrics().

◆ help

const char* help

Pointer to a static string defining this metric's help text.

Definition at line 211 of file res_prometheus.h.

Referenced by channels_scrape_cb(), endpoints_scrape_cb(), prometheus_counter_create(), prometheus_gauge_create(), prometheus_metric_create(), and prometheus_metric_to_string().

◆ labels

The metric's labels.

Definition at line 219 of file res_prometheus.h.

Referenced by prometheus_metric_cmp(), and prometheus_metric_full_to_string().

◆ last

struct prometheus_metric* last

Definition at line 249 of file res_prometheus.h.

◆ lock

A lock protecting the metric value.

Note
The metric must be locked prior to updating its value!

Definition at line 207 of file res_prometheus.h.

Referenced by prometheus_metric_create(), prometheus_metric_free(), and scrape_metrics().

◆ name

◆ next

struct prometheus_metric* next

Definition at line 250 of file res_prometheus.h.

◆ type

◆ value


The documentation for this struct was generated from the following file: