aboutsummaryrefslogtreecommitdiff
path: root/src/lib/metrics/metrics_store_entry.h
blob: 8e8a8f39172adac240b6c0b18ddf90eb075f0a4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Copyright (c) 2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * @file metrics_store_entry.h
 * @brief Header for lib/metrics/metrics_store_entry.c
 **/

#ifndef TOR_LIB_METRICS_METRICS_STORE_ENTRY_H
#define TOR_LIB_METRICS_METRICS_STORE_ENTRY_H

#include "lib/cc/torint.h"

#include "lib/metrics/metrics_common.h"

#ifdef METRICS_STORE_ENTRY_PRIVATE

/** Metrics store entry. They reside in a metrics_store_t object and are
 * opaque to the outside world. */
struct metrics_store_entry_t {
  /** Type of entry. */
  metrics_type_t type;

  /** Name. */
  char *name;

  /** Help comment string. */
  char *help;

  /** Labels attached to that entry. If NULL, no labels.
   *
   * Labels are used to add extra context to a metrics. For example, a label
   * could be an onion address so the metrics can be differentiate. */
  smartlist_t *labels;

  /* Actual data. */
  union {
    metrics_counter_t counter;
    metrics_gauge_t gauge;
  } u;
};

#endif /* METRICS_STORE_ENTRY_PRIVATE */

typedef struct metrics_store_entry_t metrics_store_entry_t;

/* Allocators. */
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);
#define metrics_store_entry_free(entry) \
  FREE_AND_NULL(metrics_store_entry_t, metrics_store_entry_free_, (entry));

/* Accessors. */
int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry);
bool metrics_store_entry_has_label(const metrics_store_entry_t *entry,
                                   const char *label);

/* Modifiers. */
void metrics_store_entry_add_label(metrics_store_entry_t *entry,
                                   const char *label);
void metrics_store_entry_reset(metrics_store_entry_t *entry);
void metrics_store_entry_update(metrics_store_entry_t *entry,
                                const int64_t value);

#endif /* !defined(TOR_LIB_METRICS_METRICS_STORE_ENTRY_H) */