blob: 5836a581f1edd397ec5f4f1e11185cedeb22bb8f (
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
|
/* 2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* @file metrics_common.c
* @brief Common code for the metrics library
**/
#include <stddef.h>
#include "orconfig.h"
#include "lib/log/util_bug.h"
#include "lib/string/printf.h"
#include "lib/metrics/metrics_common.h"
/** Return string representation of a metric type. */
const char *
metrics_type_to_str(const metrics_type_t type)
{
switch (type) {
case METRICS_TYPE_COUNTER:
return "counter";
case METRICS_TYPE_GAUGE:
return "gauge";
case METRICS_TYPE_HISTOGRAM:
return "histogram";
default:
tor_assert_unreached();
}
}
/** Return a static buffer pointer that contains a formatted label on the form
* of key=value.
*
* Subsequent call to this function invalidates the previous buffer. */
const char *
metrics_format_label(const char *key, const char *value)
{
static char buf[128];
tor_snprintf(buf, sizeof(buf), "%s=\"%s\"", key, value);
return buf;
}
|