1 #define NETDATA_HEALTH_INTERNALS
4 // ----------------------------------------------------------------------------
5 // RRDSETVAR management
8 static inline void rrdsetvar_free_variables(RRDSETVAR *rs) {
9 RRDSET *st = rs->rrdset;
13 rrdvar_free(st->rrdhost, &st->variables_root_index, rs->var_local);
18 rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family);
19 rs->var_family = NULL;
21 rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host);
26 rrdvar_free(st->rrdhost, &st->rrdfamily->variables_root_index, rs->var_family_name);
27 rs->var_family_name = NULL;
29 rrdvar_free(st->rrdhost, &st->rrdhost->variables_root_index, rs->var_host_name);
30 rs->var_host_name = NULL;
34 freez(rs->key_fullid);
35 rs->key_fullid = NULL;
37 freez(rs->key_fullname);
38 rs->key_fullname = NULL;
41 static inline void rrdsetvar_create_variables(RRDSETVAR *rs) {
42 rrdsetvar_free_variables(rs);
44 RRDSET *st = rs->rrdset;
48 char buffer[RRDVAR_MAX_LENGTH + 1];
49 snprintfz(buffer, RRDVAR_MAX_LENGTH, "%s.%s", st->id, rs->variable);
50 rs->key_fullid = strdupz(buffer);
52 snprintfz(buffer, RRDVAR_MAX_LENGTH, "%s.%s", st->name, rs->variable);
53 rs->key_fullname = strdupz(buffer);
57 rs->var_local = rrdvar_create_and_index("local", &st->variables_root_index, rs->variable, rs->type, rs->value);
61 rs->var_family = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_fullid, rs->type, rs->value);
62 rs->var_family_name = rrdvar_create_and_index("family", &st->rrdfamily->variables_root_index, rs->key_fullname, rs->type, rs->value);
66 rs->var_host = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullid, rs->type, rs->value);
67 rs->var_host_name = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullname, rs->type, rs->value);
71 RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options) {
72 debug(D_VARIABLES, "RRDVARSET create for chart id '%s' name '%s' with variable name '%s'", st->id, st->name, variable);
73 RRDSETVAR *rs = (RRDSETVAR *)callocz(1, sizeof(RRDSETVAR));
75 rs->variable = strdupz(variable);
78 rs->options = options;
81 rs->next = st->variables;
84 rrdsetvar_create_variables(rs);
89 void rrdsetvar_rename_all(RRDSET *st) {
90 debug(D_VARIABLES, "RRDSETVAR rename for chart id '%s' name '%s'", st->id, st->name);
92 RRDSETVAR *rs, *next = st->variables;
95 rrdsetvar_create_variables(rs);
98 rrdsetcalc_link_matching(st);
101 void rrdsetvar_free(RRDSETVAR *rs) {
102 RRDSET *st = rs->rrdset;
103 debug(D_VARIABLES, "RRDSETVAR free for chart id '%s' name '%s', variable '%s'", st->id, st->name, rs->variable);
105 if(st->variables == rs) {
106 st->variables = rs->next;
110 for (t = st->variables; t && t->next != rs; t = t->next);
111 if(!t) error("RRDSETVAR '%s' not found in chart '%s' variables linked list", rs->key_fullname, st->id);
112 else t->next = rs->next;
115 rrdsetvar_free_variables(rs);