@cryptotaxi247 / netdata-1 / commits / 815673423

added variable $now that resolves to the current timestamp; added entropy alarm

Costa Tsaousis committed Aug 16, 2016 at 15:14 UTC 8156734230cfcfe4bdfaee3db0b3e317c373e419
3 files changed +25 -3
conf.d/Makefile.am
+2 -1
@@ -41,6 +41,7 @@ dist_pythonconfig_DATA = \
41
42 healthconfigdir=$(configdir)/health.d
43 dist_healthconfig_DATA = \
44 - health.d/net.conf \
44 health.d/disks.conf \
45 + health.d/entropy.conf \
46 + health.d/net.conf \
47 $(NULL)
conf.d/health.d/entropy.conf new
+11
@@ -0,0 +1,11 @@
1 +
2 +# check if entropy is too low
3 +# the alarm is checked every 1 minute
4 +# and examines the last 2 minutes of data
5 +
6 + alarm: low_entropy_2m
7 + on: system.entropy
8 + lookup: min -2m unaligned
9 + every: 1m
10 + warn: $this < 1000
11 + crit: $this < 100
src/eval.c
+12 -2
@@ -73,10 +73,12 @@ static inline calculated_number eval_check_number(calculated_number n, int *erro
73 }
74
75 static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABLE *v, int *error) {
76 - static uint32_t this_hash = 0;
76 + static uint32_t this_hash = 0, now_hash = 0;
77
78 - if(unlikely(this_hash == 0))
78 + if(unlikely(this_hash == 0)) {
79 this_hash = simple_hash("this");
80 + now_hash = simple_hash("now");
81 + }
82
83 if(exp->this && v->hash == this_hash && !strcmp(v->name, "this")) {
84 buffer_strcat(exp->error_msg, "[ $this = ");
@@ -85,6 +87,14 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
87 return *exp->this;
88 }
89
90 + if(v->hash == now_hash && !strcmp(v->name, "now")) {
91 + calculated_number n = time(NULL);
92 + buffer_strcat(exp->error_msg, "[ $now = ");
93 + print_parsed_as_constant(exp->error_msg, n);
94 + buffer_strcat(exp->error_msg, " ] ");
95 + return n;
96 + }
97 +
98 calculated_number n;
99 if(exp->rrdcalc && health_variable_lookup(v->name, v->hash, exp->rrdcalc, &n)) {
100 buffer_sprintf(exp->error_msg, "[ $%s = ", v->name);