Tor  0.4.7.0-alpha-dev
metrics_store_entry.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_store_entry.h
6  * @brief Header for lib/metrics/metrics_store_entry.c
7  **/
8 
9 #ifndef TOR_LIB_METRICS_METRICS_STORE_ENTRY_H
10 #define TOR_LIB_METRICS_METRICS_STORE_ENTRY_H
11 
12 #include "lib/cc/torint.h"
13 
15 
16 #ifdef METRICS_STORE_ENTRY_PRIVATE
17 
18 /** Metrics store entry. They reside in a metrics_store_t object and are
19  * opaque to the outside world. */
20 struct metrics_store_entry_t {
21  /** Type of entry. */
22  metrics_type_t type;
23 
24  /** Name. */
25  char *name;
26 
27  /** Help comment string. */
28  char *help;
29 
30  /** Labels attached to that entry. If NULL, no labels.
31  *
32  * Labels are used to add extra context to a metrics. For example, a label
33  * could be an onion address so the metrics can be differentiate. */
34  smartlist_t *labels;
35 
36  /* Actual data. */
37  union {
38  metrics_counter_t counter;
39  metrics_gauge_t gauge;
40  } u;
41 };
42 
43 #endif /* defined(METRICS_STORE_ENTRY_PRIVATE) */
44 
45 typedef struct metrics_store_entry_t metrics_store_entry_t;
46 
47 /* Allocators. */
48 metrics_store_entry_t *metrics_store_entry_new(const metrics_type_t type,
49  const char *name,
50  const char *help);
51 
52 void metrics_store_entry_free_(metrics_store_entry_t *entry);
53 #define metrics_store_entry_free(entry) \
54  FREE_AND_NULL(metrics_store_entry_t, metrics_store_entry_free_, (entry));
55 
56 /* Accessors. */
57 int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry);
58 bool metrics_store_entry_has_label(const metrics_store_entry_t *entry,
59  const char *label);
60 
61 /* Modifiers. */
62 void metrics_store_entry_add_label(metrics_store_entry_t *entry,
63  const char *label);
64 void metrics_store_entry_reset(metrics_store_entry_t *entry);
65 void metrics_store_entry_update(metrics_store_entry_t *entry,
66  const int64_t value);
67 
68 #endif /* !defined(TOR_LIB_METRICS_METRICS_STORE_ENTRY_H) */
const char * name
Definition: config.c:2434
Header for lib/metrics/metrics_common.c.
metrics_type_t
void metrics_store_entry_update(metrics_store_entry_t *entry, const int64_t value)
void metrics_store_entry_add_label(metrics_store_entry_t *entry, const char *label)
metrics_store_entry_t * metrics_store_entry_new(const metrics_type_t type, const char *name, const char *help)
void metrics_store_entry_free_(metrics_store_entry_t *entry)
int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry)
void metrics_store_entry_reset(metrics_store_entry_t *entry)
bool metrics_store_entry_has_label(const metrics_store_entry_t *entry, const char *label)
Integer definitions used throughout Tor.