-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnetdata.c
94 lines (79 loc) · 2.06 KB
/
netdata.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <stdio.h>
#include "netdata.h"
static
const char *
nd_algorithm_str[] = {
"absolute",
"incremental",
"percentage-of-absolute-row",
"percentage-of-incremental-row",
};
static
const char *
nd_charttype_str[] = {
"line",
"area",
"stacked",
};
static
const char *
check_null(const char * str) {
return str ? str : "";
}
static
void
print_type_prefix_id(const char * type, const char * prefix, const char * id) {
if (id)
printf("%s.%s_%s", type, check_null(prefix), id);
else
printf("%s.%s", type, check_null(prefix));
}
void
nd_chart(const char * type, const char * prefix, const char * id, const char * name,
const char * title, const char * units, const char * family, const char * context,
enum nd_charttype chart_type) {
fputs("\nCHART ", stdout);
print_type_prefix_id(type, prefix, id);
printf(" '%s' '%s' '%s' '%s' '%s' %s\n",
check_null(name), check_null(title), check_null(units), check_null(family),
check_null(context), nd_charttype_str[chart_type]);
}
void
nd_disable() {
puts("DISABLE");
}
void
nd_dimension(const char * id, const char * name, enum nd_algorithm alg,
int multiplier, int divisor, enum nd_visibility visibility) {
printf("DIMENSION %s '%s' %s %d %d",
id, check_null(name), nd_algorithm_str[alg], multiplier, divisor);
if (visibility == ND_HIDDEN) {
fputs(" hidden", stdout);
}
putchar('\n');
}
void
nd_begin(const char * type, const char * prefix, const char * id) {
nd_begin_time(type, prefix, id, 0);
}
void
nd_begin_time(const char * type, const char * prefix, const char * id, const unsigned long time) {
fputs("\nBEGIN ", stdout);
print_type_prefix_id(type, prefix, id);
/* Everything less then 10ms is ignored (the constant is in microseconds).
* We should not give this value first time the plugin is started, which is
* usually less than 10ms after the plugin start. */
if (time > 10000) {
printf(" %lu", time);
}
putchar('\n');
}
void
nd_end() {
puts("END");
}
void
nd_set(const char * name, const long value) {
printf("SET %s = %ld\n", name, value);
}