cleanup remaining custom variables when a host is removed
Costa Tsaousis (ktsaou) committed
Oct 15, 2017 at 23:13 UTC
43bfa0751dc3bbd199ad222bbb71c7c3d0ec70fa
5 files changed
+19
-4
src/freebsd_sysctl.c
+3
-2
@@ -646,7 +646,6 @@ int do_hw_intcnt(int update_every, usec_t dt) {
646
// --------------------------------------------------------------------
647
648
static RRDSET *st_interrupts = NULL;
649
- RRDDIM *rd_interrupts = NULL;
649
void *p;
650
651
if (unlikely(!st_interrupts))
@@ -670,9 +669,11 @@ int do_hw_intcnt(int update_every, usec_t dt) {
669
for (i = 0; i < nintr; i++) {
670
p = intrnames + i * (MAXCOMLEN + 1);
671
if (unlikely((intrcnt[i] != 0) && (*(char *) p != 0))) {
673
- rd_interrupts = rrddim_find(st_interrupts, p);
672
+ RRDDIM *rd_interrupts = rrddim_find(st_interrupts, p);
673
+
674
if (unlikely(!rd_interrupts))
675
rd_interrupts = rrddim_add(st_interrupts, p, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
676
+
677
rrddim_set_by_pointer(st_interrupts, rd_interrupts, intrcnt[i]);
678
}
679
}
src/health.h
+1
@@ -365,6 +365,7 @@ void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf);
365
extern RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *name);
366
extern void rrdvar_custom_host_variable_destroy(RRDHOST *host, const char *name);
367
extern void rrdvar_custom_host_variable_set(RRDHOST *host, RRDVAR *rv, calculated_number value);
368
+extern void rrdvar_free_remaining_variables(RRDHOST *host);
369
370
extern const char *rrdcalc_status2string(RRDCALC_STATUS status);
371
src/rrd.h
+3
@@ -497,6 +497,9 @@ struct rrdhost {
497
498
netdata_rwlock_t rrdhost_rwlock; // lock for this RRDHOST (protects rrdset_root linked list)
499
500
+ // ------------------------------------------------------------------------
501
+ // indexes
502
+
503
avl_tree_lock rrdset_root_index; // the host's charts index (by id)
504
avl_tree_lock rrdset_root_index_name; // the host's charts index (by name)
505
src/rrdhost.c
+4
-2
@@ -487,7 +487,8 @@ void rrdhost_free(RRDHOST *host) {
487
// ------------------------------------------------------------------------
488
// release its children resources
489
490
- while(host->rrdset_root) rrdset_free(host->rrdset_root);
490
+ while(host->rrdset_root)
491
+ rrdset_free(host->rrdset_root);
492
493
while(host->alarms)
494
rrdcalc_unlink_and_free(host, host->alarms);
@@ -495,8 +496,9 @@ void rrdhost_free(RRDHOST *host) {
496
while(host->templates)
497
rrdcalctemplate_unlink_and_free(host, host->templates);
498
498
- health_alarm_log_free(host);
499
+ rrdvar_free_remaining_variables(host);
500
501
+ health_alarm_log_free(host);
502
503
// ------------------------------------------------------------------------
504
// remove it from the indexes
src/rrdvar.c
+8
@@ -115,6 +115,7 @@ inline int rrdvar_callback_for_all_variables(RRDHOST *host, int (*callback)(void
115
RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *name) {
116
calculated_number *v = callocz(1, sizeof(calculated_number));
117
*v = NAN;
118
+
119
RRDVAR *rv = rrdvar_create_and_index("host", &host->variables_root_index, name, RRDVAR_TYPE_CALCULATED_ALLOCATED, v);
120
if(unlikely(!rv)) {
121
free(v);
@@ -132,6 +133,13 @@ RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *name) {
133
return rv;
134
}
135
136
+void rrdvar_free_remaining_variables(RRDHOST *host) {
137
+ while(host->variables_root_index.avl_tree.root) {
138
+ RRDVAR *rv = (RRDVAR *)host->variables_root_index.avl_tree.root;
139
+ rrdvar_free(host, &host->variables_root_index, rv);
140
+ }
141
+}
142
+
143
void rrdvar_custom_host_variable_destroy(RRDHOST *host, const char *name) {
144
char *variable = strdupz(name);
145
rrdvar_fix_name(variable);