diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-10-15 14:35:20 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-10-15 14:35:20 +0300 |
commit | 57a38770fe2ddb93587fe9c2023163ff6117c869 (patch) | |
tree | 9b570cf7f975585a396cfa4765ccf98fc4b4fc89 /src | |
parent | 898affab8771c9c4b2379b4b449eb80ffa1b68ae (diff) |
health typedefs are now structured
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 15 | ||||
-rw-r--r-- | src/eval.c | 2 | ||||
-rw-r--r-- | src/eval.h | 2 | ||||
-rw-r--r-- | src/health.c | 9 | ||||
-rw-r--r-- | src/health.h | 61 | ||||
-rw-r--r-- | src/health_log.c | 4 | ||||
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | src/main.h | 6 | ||||
-rw-r--r-- | src/rrdcalc.c | 2 | ||||
-rw-r--r-- | src/rrddim.c | 6 | ||||
-rw-r--r-- | src/rrddimvar.c | 2 | ||||
-rw-r--r-- | src/rrdset.c | 10 | ||||
-rw-r--r-- | src/rrdsetvar.c | 2 | ||||
-rw-r--r-- | src/rrdvar.c | 4 | ||||
-rw-r--r-- | src/storage_number.h | 3 | ||||
-rw-r--r-- | src/unit_test.c | 53 |
16 files changed, 130 insertions, 71 deletions
diff --git a/src/common.h b/src/common.h index 5d35006aac..1755320264 100644 --- a/src/common.h +++ b/src/common.h @@ -203,10 +203,21 @@ #define NETDATA_OS_TYPE "linux" #endif /* __FreeBSD__, __APPLE__*/ -#include "statistical.h" -#include "socket.h" +typedef enum rrdcalc_status { + RRDCALC_STATUS_REMOVED = -2, + RRDCALC_STATUS_UNDEFINED = -1, + RRDCALC_STATUS_UNINITIALIZED = 0, + RRDCALC_STATUS_CLEAR = 1, + RRDCALC_STATUS_RAISED = 2, + RRDCALC_STATUS_WARNING = 3, + RRDCALC_STATUS_CRITICAL = 4 +} RRDCALC_STATUS; + #include "eval.h" #include "health.h" + +#include "statistical.h" +#include "socket.h" #include "rrd.h" #include "plugin_tc.h" #include "plugins_d.h" diff --git a/src/eval.c b/src/eval.c index 9248109b0b..063db50a23 100644 --- a/src/eval.c +++ b/src/eval.c @@ -232,7 +232,7 @@ calculated_number eval_equal(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) { if(isinf(n1) && isinf(n2)) return 1; if(isnan(n1) || isnan(n2)) return 0; if(isinf(n1) || isinf(n2)) return 0; - return n1 == n2; + return calculated_number_equal(n1, n2); } calculated_number eval_not_equal(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) { return !eval_equal(exp, op, error); diff --git a/src/eval.h b/src/eval.h index d68b9af474..cd271148cd 100644 --- a/src/eval.h +++ b/src/eval.h @@ -14,7 +14,7 @@ typedef struct eval_expression { const char *source; const char *parsed_as; - int *status; + RRDCALC_STATUS *status; calculated_number *this; time_t *after; time_t *before; diff --git a/src/health.c b/src/health.c index 80dcd0a320..dfa7007b96 100644 --- a/src/health.c +++ b/src/health.c @@ -84,7 +84,7 @@ void health_reload(void) { // ---------------------------------------------------------------------------- // health main thread and friends -static inline int rrdcalc_value2status(calculated_number n) { +static inline RRDCALC_STATUS rrdcalc_value2status(calculated_number n) { if(isnan(n) || isinf(n)) return RRDCALC_STATUS_UNDEFINED; if(n) return RRDCALC_STATUS_RAISED; return RRDCALC_STATUS_CLEAR; @@ -189,7 +189,6 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) { done: health_alarm_log_save(host, ae); - return; } static inline void health_process_notifications(RRDHOST *host, ALARM_ENTRY *ae) { @@ -537,8 +536,8 @@ void *health_main(void *ptr) { if(unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_RUNNABLE))) continue; - int warning_status = RRDCALC_STATUS_UNDEFINED; - int critical_status = RRDCALC_STATUS_UNDEFINED; + RRDCALC_STATUS warning_status = RRDCALC_STATUS_UNDEFINED; + RRDCALC_STATUS critical_status = RRDCALC_STATUS_UNDEFINED; // -------------------------------------------------------- // check the warning expression @@ -605,7 +604,7 @@ void *health_main(void *ptr) { // -------------------------------------------------------- // decide the final alarm status - int status = RRDCALC_STATUS_UNDEFINED; + RRDCALC_STATUS status = RRDCALC_STATUS_UNDEFINED; switch(warning_status) { case RRDCALC_STATUS_CLEAR: diff --git a/src/health.h b/src/health.h index bd574d5057..450fa5227e 100644 --- a/src/health.h +++ b/src/health.h @@ -5,13 +5,14 @@ extern int default_health_enabled; extern int rrdvar_compare(void *a, void *b); -#define RRDVAR_TYPE_CALCULATED 1 -#define RRDVAR_TYPE_TIME_T 2 -#define RRDVAR_TYPE_COLLECTED 3 -#define RRDVAR_TYPE_TOTAL 4 -#define RRDVAR_TYPE_INT 5 -#define RRDVAR_TYPE_CALCULATED_ALLOCATED 6 - +typedef enum rrdvar_type { + RRDVAR_TYPE_CALCULATED = 1, + RRDVAR_TYPE_TIME_T = 2, + RRDVAR_TYPE_COLLECTED = 3, + RRDVAR_TYPE_TOTAL = 4, + RRDVAR_TYPE_INT = 5, + RRDVAR_TYPE_CALCULATED_ALLOCATED = 6 +} RRDVAR_TYPE; // the variables as stored in the variables indexes // there are 3 indexes: @@ -24,7 +25,7 @@ typedef struct rrdvar { char *name; uint32_t hash; - int type; + RRDVAR_TYPE type; void *value; time_t last_updated; @@ -35,15 +36,21 @@ typedef struct rrdvar { // calculated / processed by the normal data collection process // This means, there will be no speed penalty for using // these variables + +typedef enum rrdvar_options { + RRDVAR_OPTION_DEFAULT = (0 << 0) + // future use +} RRDVAR_OPTIONS; + typedef struct rrdsetvar { char *key_fullid; // chart type.chart id.variable char *key_fullname; // chart type.chart name.variable - char *variable; // variable + char *variable; // variable - int type; + RRDVAR_TYPE type; void *value; - uint32_t options; + RRDVAR_OPTIONS options; RRDVAR *var_local; RRDVAR *var_family; @@ -75,10 +82,10 @@ typedef struct rrddimvar { char *key_fullnameid; // chart type.chart name + dimension id char *key_fullnamename; // chart type.chart name + dimension name - int type; + RRDVAR_TYPE type; void *value; - uint32_t options; + RRDVAR_OPTIONS options; RRDVAR *var_local_id; RRDVAR *var_local_name; @@ -101,7 +108,7 @@ typedef struct rrddimvar { // calculated variables (defined in health configuration) // These aggregate time-series data at fixed intervals // (defined in their update_every member below) -// These increase the overhead of netdata. +// They increase the overhead of netdata. // // These calculations are allocated and linked (->next) // under RRDHOST. @@ -111,14 +118,6 @@ typedef struct rrddimvar { // having as RRDSET.calculations the RRDCALC to be processed // next. -#define RRDCALC_STATUS_REMOVED -2 -#define RRDCALC_STATUS_UNDEFINED -1 -#define RRDCALC_STATUS_UNINITIALIZED 0 -#define RRDCALC_STATUS_CLEAR 1 -#define RRDCALC_STATUS_RAISED 2 -#define RRDCALC_STATUS_WARNING 3 -#define RRDCALC_STATUS_CRITICAL 4 - #define RRDCALC_FLAG_DB_ERROR 0x00000001 #define RRDCALC_FLAG_DB_NAN 0x00000002 /* #define RRDCALC_FLAG_DB_STALE 0x00000004 */ @@ -179,7 +178,7 @@ typedef struct rrdcalc { // ------------------------------------------------------------------------ // runtime information - int status; // the current status of the alarm + RRDCALC_STATUS status; // the current status of the alarm calculated_number value; // the current value of the alarm calculated_number old_value; // the previous value of the alarm @@ -314,8 +313,8 @@ typedef struct alarm_entry { char *old_value_string; char *new_value_string; - int old_status; - int new_status; + RRDCALC_STATUS old_status; + RRDCALC_STATUS new_status; uint32_t flags; @@ -340,11 +339,11 @@ typedef struct alarm_log { #include "rrd.h" extern void rrdsetvar_rename_all(RRDSET *st); -extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options); +extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, RRDVAR_TYPE type, void *value, RRDVAR_OPTIONS options); extern void rrdsetvar_free(RRDSETVAR *rs); extern void rrddimvar_rename_all(RRDDIM *rd); -extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options); +extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, RRDVAR_TYPE type, const char *prefix, const char *suffix, void *value, RRDVAR_OPTIONS options); extern void rrddimvar_free(RRDDIMVAR *rs); extern void rrdsetcalc_link_matching(RRDSET *st); @@ -367,7 +366,7 @@ extern RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *nam extern void rrdvar_custom_host_variable_destroy(RRDHOST *host, const char *name); extern void rrdvar_custom_host_variable_set(RRDVAR *rv, calculated_number value); -extern const char *rrdcalc_status2string(int status); +extern const char *rrdcalc_status2string(RRDCALC_STATUS status); extern int health_alarm_log_open(RRDHOST *host); @@ -389,8 +388,8 @@ extern void health_alarm_log( time_t duration, calculated_number old_value, calculated_number new_value, - int old_status, - int new_status, + RRDCALC_STATUS old_status, + RRDCALC_STATUS new_status, const char *source, const char *units, const char *info, @@ -419,7 +418,7 @@ extern int rrdvar_fix_name(char *variable); extern RRDCALC *rrdcalc_create(RRDHOST *host, RRDCALCTEMPLATE *rt, const char *chart); extern void rrdcalc_create_part2(RRDHOST *host, RRDCALC *rc); -extern RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, int type, void *value); +extern RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, RRDVAR_TYPE type, void *value); extern void rrdvar_free(RRDHOST *host, avl_tree_lock *tree, RRDVAR *rv); extern void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae); diff --git a/src/health_log.c b/src/health_log.c index 9881d35d47..0314b086c5 100644 --- a/src/health_log.c +++ b/src/health_log.c @@ -351,8 +351,8 @@ inline void health_alarm_log( time_t duration, calculated_number old_value, calculated_number new_value, - int old_status, - int new_status, + RRDCALC_STATUS old_status, + RRDCALC_STATUS new_status, const char *source, const char *units, const char *info, diff --git a/src/main.c b/src/main.c index b4b1c59ae4..54f13ba0d5 100644 --- a/src/main.c +++ b/src/main.c @@ -228,7 +228,7 @@ void kill_childs() info("All threads/childs stopped."); } -struct option_def options[] = { +struct option_def option_definitions[] = { // opt description arg name default value { 'c', "Configuration file to load.", "filename", CONFIG_DIR "/" CONFIG_FILENAME}, { 'D', "Do not fork. Run in the foreground.", NULL, "run in the background"}, @@ -251,14 +251,14 @@ int help(int exitcode) { else stream = stderr; - int num_opts = sizeof(options) / sizeof(struct option_def); + int num_opts = sizeof(option_definitions) / sizeof(struct option_def); int i; int max_len_arg = 0; // Compute maximum argument length for( i = 0; i < num_opts; i++ ) { - if(options[i].arg_name) { - int len_arg = (int)strlen(options[i].arg_name); + if(option_definitions[i].arg_name) { + int len_arg = (int)strlen(option_definitions[i].arg_name); if(len_arg > max_len_arg) max_len_arg = len_arg; } } @@ -296,9 +296,9 @@ int help(int exitcode) { // Output options description. for( i = 0; i < num_opts; i++ ) { - fprintf(stream, " -%c %-*s %s", options[i].val, max_len_arg, options[i].arg_name ? options[i].arg_name : "", options[i].description); - if(options[i].default_value) { - fprintf(stream, "\n %c %-*s Default: %s\n", ' ', max_len_arg, "", options[i].default_value); + fprintf(stream, " -%c %-*s %s", option_definitions[i].val, max_len_arg, option_definitions[i].arg_name ? option_definitions[i].arg_name : "", option_definitions[i].description); + if(option_definitions[i].default_value) { + fprintf(stream, "\n %c %-*s Default: %s\n", ' ', max_len_arg, "", option_definitions[i].default_value); } else { fprintf(stream, "\n"); } @@ -656,14 +656,14 @@ int main(int argc, char **argv) { // parse options { - int num_opts = sizeof(options) / sizeof(struct option_def); + int num_opts = sizeof(option_definitions) / sizeof(struct option_def); char optstring[(num_opts * 2) + 1]; int string_i = 0; for( i = 0; i < num_opts; i++ ) { - optstring[string_i] = options[i].val; + optstring[string_i] = option_definitions[i].val; string_i++; - if(options[i].arg_name) { + if(option_definitions[i].arg_name) { optstring[string_i] = ':'; string_i++; } diff --git a/src/main.h b/src/main.h index 38df0fea44..09567bc7c9 100644 --- a/src/main.h +++ b/src/main.h @@ -16,12 +16,6 @@ struct option_def { const char *default_value; }; -/** - * List of command line options. - * This can be used to compute manpage, help messages, ect. - */ -extern struct option_def options[]; - struct netdata_static_thread { char *name; diff --git a/src/rrdcalc.c b/src/rrdcalc.c index 51c6a491ea..bc01d8729c 100644 --- a/src/rrdcalc.c +++ b/src/rrdcalc.c @@ -4,7 +4,7 @@ // ---------------------------------------------------------------------------- // RRDCALC management -inline const char *rrdcalc_status2string(int status) { +inline const char *rrdcalc_status2string(RRDCALC_STATUS status) { switch(status) { case RRDCALC_STATUS_REMOVED: return "REMOVED"; diff --git a/src/rrddim.c b/src/rrddim.c index 8df548397d..7ab7478af6 100644 --- a/src/rrddim.c +++ b/src/rrddim.c @@ -262,9 +262,9 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte } if(st->rrdhost->health_enabled) { - rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, 0); - rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, 0); - rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, 0); + rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, RRDVAR_OPTION_DEFAULT); + rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, RRDVAR_OPTION_DEFAULT); + rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT); } rrdset_unlock(st); diff --git a/src/rrddimvar.c b/src/rrddimvar.c index f6eb6d8ef8..014eef8a8e 100644 --- a/src/rrddimvar.c +++ b/src/rrddimvar.c @@ -147,7 +147,7 @@ static inline void rrddimvar_create_variables(RRDDIMVAR *rs) { rs->var_host_chartnamename = rrdvar_create_and_index("host", &st->rrdhost->variables_root_index, rs->key_fullnamename, rs->type, rs->value); } -RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options) { +RRDDIMVAR *rrddimvar_create(RRDDIM *rd, RRDVAR_TYPE type, const char *prefix, const char *suffix, void *value, RRDVAR_OPTIONS options) { RRDSET *st = rd->rrdset; debug(D_VARIABLES, "RRDDIMSET create for chart id '%s' name '%s', dimension id '%s', name '%s%s%s'", st->id, st->name, rd->id, (prefix)?prefix:"", rd->name, (suffix)?suffix:""); diff --git a/src/rrdset.c b/src/rrdset.c index 63e9d4653d..5927039d45 100644 --- a/src/rrdset.c +++ b/src/rrdset.c @@ -660,11 +660,11 @@ RRDSET *rrdset_create_custom( host->rrdset_root = st; if(host->health_enabled) { - rrdsetvar_create(st, "last_collected_t", RRDVAR_TYPE_TIME_T, &st->last_collected_time.tv_sec, 0); - rrdsetvar_create(st, "collected_total_raw", RRDVAR_TYPE_TOTAL, &st->last_collected_total, 0); - rrdsetvar_create(st, "green", RRDVAR_TYPE_CALCULATED, &st->green, 0); - rrdsetvar_create(st, "red", RRDVAR_TYPE_CALCULATED, &st->red, 0); - rrdsetvar_create(st, "update_every", RRDVAR_TYPE_INT, &st->update_every, 0); + rrdsetvar_create(st, "last_collected_t", RRDVAR_TYPE_TIME_T, &st->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "collected_total_raw", RRDVAR_TYPE_TOTAL, &st->last_collected_total, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "green", RRDVAR_TYPE_CALCULATED, &st->green, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "red", RRDVAR_TYPE_CALCULATED, &st->red, RRDVAR_OPTION_DEFAULT); + rrdsetvar_create(st, "update_every", RRDVAR_TYPE_INT, &st->update_every, RRDVAR_OPTION_DEFAULT); } if(unlikely(rrdset_index_add(host, st) != st)) diff --git a/src/rrdsetvar.c b/src/rrdsetvar.c index 03d7aeceda..5e207a66e9 100644 --- a/src/rrdsetvar.c +++ b/src/rrdsetvar.c @@ -68,7 +68,7 @@ static inline void rrdsetvar_create_variables(RRDSETVAR *rs) { } -RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options) { +RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, RRDVAR_TYPE type, void *value, RRDVAR_OPTIONS options) { debug(D_VARIABLES, "RRDVARSET create for chart id '%s' name '%s' with variable name '%s'", st->id, st->name, variable); RRDSETVAR *rs = (RRDSETVAR *)callocz(1, sizeof(RRDSETVAR)); diff --git a/src/rrdvar.c b/src/rrdvar.c index 2223d7c9a8..518d33a421 100644 --- a/src/rrdvar.c +++ b/src/rrdvar.c @@ -63,7 +63,7 @@ inline void rrdvar_free(RRDHOST *host, avl_tree_lock *tree, RRDVAR *rv) { freez(rv); } -inline RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, int type, void *value) { +inline RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, RRDVAR_TYPE type, void *value) { char *variable = strdupz(name); rrdvar_fix_name(variable); uint32_t hash = simple_hash(variable); @@ -191,7 +191,7 @@ static calculated_number rrdvar2number(RRDVAR *rv) { } default: - error("I don't know how to convert RRDVAR type %d to calculated_number", rv->type); + error("I don't know how to convert RRDVAR type %u to calculated_number", rv->type); return NAN; } } diff --git a/src/storage_number.h b/src/storage_number.h index 3c1b6bab32..616ff881ee 100644 --- a/src/storage_number.h +++ b/src/storage_number.h @@ -17,6 +17,9 @@ typedef long double collected_number; #define calculated_number_llrint(x) llrintl(x) #define calculated_number_round(x) roundl(x) #define calculated_number_fabs(x) fabsl(x) +#define calculated_number_epsilon (calculated_number)0.0000001 + +#define calculated_number_equal(a, b) (calculated_number_fabs((a) - (b)) < calculated_number_epsilon) typedef uint32_t storage_number; #define STORAGE_NUMBER_FORMAT "%u" diff --git a/src/unit_test.c b/src/unit_test.c index a2f7c8a6b0..607c223a9a 100644 --- a/src/unit_test.c +++ b/src/unit_test.c @@ -1,5 +1,55 @@ #include "common.h" +static int check_rrdcalc_comparisons(void) { + RRDCALC_STATUS a, b; + + a = RRDCALC_STATUS_REMOVED; + b = RRDCALC_STATUS_UNDEFINED; + if(!(a < b)) { + fprintf(stderr, "%s is not less than %s\n", rrdcalc_status2string(a), rrdcalc_status2string(b)); + return 1; + } + + a = RRDCALC_STATUS_UNDEFINED; + b = RRDCALC_STATUS_UNINITIALIZED; + if(!(a < b)) { + fprintf(stderr, "%s is not less than %s\n", rrdcalc_status2string(a), rrdcalc_status2string(b)); + return 1; + } + + a = RRDCALC_STATUS_UNINITIALIZED; + b = RRDCALC_STATUS_CLEAR; + if(!(a < b)) { + fprintf(stderr, "%s is not less than %s\n", rrdcalc_status2string(a), rrdcalc_status2string(b)); + return 1; + } + + a = RRDCALC_STATUS_CLEAR; + b = RRDCALC_STATUS_RAISED; + if(!(a < b)) { + fprintf(stderr, "%s is not less than %s\n", rrdcalc_status2string(a), rrdcalc_status2string(b)); + return 1; + } + + a = RRDCALC_STATUS_RAISED; + b = RRDCALC_STATUS_WARNING; + if(!(a < b)) { + fprintf(stderr, "%s is not less than %s\n", rrdcalc_status2string(a), rrdcalc_status2string(b)); + return 1; + } + + a = RRDCALC_STATUS_WARNING; + b = RRDCALC_STATUS_CRITICAL; + if(!(a < b)) { + fprintf(stderr, "%s is not less than %s\n", rrdcalc_status2string(a), rrdcalc_status2string(b)); + return 1; + } + + fprintf(stderr, "RRDCALC_STATUSes are sortable.\n"); + + return 0; +} + int check_storage_number(calculated_number n, int debug) { char buffer[100]; uint32_t flags = SN_EXISTS; @@ -1106,6 +1156,9 @@ static int test_variable_renames(void) { int run_all_mockup_tests(void) { + if(check_rrdcalc_comparisons()) + return 1; + if(!test_variable_renames()) return 1; |