Tor 0.4.9.0-alpha-dev
metrics_common.h
Go to the documentation of this file.
1/* Copyright (c) 2020-2021, The Tor Project, Inc. */
2/* See LICENSE for licensing information */
3
4/**
5 * @file metrics_common.h
6 * @brief Header for lib/metrics/metrics_common.c
7 **/
8
9#ifndef TOR_LIB_METRICS_METRICS_COMMON_H
10#define TOR_LIB_METRICS_METRICS_COMMON_H
11
12#include "lib/cc/torint.h"
14
15/** Helper macro that must be used to construct the right namespaced metrics
16 * name. A name is a string so stringify the result. */
17#define METRICS_STR(val) #val
18#define METRICS_NAME(name) METRICS_STR(tor_ ## name)
19
20/** Format output type. */
21typedef enum {
22 /** Prometheus data output format. */
25
26/** Metric type. */
27typedef enum {
28 /* Increment only. */
29 METRICS_TYPE_COUNTER,
30 /* Can go up or down. */
31 METRICS_TYPE_GAUGE,
32 /* Cumulative counters for multiple observation buckets. */
33 METRICS_TYPE_HISTOGRAM,
35
37 /* The value of the counter of this bucket. */
38 uint64_t value;
39 /* Technically, this should be a floating point value, but in practice, we
40 * can make do with integer buckets. */
41 int64_t bucket;
43
44/** Metric counter object (METRICS_TYPE_COUNTER). */
45typedef struct metrics_counter_t {
46 uint64_t value;
48
49/** Metric gauge object (METRICS_TYPE_GAUGE). */
50typedef struct metrics_gauge_t {
51 int64_t value;
53
54/** Metric histogram object (METRICS_TYPE_HISTOGRAM). */
55typedef struct metrics_histogram_t {
56 /* The observation buckets. */
58 /* The number of observation buckets. */
59 size_t bucket_count;
60 /* The sum of all observations */
61 int64_t sum;
62 /* The total number of observations */
63 uint64_t count;
65
66const char *metrics_type_to_str(const metrics_type_t type);
67
68/* Helpers. */
69const char *metrics_format_label(const char *key, const char *value);
70
71#endif /* !defined(TOR_LIB_METRICS_METRICS_COMMON_H) */
metrics_type_t
const char * metrics_format_label(const char *key, const char *value)
const char * metrics_type_to_str(const metrics_type_t type)
metrics_format_t
@ METRICS_FORMAT_PROMETHEUS
Header for smartlist.c.
Integer definitions used throughout Tor.