@cryptotaxi247 / netdata-1 / commits / 028decf87

added abs() function to expressions; added health.d/net.conf

Costa Tsaousis committed Aug 15, 2016 at 21:08 UTC 028decf87dbd67e4f602fbe5f04db24cc6315573
4 files changed +85 -33
conf.d/Makefile.am
+1
@@ -41,5 +41,6 @@ dist_pythonconfig_DATA = \
41
42 healthconfigdir=$(configdir)/health.d
43 dist_healthconfig_DATA = \
44 + health.d/net.conf \
45 health.d/disks.conf \
46 $(NULL)
conf.d/health.d/net.conf new
+22
@@ -0,0 +1,22 @@
1 +
2 +# check if an interface is dropping packets
3 +# the alarm is checked every 10 seconds
4 +# and examines the last minute of data
5 +
6 +template: packet_drops_1m
7 + on: net.drops
8 + lookup: sum -1m unaligned absolute
9 + every: 10s
10 + crit: $this > 0
11 +
12 +
13 +# check if a QoS class is dropping packets
14 +# the alarm is checked every 10 seconds
15 +# and examines the last minute of data
16 +
17 +template: qos_packet_drops_1m
18 + on: tc.qos_dropped
19 + lookup: sum -1m unaligned absolute
20 + every: 10s
21 + crit: $this > 0
22 +
src/eval.c
+47 -19
@@ -43,6 +43,7 @@ typedef struct eval_node {
43 #define EVAL_OPERATOR_DIVIDE '/'
44 #define EVAL_OPERATOR_SIGN_PLUS 'P'
45 #define EVAL_OPERATOR_SIGN_MINUS 'M'
46 +#define EVAL_OPERATOR_ABS 'A'
47
48 // ----------------------------------------------------------------------------
49 // forward function definitions
@@ -171,36 +172,42 @@ calculated_number eval_sign_plus(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error
172 calculated_number eval_sign_minus(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
173 return -eval_value(exp, &op->ops[0], error);
174 }
175 +calculated_number eval_abs(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
176 + calculated_number n = eval_value(exp, &op->ops[0], error);
177 + return abs(n);
178 +}
179
180 static struct operator {
181 const char *print_as;
182 char precedence;
183 char parameters;
184 + char isfunction;
185 calculated_number (*eval)(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error);
186 } operators[256] = {
187 // this is a random access array
188 // we always access it with a known EVAL_OPERATOR_X
189
184 - [EVAL_OPERATOR_AND] = { "&&", 2, 2, eval_and },
185 - [EVAL_OPERATOR_OR] = { "||", 2, 2, eval_or },
186 - [EVAL_OPERATOR_GREATER_THAN_OR_EQUAL] = { ">=", 3, 2, eval_greater_than_or_equal },
187 - [EVAL_OPERATOR_LESS_THAN_OR_EQUAL] = { "<=", 3, 2, eval_less_than_or_equal },
188 - [EVAL_OPERATOR_NOT_EQUAL] = { "!=", 3, 2, eval_not_equal },
189 - [EVAL_OPERATOR_EQUAL] = { "==", 3, 2, eval_equal },
190 - [EVAL_OPERATOR_LESS] = { "<", 3, 2, eval_less },
191 - [EVAL_OPERATOR_GREATER] = { ">", 3, 2, eval_greater },
192 - [EVAL_OPERATOR_PLUS] = { "+", 4, 2, eval_plus },
193 - [EVAL_OPERATOR_MINUS] = { "-", 4, 2, eval_minus },
194 - [EVAL_OPERATOR_MULTIPLY] = { "*", 5, 2, eval_multiply },
195 - [EVAL_OPERATOR_DIVIDE] = { "/", 5, 2, eval_divide },
196 - [EVAL_OPERATOR_NOT] = { "!", 6, 1, eval_not },
197 - [EVAL_OPERATOR_SIGN_PLUS] = { "+", 6, 1, eval_sign_plus },
198 - [EVAL_OPERATOR_SIGN_MINUS] = { "-", 6, 1, eval_sign_minus },
199 - [EVAL_OPERATOR_NOP] = { NULL, 7, 1, eval_nop },
200 - [EVAL_OPERATOR_EXPRESSION_OPEN] = { NULL, 7, 1, eval_nop },
190 + [EVAL_OPERATOR_AND] = { "&&", 2, 2, 0, eval_and },
191 + [EVAL_OPERATOR_OR] = { "||", 2, 2, 0, eval_or },
192 + [EVAL_OPERATOR_GREATER_THAN_OR_EQUAL] = { ">=", 3, 2, 0, eval_greater_than_or_equal },
193 + [EVAL_OPERATOR_LESS_THAN_OR_EQUAL] = { "<=", 3, 2, 0, eval_less_than_or_equal },
194 + [EVAL_OPERATOR_NOT_EQUAL] = { "!=", 3, 2, 0, eval_not_equal },
195 + [EVAL_OPERATOR_EQUAL] = { "==", 3, 2, 0, eval_equal },
196 + [EVAL_OPERATOR_LESS] = { "<", 3, 2, 0, eval_less },
197 + [EVAL_OPERATOR_GREATER] = { ">", 3, 2, 0, eval_greater },
198 + [EVAL_OPERATOR_PLUS] = { "+", 4, 2, 0, eval_plus },
199 + [EVAL_OPERATOR_MINUS] = { "-", 4, 2, 0, eval_minus },
200 + [EVAL_OPERATOR_MULTIPLY] = { "*", 5, 2, 0, eval_multiply },
201 + [EVAL_OPERATOR_DIVIDE] = { "/", 5, 2, 0, eval_divide },
202 + [EVAL_OPERATOR_NOT] = { "!", 6, 1, 0, eval_not },
203 + [EVAL_OPERATOR_SIGN_PLUS] = { "+", 6, 1, 0, eval_sign_plus },
204 + [EVAL_OPERATOR_SIGN_MINUS] = { "-", 6, 1, 0, eval_sign_minus },
205 + [EVAL_OPERATOR_ABS] = { "abs(",6,1, 1, eval_abs },
206 + [EVAL_OPERATOR_NOP] = { NULL, 7, 1, 0, eval_nop },
207 + [EVAL_OPERATOR_EXPRESSION_OPEN] = { NULL, 7, 1, 0, eval_nop },
208
209 // this should exist in our evaluation list
203 - [EVAL_OPERATOR_EXPRESSION_CLOSE] = { NULL, 7, 1, eval_nop }
210 + [EVAL_OPERATOR_EXPRESSION_CLOSE] = { NULL, 7, 1, 0, eval_nop }
211 };
212
213 #define eval_precedence(operator) (operators[(unsigned char)(operator)].precedence)
@@ -301,6 +308,9 @@ static inline void print_parsed_as_node(BUFFER *out, EVAL_NODE *op, int *error)
308 print_parsed_as_value(out, &op->ops[1], error);
309 buffer_strcat(out, ")");
310 }
311 +
312 + if(operators[op->operator].isfunction)
313 + buffer_strcat(out, ")");
314 }
315
316 // ----------------------------------------------------------------------------
@@ -537,10 +547,12 @@ static inline int parse_open_subexpression(const char **string) {
547 return 0;
548 }
549
550 +#define parse_close_function(x) parse_close_subexpression(x)
551 +
552 static inline int parse_close_subexpression(const char **string) {
553 const char *s = *string;
554
543 - // (
555 + // )
556 if(s[0] == ')') {
557 *string = &s[1];
558 return 1;
@@ -583,6 +595,18 @@ static inline int parse_constant(const char **string, calculated_number *number)
595 return 1;
596 }
597
598 +static inline int parse_abs(const char **string) {
599 + const char *s = *string;
600 +
601 + // ABS
602 + if((s[0] == 'A' || s[0] == 'a') && (s[1] == 'B' || s[1] == 'b') && (s[2] == 'S' || s[2] == 's') && s[3] == '(') {
603 + *string = &s[3];
604 + return 1;
605 + }
606 +
607 + return 0;
608 +}
609 +
610 static struct operator_parser {
611 unsigned char id;
612 int (*parse)(const char **);
@@ -742,6 +766,10 @@ static inline EVAL_NODE *parse_one_full_operand(const char **string, int *error)
766 op1 = parse_next_operand_given_its_operator(string, EVAL_OPERATOR_SIGN_MINUS, error);
767 op1->precedence = eval_precedence(EVAL_OPERATOR_SIGN_MINUS);
768 }
769 + else if(parse_abs(string)) {
770 + op1 = parse_next_operand_given_its_operator(string, EVAL_OPERATOR_ABS, error);
771 + op1->precedence = eval_precedence(EVAL_OPERATOR_ABS);
772 + }
773 else if(parse_open_subexpression(string)) {
774 EVAL_NODE *sub = parse_full_expression(string, error);
775 if(sub) {
src/eval.h
+15 -14
@@ -27,26 +27,27 @@ typedef struct eval_expression {
27 struct rrdcalc *rrdcalc;
28 } EVAL_EXPRESSION;
29
30 -#define EVAL_VALUE_INVALID 0
31 -#define EVAL_VALUE_NUMBER 1
32 -#define EVAL_VALUE_VARIABLE 2
30 +#define EVAL_VALUE_INVALID 0
31 +#define EVAL_VALUE_NUMBER 1
32 +#define EVAL_VALUE_VARIABLE 2
33 #define EVAL_VALUE_EXPRESSION 3
34
35 -#define EVAL_ERROR_OK 0
35 +// parsing and evaluation
36 +#define EVAL_ERROR_OK 0
37
38 // parsing errors
38 -#define EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION 1
39 -#define EVAL_ERROR_UNKNOWN_OPERAND 2
40 -#define EVAL_ERROR_MISSING_OPERAND 3
41 -#define EVAL_ERROR_MISSING_OPERATOR 4
42 -#define EVAL_ERROR_REMAINING_GARBAGE 5
39 +#define EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION 1
40 +#define EVAL_ERROR_UNKNOWN_OPERAND 2
41 +#define EVAL_ERROR_MISSING_OPERAND 3
42 +#define EVAL_ERROR_MISSING_OPERATOR 4
43 +#define EVAL_ERROR_REMAINING_GARBAGE 5
44
45 // evaluation errors
45 -#define EVAL_ERROR_INVALID_VALUE 11
46 -#define EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS 12
47 -#define EVAL_ERROR_VALUE_IS_NAN 13
48 -#define EVAL_ERROR_VALUE_IS_INFINITE 14
49 -#define EVAL_ERROR_UNKNOWN_VARIABLE 15
46 +#define EVAL_ERROR_INVALID_VALUE 101
47 +#define EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS 102
48 +#define EVAL_ERROR_VALUE_IS_NAN 103
49 +#define EVAL_ERROR_VALUE_IS_INFINITE 104
50 +#define EVAL_ERROR_UNKNOWN_VARIABLE 105
51
52 // parse the given string as an expression and return:
53 // a pointer to an expression if it parsed OK