@cryptotaxi247 / netdata-1 / commits / bfb55f481

process alarms in the order they appear in the config files

Costa Tsaousis (ktsaou) committed Sep 1, 2016 at 00:34 UTC bfb55f4810a684f87c70e50cd54330bb619a134f
2 files changed +58 -47
src/health.c
+57 -46
@@ -485,9 +485,10 @@ inline void rrdsetcalc_link_matching(RRDSET *st) {
485
486 RRDCALC *rc;
487 for(rc = st->rrdhost->alarms; rc ; rc = rc->next) {
488 - if(rc->rrdset) continue;
488 + if(unlikely(rc->rrdset))
489 + continue;
490
490 - if(rrdcalc_is_matching_this_rrdset(rc, st))
491 + if(unlikely(rrdcalc_is_matching_this_rrdset(rc, st)))
492 rrdsetcalc_link(st, rc);
493 }
494 }
@@ -541,7 +542,7 @@ RRDCALC *rrdcalc_find(RRDSET *st, const char *name) {
542 uint32_t hash = simple_hash(name);
543
544 for( rc = st->alarms; rc ; rc = rc->rrdset_next ) {
544 - if(rc->hash == hash && !strcmp(rc->name, name))
545 + if(unlikely(rc->hash == hash && !strcmp(rc->name, name)))
546 return rc;
547 }
548
@@ -553,7 +554,7 @@ static inline int rrdcalc_exists(RRDHOST *host, const char *name, uint32_t hash)
554
555 // make sure it does not already exist
556 for(rc = host->alarms; rc ; rc = rc->next) {
556 - if (rc->hash == hash && !strcmp(name, rc->name)) {
557 + if (unlikely(rc->hash == hash && !strcmp(name, rc->name))) {
558 error("Health alarm '%s' already exists in host '%s'.", name, host->hostname);
559 return 1;
560 }
@@ -587,8 +588,15 @@ static inline void rrdcalc_create_part2(RRDHOST *host, RRDCALC *rc) {
588 }
589
590 // link it to the host
590 - rc->next = host->alarms;
591 - host->alarms = rc;
591 + if(likely(host->alarms)) {
592 + // append it
593 + RRDCALC *t;
594 + for(t = host->alarms; t && t->next ; t = t->next) ;
595 + t->next = rc;
596 + }
597 + else {
598 + host->alarms = rc;
599 + }
600
601 // link it to its chart
602 RRDSET *st;
@@ -692,10 +700,10 @@ void rrdcalc_free(RRDHOST *host, RRDCALC *rc) {
700 if(rc->rrdset) rrdsetcalc_unlink(rc);
701
702 // unlink it from RRDHOST
695 - if(rc == host->alarms)
703 + if(unlikely(rc == host->alarms))
704 host->alarms = rc->next;
705
698 - else if(host->alarms) {
706 + else if(likely(host->alarms)) {
707 RRDCALC *t, *last = host->alarms;
708
709 for(t = last->next; t && t != rc; last = t, t = t->next) ;
@@ -730,7 +738,6 @@ void rrdcalctemplate_link_matching(RRDSET *st) {
738
739 for(rt = st->rrdhost->templates; rt ; rt = rt->next) {
740 if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context)) {
733 -
741 RRDCALC *rc = rrdcalc_create(st->rrdhost, rt->name, st->id,
742 rt->dimensions, rt->units, rt->info, rt->group, rt->after, rt->before, rt->update_every, rt->options,
743 rt->green, rt->red, rt->exec, rt->source,
@@ -738,14 +745,12 @@ void rrdcalctemplate_link_matching(RRDSET *st) {
745 (rt->warning)?rt->warning->source:NULL,
746 (rt->critical)?rt->critical->source:NULL);
747
741 - if(!rc)
748 + if(unlikely(!rc))
749 error("Health tried to create alarm from template '%s', but it failed", rt->name);
750
751 #ifdef NETDATA_INTERNAL_CHECKS
752 else if(rc->rrdset != st)
753 error("Health alarm '%s.%s' should be linked to chart '%s', but it is not", rc->chart?rc->chart:"NOCHART", rc->name, st->id);
747 -#else
748 - (void)rc;
754 #endif
755 }
756 }
@@ -850,24 +855,24 @@ static inline int rrdcalc_add_alarm_from_config(RRDHOST *host, RRDCALC *rc) {
855 }
856
857 static inline int rrdcalctemplate_add_template_from_config(RRDHOST *host, RRDCALCTEMPLATE *rt) {
853 - if(!rt->context) {
858 + if(unlikely(!rt->context)) {
859 error("Health configuration for template '%s' does not have a context", rt->name);
860 return 0;
861 }
862
858 - if(!rt->update_every) {
863 + if(unlikely(!rt->update_every)) {
864 error("Health configuration for template '%s' has no frequency (parameter 'every'). Ignoring it.", rt->name);
865 return 0;
866 }
867
863 - if(!RRDCALCTEMPLATE_HAS_CALCULATION(rt) && !rt->warning && !rt->critical) {
868 + if(unlikely(!RRDCALCTEMPLATE_HAS_CALCULATION(rt) && !rt->warning && !rt->critical)) {
869 error("Health configuration for template '%s' is useless (no calculation, no warning and no critical evaluation)", rt->name);
870 return 0;
871 }
872
868 - RRDCALCTEMPLATE *t;
869 - for (t = host->templates; t ; t = t->next) {
870 - if(t->hash_name == rt->hash_name && !strcmp(t->name, rt->name)) {
873 + RRDCALCTEMPLATE *t, *last = NULL;
874 + for (t = host->templates; t ; last = t, t = t->next) {
875 + if(unlikely(t->hash_name == rt->hash_name && !strcmp(t->name, rt->name))) {
876 error("Health configuration template '%s' already exists for host '%s'.", rt->name, host->hostname);
877 return 0;
878 }
@@ -891,8 +896,14 @@ static inline int rrdcalctemplate_add_template_from_config(RRDHOST *host, RRDCAL
896 rt->source
897 );
898
894 - rt->next = host->templates;
895 - host->templates = rt;
899 + if(likely(last)) {
900 + last->next = rt;
901 + }
902 + else {
903 + rt->next = host->templates;
904 + host->templates = rt;
905 + }
906 +
907 return 1;
908 }
909
@@ -1643,10 +1654,10 @@ void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) {
1654 buffer_strcat(wb, "{\n\t\"alarms\": {\n");
1655 RRDCALC *rc;
1656 for(i = 0, rc = host->alarms; rc ; rc = rc->next) {
1646 - if(!rc->rrdset)
1657 + if(unlikely(!rc->rrdset))
1658 continue;
1659
1649 - if(!all && !(rc->status == RRDCALC_STATUS_WARNING || rc->status == RRDCALC_STATUS_CRITICAL))
1660 + if(likely(!all && !(rc->status == RRDCALC_STATUS_WARNING || rc->status == RRDCALC_STATUS_CRITICAL)))
1661 continue;
1662
1663 if(likely(i)) buffer_strcat(wb, ",\n");
@@ -1712,28 +1723,6 @@ void health_reload(void) {
1723 // ----------------------------------------------------------------------------
1724 // health main thread and friends
1725
1715 -static inline int rrdcalc_isrunnable(RRDCALC *rc, time_t now, time_t *next_run) {
1716 - if (unlikely(!rc->rrdset)) {
1717 - debug(D_HEALTH, "Health not running alarm '%s.%s'. It is not linked to a chart.", rc->chart?rc->chart:"NOCHART", rc->name);
1718 - return 0;
1719 - }
1720 -
1721 - if (unlikely(!rc->update_every)) {
1722 - debug(D_HEALTH, "Health not running alarm '%s.%s'. It does not have an update frequency", rc->chart?rc->chart:"NOCHART", rc->name);
1723 - return 0;
1724 - }
1725 -
1726 - if (unlikely(rc->next_update > now)) {
1727 - if (*next_run > rc->next_update)
1728 - *next_run = rc->next_update;
1729 -
1730 - debug(D_HEALTH, "Health not examining alarm '%s.%s' yet (will do in %d secs).", rc->chart?rc->chart:"NOCHART", rc->name, (int) (rc->next_update - now));
1731 - return 0;
1732 - }
1733 -
1734 - return 1;
1735 -}
1736 -
1726 static inline int rrdcalc_value2status(calculated_number n) {
1727 if(isnan(n)) return RRDCALC_STATUS_UNDEFINED;
1728 if(n) return RRDCALC_STATUS_RAISED;
@@ -1921,6 +1910,28 @@ static inline void health_alarm_log_process(RRDHOST *host) {
1910 pthread_rwlock_unlock(&host->health_log.alarm_log_rwlock);
1911 }
1912
1913 +static inline int rrdcalc_isrunnable(RRDCALC *rc, time_t now, time_t *next_run) {
1914 + if (unlikely(!rc->rrdset)) {
1915 + debug(D_HEALTH, "Health not running alarm '%s.%s'. It is not linked to a chart.", rc->chart?rc->chart:"NOCHART", rc->name);
1916 + return 0;
1917 + }
1918 +
1919 + if (unlikely(!rc->update_every)) {
1920 + debug(D_HEALTH, "Health not running alarm '%s.%s'. It does not have an update frequency", rc->chart?rc->chart:"NOCHART", rc->name);
1921 + return 0;
1922 + }
1923 +
1924 + if (unlikely(rc->next_update > now)) {
1925 + if (unlikely(*next_run > rc->next_update))
1926 + *next_run = rc->next_update;
1927 +
1928 + debug(D_HEALTH, "Health not examining alarm '%s.%s' yet (will do in %d secs).", rc->chart?rc->chart:"NOCHART", rc->name, (int) (rc->next_update - now));
1929 + return 0;
1930 + }
1931 +
1932 + return 1;
1933 +}
1934 +
1935 void *health_main(void *ptr) {
1936 (void)ptr;
1937
@@ -2063,7 +2074,7 @@ void *health_main(void *ptr) {
2074 int warning_status = RRDCALC_STATUS_UNDEFINED;
2075 int critical_status = RRDCALC_STATUS_UNDEFINED;
2076
2066 - if(unlikely(rc->warning)) {
2077 + if(likely(rc->warning)) {
2078 if(unlikely(!expression_evaluate(rc->warning))) {
2079 // calculation failed
2080
@@ -2093,7 +2104,7 @@ void *health_main(void *ptr) {
2104 }
2105 }
2106
2096 - if(unlikely(rc->critical)) {
2107 + if(likely(rc->critical)) {
2108 if(unlikely(!expression_evaluate(rc->critical))) {
2109 // calculation failed
2110
src/rrd.h
+1 -1
@@ -277,7 +277,7 @@ struct rrdset {
277 // ------------------------------------------------------------------------
278 // the dimensions
279
280 - avl_tree_lock dimensions_index; // the root of the dimensions index
280 + avl_tree_lock dimensions_index; // the root of the dimensions index
281 RRDDIM *dimensions; // the actual data for every dimension
282
283 };