]> arthur.barton.de Git - netdata.git/commitdiff
track the duration of all alarms
authorCosta Tsaousis <costa@tsaousis.gr>
Tue, 16 Aug 2016 23:25:18 +0000 (02:25 +0300)
committerCosta Tsaousis <costa@tsaousis.gr>
Tue, 16 Aug 2016 23:25:18 +0000 (02:25 +0300)
plugins.d/Makefile.am
src/health.c
src/health.h

index 884b8242e410315d8533e011ef2ec8b9a235e229..32d6f78930f41ab2e574446b0292cd54d273226a 100644 (file)
@@ -8,6 +8,7 @@ dist_plugins_DATA = \
        $(NULL)
 
 dist_plugins_SCRIPTS = \
+       alarm.sh \
        cgroup-name.sh \
        charts.d.dryrun-helper.sh \
        charts.d.plugin \
index 6db51063df2f850d925a400ab34b6ffb674d0b64..50b5e5f8faf4d8648089a661bdc247ebd2c95a3f 100644 (file)
@@ -1451,7 +1451,7 @@ static inline void health_alarm_execute(ALARM_ENTRY *ae) {
     const char *exec = ae->exec;
     if(!exec) exec = health_default_exec;
 
-    snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf', '%s'",
+    snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u'",
               exec,
               alarm_entry_type2string(ae->type),
               ae->name,
@@ -1460,7 +1460,8 @@ static inline void health_alarm_execute(ALARM_ENTRY *ae) {
               rrdcalc_status2string(ae->old_status),
               ae->new_value,
               ae->old_value,
-              ae->source?ae->source:"UNKNOWN"
+              ae->source?ae->source:"UNKNOWN",
+              (uint32_t)ae->duration
     );
 
     debug(D_HEALTH, "executing command '%s'", buffer);
@@ -1491,6 +1492,7 @@ static inline void health_process_notifications(ALARM_ENTRY *ae) {
 
 static inline void health_alarm_log(time_t when, int type,
                 const char *name, const char *chart, const char *exec,
+                time_t duration,
                 calculated_number old_value, calculated_number new_value,
                 int old_status, int new_status,
                 const char *source
@@ -1508,7 +1510,7 @@ static inline void health_alarm_log(time_t when, int type,
     ae->new_value = new_value;
     ae->old_status = old_status;
     ae->new_status = new_status;
-
+    ae->duration = duration;
     // link it
     ae->next = health_log.alarms;
     health_log.alarms = ae;
@@ -1560,7 +1562,9 @@ static inline void rrdcalc_check_critical_event(RRDCALC *rc) {
     int new_status = rrdcalc_value2status(n);
 
     if(new_status != old_status) {
-        health_alarm_log(time(NULL), ALARM_ENTRY_TYPE_WARNING, rc->name, rc->rrdset->id, rc->exec, rc->old_value, rc->value, old_status, new_status, rc->source);
+        time_t now = time(NULL);
+        health_alarm_log(time(NULL), ALARM_ENTRY_TYPE_WARNING, rc->name, rc->rrdset->id, rc->exec, now - rc->last_status_change, rc->old_value, rc->value, old_status, new_status, rc->source);
+        rc->last_status_change = now;
         rc->critical_status = new_status;
     }
 }
@@ -1572,7 +1576,9 @@ static inline void rrdcalc_check_warning_event(RRDCALC *rc) {
     int new_status = rrdcalc_value2status(n);
 
     if(new_status != old_status) {
-        health_alarm_log(time(NULL), ALARM_ENTRY_TYPE_CRITICAL, rc->name, rc->rrdset->id, rc->exec, rc->old_value, rc->value, old_status, new_status, rc->source);
+        time_t now = time(NULL);
+        health_alarm_log(time(NULL), ALARM_ENTRY_TYPE_CRITICAL, rc->name, rc->rrdset->id, rc->exec, now - rc->last_status_change, rc->old_value, rc->value, old_status, new_status, rc->source);
+        rc->last_status_change = now;
         rc->warning_status = new_status;
     }
 }
index 2c30914457ded025b41a1a8f05fa7723d6e98282..0cd250973c2a4c3e149aa08c039ffe6e498df0aa 100644 (file)
@@ -147,6 +147,7 @@ typedef struct rrdcalc {
     int critical_status;
 
     time_t db_timestamp;
+    time_t last_status_change;
 
     calculated_number value;
     calculated_number old_value;
@@ -210,6 +211,7 @@ typedef struct rrdcalctemplate {
 typedef struct alarm_entry {
     uint32_t id;
     time_t when;
+    time_t duration;
     int type;
     char *name;
     char *chart;