Tor  0.4.6.0-alpha-dev
metrics_store_entry.h
Go to the documentation of this file.
1 /* Copyright (c) 2020, 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 /* 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) */
name
const char * name
Definition: config.c:2447
metrics_common.h
Header for lib/metrics/metrics_common.c.
metrics_store_entry_add_label
void metrics_store_entry_add_label(metrics_store_entry_t *entry, const char *label)
Definition: metrics_store_entry.c:111
torint.h
Integer definitions used throughout Tor.
metrics_counter_t
Definition: metrics_common.h:34
metrics_type_t
metrics_type_t
Definition: metrics_common.h:26
metrics_store_entry_reset
void metrics_store_entry_reset(metrics_store_entry_t *entry)
Definition: metrics_store_entry.c:81
metrics_store_entry_new
metrics_store_entry_t * metrics_store_entry_new(const metrics_type_t type, const char *name, const char *help)
Definition: metrics_store_entry.c:27
metrics_store_entry_get_value
int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry)
Definition: metrics_store_entry.c:90
metrics_gauge_t
Definition: metrics_common.h:39
metrics_store_entry_free_
void metrics_store_entry_free_(metrics_store_entry_t *entry)
Definition: metrics_store_entry.c:46
smartlist_t
Definition: smartlist_core.h:26
metrics_store_entry_update
void metrics_store_entry_update(metrics_store_entry_t *entry, const int64_t value)
Definition: metrics_store_entry.c:60
metrics_store_entry_has_label
bool metrics_store_entry_has_label(const metrics_store_entry_t *entry, const char *label)
Definition: metrics_store_entry.c:122