@cryptotaxi247 / netdata-1 / commits / 1d30ff56f

track the duration of all alarms

Costa Tsaousis committed Aug 17, 2016 at 02:25 UTC 1d30ff56f851c555cec4bb70617f6bfc8a19b937
3 files changed +14 -5
plugins.d/Makefile.am
+1
@@ -8,6 +8,7 @@ dist_plugins_DATA = \
8 $(NULL)
9
10 dist_plugins_SCRIPTS = \
11 + alarm.sh \
12 cgroup-name.sh \
13 charts.d.dryrun-helper.sh \
14 charts.d.plugin \
src/health.c
+11 -5
@@ -1451,7 +1451,7 @@ static inline void health_alarm_execute(ALARM_ENTRY *ae) {
1451 const char *exec = ae->exec;
1452 if(!exec) exec = health_default_exec;
1453
1454 - snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf', '%s'",
1454 + snprintfz(buffer, FILENAME_MAX, "exec %s '%s' '%s' '%s' '%s' '%s' '%0.0Lf' '%0.0Lf' '%s' '%u'",
1455 exec,
1456 alarm_entry_type2string(ae->type),
1457 ae->name,
@@ -1460,7 +1460,8 @@ static inline void health_alarm_execute(ALARM_ENTRY *ae) {
1460 rrdcalc_status2string(ae->old_status),
1461 ae->new_value,
1462 ae->old_value,
1463 - ae->source?ae->source:"UNKNOWN"
1463 + ae->source?ae->source:"UNKNOWN",
1464 + (uint32_t)ae->duration
1465 );
1466
1467 debug(D_HEALTH, "executing command '%s'", buffer);
@@ -1491,6 +1492,7 @@ static inline void health_process_notifications(ALARM_ENTRY *ae) {
1492
1493 static inline void health_alarm_log(time_t when, int type,
1494 const char *name, const char *chart, const char *exec,
1495 + time_t duration,
1496 calculated_number old_value, calculated_number new_value,
1497 int old_status, int new_status,
1498 const char *source
@@ -1508,7 +1510,7 @@ static inline void health_alarm_log(time_t when, int type,
1510 ae->new_value = new_value;
1511 ae->old_status = old_status;
1512 ae->new_status = new_status;
1511 -
1513 + ae->duration = duration;
1514 // link it
1515 ae->next = health_log.alarms;
1516 health_log.alarms = ae;
@@ -1560,7 +1562,9 @@ static inline void rrdcalc_check_critical_event(RRDCALC *rc) {
1562 int new_status = rrdcalc_value2status(n);
1563
1564 if(new_status != old_status) {
1563 - 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);
1565 + time_t now = time(NULL);
1566 + 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);
1567 + rc->last_status_change = now;
1568 rc->critical_status = new_status;
1569 }
1570 }
@@ -1572,7 +1576,9 @@ static inline void rrdcalc_check_warning_event(RRDCALC *rc) {
1576 int new_status = rrdcalc_value2status(n);
1577
1578 if(new_status != old_status) {
1575 - 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);
1579 + time_t now = time(NULL);
1580 + 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);
1581 + rc->last_status_change = now;
1582 rc->warning_status = new_status;
1583 }
1584 }
src/health.h
+2
@@ -147,6 +147,7 @@ typedef struct rrdcalc {
147 int critical_status;
148
149 time_t db_timestamp;
150 + time_t last_status_change;
151
152 calculated_number value;
153 calculated_number old_value;
@@ -210,6 +211,7 @@ typedef struct rrdcalctemplate {
211 typedef struct alarm_entry {
212 uint32_t id;
213 time_t when;
214 + time_t duration;
215 int type;
216 char *name;
217 char *chart;