summaryrefslogtreecommitdiffstats
path: root/health/health_log.c
diff options
context:
space:
mode:
authorthiagoftsm <thiagoftsm@gmail.com>2020-01-17 11:43:02 +0000
committerGitHub <noreply@github.com>2020-01-17 11:43:02 +0000
commit0d509a07ca194950fa7f3e3265d4a948f7c0d35a (patch)
treeb959756c2ad282066c2d6558a1923f5d06834e8f /health/health_log.c
parentc2fcb04bf71baf625e764d0dc411a53f3ded1337 (diff)
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
Diffstat (limited to 'health/health_log.c')
-rw-r--r--health/health_log.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/health/health_log.c b/health/health_log.c
index c91cde6cbf..11714a2dd8 100644
--- a/health/health_log.c
+++ b/health/health_log.c
@@ -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;