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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
#define NETDATA_HEALTH_INTERNALS
#include "common.h"
// ----------------------------------------------------------------------------
// RRDDIMVAR management
// DIMENSION VARIABLES
#define RRDDIMVAR_ID_MAX 1024
static inline void rrddimvar_free_variables(RRDDIMVAR *rs) {
RRDDIM *rd = rs->rrddim;
RRDSET *st = rd->rrdset;
RRDHOST *host = st->rrdhost;
// CHART VARIABLES FOR THIS DIMENSION
rrdvar_free(host, &st->rrdvar_root_index, rs->var_local_id);
rs->var_local_id = NULL;
rrdvar_free(host, &st->rrdvar_root_index, rs->var_local_name);
rs->var_local_name = NULL;
// FAMILY VARIABLES FOR THIS DIMENSION
rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_id);
rs->var_family_id = NULL;
rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_name);
rs->var_family_name = NULL;
rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_contextid);
rs->var_family_contextid = NULL;
rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_contextname);
rs->var_family_contextname = NULL;
// HOST VARIABLES FOR THIS DIMENSION
rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartidid);
rs->var_host_chartidid = NULL;
rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartidname);
rs->var_host_chartidname = NULL;
rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartnameid);
rs->var_host_chartnameid = NULL;
rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartnamename);
rs->var_host_chartnamename = NULL;
// KEYS
freez(rs->key_id);
rs->key_id = NULL;
freez(rs->key_name);
rs->key_name = NULL;
freez(rs->key_fullidid);
rs->key_fullidid = NULL;
freez(rs->key_fullidname);
rs->key_fullidname = NULL;
freez(rs->key_contextid);
rs->key_contextid = NULL;
freez(rs->key_contextname);
rs->key_contextname = NULL;
freez(rs->key_fullnameid);
rs->key_fullnameid = NULL;
freez(rs->key_fullnamename);
rs->key_fullnamename = NULL;
}
static inline void rrddimvar_create_variables(RRDDIMVAR *rs) {
rrddimvar_free_variables(rs);
RRDDIM *rd = rs->rrddim;
RRDSET *st = rd->rrdset;
RRDHOST *host = st->rrdhost;
char buffer[RRDDIMVAR_ID_MAX + 1];
// KEYS
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s%s%s", rs->prefix, rd->id, rs->suffix);
rs->key_id = strdupz(buffer);
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s%s%s", rs->prefix, rd->name, rs->suffix);
rs->key_name = strdupz(buffer);
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->key_id);
rs->key_fullidid = strdupz(buffer);
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->id, rs->key_name);
rs->key_fullidname = strdupz(buffer);
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->key_id);
rs->key_contextid = strdupz(buffer);
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->context, rs->key_name);
rs->key_contextname = strdupz(buffer);
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->key_id);
rs->key_fullnameid = strdupz(buffer);
snprintfz(buffer, RRDDIMVAR_ID_MAX, "%s.%s", st->name, rs->key_name);
rs->key_fullnamename = strdupz(buffer);
// CHART VARIABLES FOR THIS DIMENSION
// -----------------------------------
//
// dimensions are available as:
// - $id
// - $name
rs->var_local_id = rrdvar_create_and_index("local", &st->rrdvar_root_index, rs->key_id, rs->type, rs->value);
rs->var_local_name = rrdvar_create_and_index("local", &st->rrdvar_root_index, rs->key_name, rs->type, rs->value);
// FAMILY VARIABLES FOR THIS DIMENSION
// -----------------------------------
//
// dimensions are available as:
// - $id (only the first, when multiple overlap)
// - $name (only the first, when multiple overlap)
// - $chart-context.id
// - $chart-context.name
rs->var_family_id = rrdvar_create_and_index("family", &st->rrdfamily->rrdvar_root_index, rs->key_id, rs->type, rs->value);
rs->var_family_name = rrdvar_create_and_index("family", &st->rrdfamily->rrdvar_root_index, rs->key_name, rs->type, rs->value);
rs->var_family_contextid = rrdvar_create_and_index("family", &st->rrdfamily->rrdvar_root_index, rs->key_contextid, rs->type, rs->value);
rs->var_family_contextname = rrdvar_create_and_index("family", &st->rrdfamily->rrdvar_root_index, rs->key_contextname, rs->type, rs->value);
// HOST VARIABLES FOR THIS DIMENSION
// -----------------------------------
//
// dimensions are available as:
// - $chart-id.id
// - $chart-id.name
// - $chart-name.id
// - $chart-name.name
rs->var_host_chartidid = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullidid, rs->type, rs->value);
rs->var_host_chartidname = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullidname, rs->type, rs->value);
rs->var_host_chartnameid = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullnameid, rs->type, rs->value);
rs->var_host_chartnamename = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullnamename, rs->type, rs->value);
}
RRDDIMVAR *rrddimvar_create(RRDDIM *rd, RRDVAR_TYPE type, const char *prefix, const char *suffix, void *value, RRDVAR_OPTIONS options) {
RRDSET *st = rd->rrdset;
debug(D_VARIABLES, "RRDDIMSET create for chart id '%s' name '%s', dimension id '%s', name '%s%s%s'", st->id, st->name, rd->id, (prefix)?prefix:"", rd->name, (suffix)?suffix:"");
if(!prefix) prefix = "";
if(!suffix) suffix = "";
RRDDIMVAR *rs = (RRDDIMVAR *)callocz(1, sizeof(RRDDIMVAR));
rs->prefix = strdupz(prefix);
rs->suffix = strdupz(suffix);
rs->type = type;
rs->value = value;
rs->options = options;
rs->rrddim = rd;
rs->next = rd->variables;
rd->variables = rs;
rrddimvar_create_variables(rs);
return rs;
}
void rrddimvar_rename_all(RRDDIM *rd) {
RRDSET *st = rd->rrdset;
debug(D_VARIABLES, "RRDDIMSET rename for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
RRDDIMVAR *rs, *next = rd->variables;
while((rs = next)) {
next = rs->next;
rrddimvar_create_variables(rs);
}
}
void rrddimvar_free(RRDDIMVAR *rs) {
RRDDIM *rd = rs->rrddim;
RRDSET *st = rd->rrdset;
debug(D_VARIABLES, "RRDDIMSET free for chart id '%s' name '%s', dimension id '%s', name '%s', prefix='%s', suffix='%s'", st->id, st->name, rd->id, rd->name, rs->prefix, rs->suffix);
rrddimvar_free_variables(rs);
if(rd->variables == rs) {
debug(D_VARIABLES, "RRDDIMSET removing first entry for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
rd->variables = rs->next;
}
else {
debug(D_VARIABLES, "RRDDIMSET removing non-first entry for chart id '%s' name '%s', dimension id '%s', name '%s'", st->id, st->name, rd->id, rd->name);
RRDDIMVAR *t;
for (t = rd->variables; t && t->next != rs; t = t->next) ;
if(!t) error("RRDDIMVAR '%s' not found in dimension '%s/%s' variables linked list", rs->key_name, st->id, rd->id);
else t->next = rs->next;
}
freez(rs->prefix);
freez(rs->suffix);
freez(rs);
}
|