Alarm Log labels (#7548)
* alarm_log_with_labels: Alarm Log Rebase of alarm log to commit against master * alarm_log_with_labels: Remove lock This commit removes unecessary locks from health_log * alarm_log_with_labels: Restore and Rebase Remove previous changes and rebase the PR * alarm_log_with_labels: Unique line This commit brings an unique line to alarm log * alarm_log_with_labels: Correct separator This log file uses tabulation instead comma * alarm_log_with_labels: Fix memory leak There was a missing call for buffer_free
thiagoftsm committed
Jan 17, 2020 at 11:43 UTC
0d509a07ca194950fa7f3e3265d4a948f7c0d35a
3 files changed
+38
database/rrdhost.c
+2
@@ -974,6 +974,8 @@ void reload_host_labels()
974
975
replace_label_list(localhost, new_labels);
976
977
+ health_label_log_save(localhost);
978
+
979
if(localhost->rrdpush_send_enabled && localhost->rrdpush_sender_buffer){
980
localhost->labels_flag |= LABEL_FLAG_UPDATE_STREAM;
981
rrdpush_send_labels(localhost);
health/health.h
+2
@@ -107,6 +107,8 @@ extern void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae);
107
108
extern void *health_cmdapi_thread(void *ptr);
109
110
+extern void health_label_log_save(RRDHOST *host);
111
+
112
extern SIMPLE_PATTERN *health_pattern_from_foreach(char *s);
113
114
#endif //NETDATA_HEALTH_H
health/health_log.c
+34
@@ -67,6 +67,37 @@ inline void health_log_rotate(RRDHOST *host) {
67
}
68
}
69
70
+inline void health_label_log_save(RRDHOST *host) {
71
+ health_log_rotate(host);
72
+
73
+ if(likely(host->health_log_fp)) {
74
+ BUFFER *wb = buffer_create(1024);
75
+ netdata_rwlock_rdlock(&host->labels_rwlock);
76
+ struct label *l=localhost->labels;
77
+ while (l != NULL) {
78
+ buffer_sprintf(wb,"%s=%s\t ", l->key, l->value);
79
+ l = l->next;
80
+ }
81
+ netdata_rwlock_unlock(&host->labels_rwlock);
82
+
83
+ char *write = (char *) buffer_tostring(wb) ;
84
+
85
+ write[wb->len-2] = '\n';
86
+ write[wb->len-1] = '\0';
87
+
88
+ if (unlikely(fprintf(host->health_log_fp, "L\t%s"
89
+ , write
90
+ ) < 0))
91
+ error("HEALTH [%s]: failed to save alarm log entry to '%s'. Health data may be lost in case of abnormal restart.",
92
+ host->hostname, host->health_log_filename);
93
+ else {
94
+ host->health_log_entries_written++;
95
+ }
96
+
97
+ buffer_free(wb);
98
+ }
99
+}
100
+
101
inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae) {
102
health_log_rotate(host);
103
@@ -152,6 +183,9 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
183
else s++;
184
}
185
186
+ if(likely(*pointers[0] == 'L'))
187
+ continue;
188
+
189
if(likely(*pointers[0] == 'U' || *pointers[0] == 'A')) {
190
ALARM_ENTRY *ae = NULL;
191