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
This commit is contained in:
parent
c2fcb04bf7
commit
0d509a07ca
|
@ -974,6 +974,8 @@ void reload_host_labels()
|
|||
|
||||
replace_label_list(localhost, new_labels);
|
||||
|
||||
health_label_log_save(localhost);
|
||||
|
||||
if(localhost->rrdpush_send_enabled && localhost->rrdpush_sender_buffer){
|
||||
localhost->labels_flag |= LABEL_FLAG_UPDATE_STREAM;
|
||||
rrdpush_send_labels(localhost);
|
||||
|
|
|
@ -107,6 +107,8 @@ extern void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae);
|
|||
|
||||
extern void *health_cmdapi_thread(void *ptr);
|
||||
|
||||
extern void health_label_log_save(RRDHOST *host);
|
||||
|
||||
extern SIMPLE_PATTERN *health_pattern_from_foreach(char *s);
|
||||
|
||||
#endif //NETDATA_HEALTH_H
|
||||
|
|
|
@ -67,6 +67,37 @@ inline void health_log_rotate(RRDHOST *host) {
|
|||
}
|
||||
}
|
||||
|
||||
inline void health_label_log_save(RRDHOST *host) {
|
||||
health_log_rotate(host);
|
||||
|
||||
if(likely(host->health_log_fp)) {
|
||||
BUFFER *wb = buffer_create(1024);
|
||||
netdata_rwlock_rdlock(&host->labels_rwlock);
|
||||
struct label *l=localhost->labels;
|
||||
while (l != NULL) {
|
||||
buffer_sprintf(wb,"%s=%s\t ", l->key, l->value);
|
||||
l = l->next;
|
||||
}
|
||||
netdata_rwlock_unlock(&host->labels_rwlock);
|
||||
|
||||
char *write = (char *) buffer_tostring(wb) ;
|
||||
|
||||
write[wb->len-2] = '\n';
|
||||
write[wb->len-1] = '\0';
|
||||
|
||||
if (unlikely(fprintf(host->health_log_fp, "L\t%s"
|
||||
, write
|
||||
) < 0))
|
||||
error("HEALTH [%s]: failed to save alarm log entry to '%s'. Health data may be lost in case of abnormal restart.",
|
||||
host->hostname, host->health_log_filename);
|
||||
else {
|
||||
host->health_log_entries_written++;
|
||||
}
|
||||
|
||||
buffer_free(wb);
|
||||
}
|
||||
}
|
||||
|
||||
inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae) {
|
||||
health_log_rotate(host);
|
||||
|
||||
|
@ -152,6 +183,9 @@ inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filena
|
|||
else s++;
|
||||
}
|
||||
|
||||
if(likely(*pointers[0] == 'L'))
|
||||
continue;
|
||||
|
||||
if(likely(*pointers[0] == 'U' || *pointers[0] == 'A')) {
|
||||
ALARM_ENTRY *ae = NULL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue