@cryptotaxi247 / netdata-1 / commits / e1d7bb040

more code cleanup

Costa Tsaousis (ktsaou) committed Dec 26, 2017 at 17:46 UTC e1d7bb0408d73fafcd073ef0f43e51c524a50637
33 files changed +178 -159
cppcheck.sh
+1
@@ -32,4 +32,5 @@ shift
32 --library=posix \
33 --suppress="unusedFunction:*" \
34 --suppress="nullPointerRedundantCheck:*" \
35 + --suppress="readdirCalled:*" \
36 "${file}" "${@}"
netdata.cppcheck
+1
@@ -13,5 +13,6 @@
13 <suppressions>
14 <suppression>nullPointerRedundantCheck</suppression>
15 <suppression>unusedFunction</suppression>
16 + <suppression>readdirCalled</suppression>
17 </suppressions>
18 </project>
src/appconfig.c
+2 -2
@@ -110,8 +110,8 @@ static int appconfig_section_compare(void *a, void *b) {
110 else return strcmp(((struct section *)a)->name, ((struct section *)b)->name);
111 }
112
113 -#define appconfig_index_add(root, cfg) (struct section *)avl_insert_lock(&root->index, (avl *)(cfg))
114 -#define appconfig_index_del(root, cfg) (struct section *)avl_remove_lock(&root->index, (avl *)(cfg))
113 +#define appconfig_index_add(root, cfg) (struct section *)avl_insert_lock(&(root)->index, (avl *)(cfg))
114 +#define appconfig_index_del(root, cfg) (struct section *)avl_remove_lock(&(root)->index, (avl *)(cfg))
115
116 static struct section *appconfig_index_find(struct config *root, const char *name, uint32_t hash) {
117 struct section tmp;
src/apps_plugin.c
+3 -3
@@ -870,8 +870,8 @@ static inline int read_proc_pid_ownership(struct pid_stat *p, void *ptr) {
870
871 #define incremental_rate(rate_variable, last_kernel_variable, new_kernel_value, collected_usec, last_collected_usec) { \
872 kernel_uint_t _new_tmp = new_kernel_value; \
873 - rate_variable = (_new_tmp - last_kernel_variable) * (USEC_PER_SEC * RATES_DETAIL) / (collected_usec - last_collected_usec); \
874 - last_kernel_variable = _new_tmp; \
873 + (rate_variable) = (_new_tmp - (last_kernel_variable)) * (USEC_PER_SEC * RATES_DETAIL) / ((collected_usec) - (last_collected_usec)); \
874 + (last_kernel_variable) = _new_tmp; \
875 }
876
877 // the same macro for struct pid members
@@ -930,7 +930,7 @@ static inline int read_proc_pid_stat(struct pid_stat *p, void *ptr) {
930 // p->flags = str2uint64_t(procfile_lineword(ff, 0, 8));
931 #endif
932
933 - if(strcmp(p->comm, comm)) {
933 + if(strcmp(p->comm, comm) != 0) {
934 if(unlikely(debug)) {
935 if(p->comm[0])
936 fprintf(stderr, "apps.plugin: \tpid %d (%s) changed name to '%s'\n", p->pid, p->comm, comm);
src/backends.c
+9 -5
@@ -56,6 +56,8 @@ inline calculated_number backend_calculate_value_from_stored_data(
56 , time_t *first_timestamp // the first point of the database used in this response
57 , time_t *last_timestamp // the timestamp that should be reported to backend
58 ) {
59 + RRDHOST *host = st->rrdhost;
60 +
61 // find the edges of the rrd database for this chart
62 time_t first_t = rrdset_first_entry_t(st);
63 time_t last_t = rrdset_last_entry_t(st);
@@ -87,7 +89,7 @@ inline calculated_number backend_calculate_value_from_stored_data(
89 if(unlikely(before < first_t || after > last_t)) {
90 // the chart has not been updated in the wanted timeframe
91 debug(D_BACKEND, "BACKEND: %s.%s.%s: aligned timeframe %lu to %lu is outside the chart's database range %lu to %lu",
90 - st->rrdhost->hostname, st->id, rd->id,
92 + host->hostname, st->id, rd->id,
93 (unsigned long)after, (unsigned long)before,
94 (unsigned long)first_t, (unsigned long)last_t
95 );
@@ -124,7 +126,7 @@ inline calculated_number backend_calculate_value_from_stored_data(
126
127 if(unlikely(!counter)) {
128 debug(D_BACKEND, "BACKEND: %s.%s.%s: no values stored in database for range %lu to %lu",
127 - st->rrdhost->hostname, st->id, rd->id,
129 + host->hostname, st->id, rd->id,
130 (unsigned long)after, (unsigned long)before
131 );
132 return NAN;
@@ -447,6 +449,8 @@ static inline int process_json_response(BUFFER *b) {
449 static SIMPLE_PATTERN *charts_pattern = NULL;
450
451 inline int backends_can_send_rrdset(uint32_t options, RRDSET *st) {
452 + RRDHOST *host = st->rrdhost;
453 +
454 if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_BACKEND_IGNORE)))
455 return 0;
456
@@ -456,18 +460,18 @@ inline int backends_can_send_rrdset(uint32_t options, RRDSET *st) {
460 rrdset_flag_set(st, RRDSET_FLAG_BACKEND_SEND);
461 else {
462 rrdset_flag_set(st, RRDSET_FLAG_BACKEND_IGNORE);
459 - debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is disabled for backends.", st->id, st->rrdhost->hostname);
463 + debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is disabled for backends.", st->id, host->hostname);
464 return 0;
465 }
466 }
467
468 if(unlikely(!rrdset_is_available_for_backends(st))) {
465 - debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is not available for backends.", st->id, st->rrdhost->hostname);
469 + debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s', because it is not available for backends.", st->id, host->hostname);
470 return 0;
471 }
472
473 if(unlikely(st->rrd_memory_mode == RRD_MEMORY_MODE_NONE && !((options & BACKEND_SOURCE_BITS) == BACKEND_SOURCE_DATA_AS_COLLECTED))) {
470 - debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s' because its memory mode is '%s' and the backend requires database access.", st->id, st->rrdhost->hostname, rrd_memory_mode_name(st->rrdhost->rrd_memory_mode));
474 + debug(D_BACKEND, "BACKEND: not sending chart '%s' of host '%s' because its memory mode is '%s' and the backend requires database access.", st->id, host->hostname, rrd_memory_mode_name(host->rrd_memory_mode));
475 return 0;
476 }
477
src/common.h
+1 -1
@@ -163,7 +163,7 @@
163 #ifdef abs
164 #undef abs
165 #endif
166 -#define abs(x) ((x < 0)? -x : x)
166 +#define abs(x) (((x) < 0)? (-(x)) : (x))
167
168 #define GUID_LEN 36
169
src/daemon.c
+2 -2
@@ -121,10 +121,10 @@ int become_user(const char *username, int pid_fd) {
121 }
122
123 #ifndef OOM_SCORE_ADJ_MAX
124 -#define OOM_SCORE_ADJ_MAX 1000
124 +#define OOM_SCORE_ADJ_MAX (1000)
125 #endif
126 #ifndef OOM_SCORE_ADJ_MIN
127 -#define OOM_SCORE_ADJ_MIN -1000
127 +#define OOM_SCORE_ADJ_MIN (-1000)
128 #endif
129
130 static void oom_score_adj(void) {
src/eval.h
-1
@@ -6,7 +6,6 @@
6 typedef struct eval_variable {
7 char *name;
8 uint32_t hash;
9 - struct rrdvar *rrdvar;
9 struct eval_variable *next;
10 } EVAL_VARIABLE;
11
src/health_config.c
+11 -11
@@ -373,7 +373,7 @@ static inline int health_parse_db_lookup(
373 *options |= RRDR_OPTION_NOT_ALIGNED;
374 }
375 else if(!strcasecmp(key, "of")) {
376 - if(*s && strcasecmp(s, "all"))
376 + if(*s && strcasecmp(s, "all") != 0)
377 *dimensions = strdupz(s);
378 break;
379 }
@@ -589,7 +589,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
589 else if(rc) {
590 if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
591 if(rc->chart) {
592 - if(strcmp(rc->chart, value))
592 + if(strcmp(rc->chart, value) != 0)
593 error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
594 line, path, filename, rc->name, key, rc->chart, value, value);
595
@@ -653,7 +653,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
653 }
654 else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
655 if(rc->exec) {
656 - if(strcmp(rc->exec, value))
656 + if(strcmp(rc->exec, value) != 0)
657 error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
658 line, path, filename, rc->name, key, rc->exec, value, value);
659
@@ -663,7 +663,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
663 }
664 else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
665 if(rc->recipient) {
666 - if(strcmp(rc->recipient, value))
666 + if(strcmp(rc->recipient, value) != 0)
667 error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
668 line, path, filename, rc->name, key, rc->recipient, value, value);
669
@@ -673,7 +673,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
673 }
674 else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
675 if(rc->units) {
676 - if(strcmp(rc->units, value))
676 + if(strcmp(rc->units, value) != 0)
677 error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
678 line, path, filename, rc->name, key, rc->units, value, value);
679
@@ -684,7 +684,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
684 }
685 else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
686 if(rc->info) {
687 - if(strcmp(rc->info, value))
687 + if(strcmp(rc->info, value) != 0)
688 error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
689 line, path, filename, rc->name, key, rc->info, value, value);
690
@@ -707,7 +707,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
707 else if(rt) {
708 if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
709 if(rt->context) {
710 - if(strcmp(rt->context, value))
710 + if(strcmp(rt->context, value) != 0)
711 error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
712 line, path, filename, rt->name, key, rt->context, value, value);
713
@@ -777,7 +777,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
777 }
778 else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
779 if(rt->exec) {
780 - if(strcmp(rt->exec, value))
780 + if(strcmp(rt->exec, value) != 0)
781 error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
782 line, path, filename, rt->name, key, rt->exec, value, value);
783
@@ -787,7 +787,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
787 }
788 else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
789 if(rt->recipient) {
790 - if(strcmp(rt->recipient, value))
790 + if(strcmp(rt->recipient, value) != 0)
791 error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
792 line, path, filename, rt->name, key, rt->recipient, value, value);
793
@@ -797,7 +797,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
797 }
798 else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
799 if(rt->units) {
800 - if(strcmp(rt->units, value))
800 + if(strcmp(rt->units, value) != 0)
801 error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
802 line, path, filename, rt->name, key, rt->units, value, value);
803
@@ -808,7 +808,7 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
808 }
809 else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
810 if(rt->info) {
811 - if(strcmp(rt->info, value))
811 + if(strcmp(rt->info, value) != 0)
812 error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
813 line, path, filename, rt->name, key, rt->info, value, value);
814
src/plugin_proc_diskspace.c
+1 -1
@@ -46,7 +46,7 @@ struct mount_point_metadata {
46
47 static DICTIONARY *dict_mountpoints = NULL;
48
49 -#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_is_obsolete(st); st = NULL; } } while(st)
49 +#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_is_obsolete(st); (st) = NULL; } } while(st)
50
51 int mount_point_cleanup(void *entry, void *data) {
52 (void)data;
src/popen.c
-7
@@ -133,37 +133,30 @@ int mypclose(FILE *fp, pid_t pid) {
133 if(info.si_status)
134 error("child pid %d exited with code %d.", info.si_pid, info.si_status);
135 return(info.si_status);
136 - break;
136
137 case CLD_KILLED:
138 error("child pid %d killed by signal %d.", info.si_pid, info.si_status);
139 return(-1);
141 - break;
140
141 case CLD_DUMPED:
142 error("child pid %d core dumped by signal %d.", info.si_pid, info.si_status);
143 return(-2);
146 - break;
144
145 case CLD_STOPPED:
146 error("child pid %d stopped by signal %d.", info.si_pid, info.si_status);
147 return(0);
151 - break;
148
149 case CLD_TRAPPED:
150 error("child pid %d trapped by signal %d.", info.si_pid, info.si_status);
151 return(-4);
156 - break;
152
153 case CLD_CONTINUED:
154 error("child pid %d continued by signal %d.", info.si_pid, info.si_status);
155 return(0);
161 - break;
156
157 default:
158 error("child pid %d gave us a SIGCHLD with code %d and status %d.", info.si_pid, info.si_code, info.si_status);
159 return(-5);
166 - break;
160 }
161 }
162 else
src/proc_diskstats.c
+1 -1
@@ -71,7 +71,7 @@ static struct disk {
71 struct disk *next;
72 } *disk_root = NULL;
73
74 -#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_is_obsolete(st); st = NULL; } } while(st)
74 +#define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_is_obsolete(st); (st) = NULL; } } while(st)
75
76 static char *path_to_get_hw_sector_size = NULL;
77 static char *path_to_get_hw_sector_size_partitions = NULL;
src/proc_softirqs.c
+2 -2
@@ -18,10 +18,10 @@ struct interrupt {
18
19 // since each interrupt is variable in size
20 // we use this to calculate its record size
21 -#define recordsize(cpus) (sizeof(struct interrupt) + (cpus * sizeof(struct cpu_interrupt)))
21 +#define recordsize(cpus) (sizeof(struct interrupt) + ((cpus) * sizeof(struct cpu_interrupt)))
22
23 // given a base, get a pointer to each record
24 -#define irrindex(base, line, cpus) ((struct interrupt *)&((char *)(base))[line * recordsize(cpus)])
24 +#define irrindex(base, line, cpus) ((struct interrupt *)&((char *)(base))[(line) * recordsize(cpus)])
25
26 static inline struct interrupt *get_interrupts_array(size_t lines, int cpus) {
27 static struct interrupt *irrs = NULL;
src/procfile.h
+2 -2
@@ -107,7 +107,7 @@ extern char *procfile_filename(procfile *ff);
107 extern int procfile_adaptive_initial_allocation;
108
109 // return the number of lines present
110 -#define procfile_lines(ff) (ff->lines->len)
110 +#define procfile_lines(ff) ((ff)->lines->len)
111
112 // return the number of words of the Nth line
113 #define procfile_linewords(ff, line) (((line) < procfile_lines(ff)) ? (ff)->lines->lines[(line)].words : 0)
@@ -119,6 +119,6 @@ extern int procfile_adaptive_initial_allocation;
119 #define procfile_line(ff, line) (((line) < procfile_lines(ff)) ? procfile_word((ff), (ff)->lines->lines[(line)].first) : "")
120
121 // return the Nth word of the current line
122 -#define procfile_lineword(ff, line, word) (((line) < procfile_lines(ff) && (word) < procfile_linewords(ff, (line))) ? procfile_word((ff), (ff)->lines->lines[(line)].first + word) : "")
122 +#define procfile_lineword(ff, line, word) (((line) < procfile_lines(ff) && (word) < procfile_linewords((ff), (line))) ? procfile_word((ff), (ff)->lines->lines[(line)].first + (word)) : "")
123
124 #endif /* NETDATA_PROCFILE_H */
src/registry_internals.c
+1 -8
@@ -17,7 +17,7 @@ int regenerate_guid(const char *guid, char *result) {
17 uuid_unparse_lower(uuid, result);
18
19 #ifdef NETDATA_INTERNAL_CHECKS
20 - if(strcmp(guid, result))
20 + if(strcmp(guid, result) != 0)
21 info("GUID '%s' and re-generated GUID '%s' differ!", guid, result);
22 #endif /* NETDATA_INTERNAL_CHECKS */
23 }
@@ -73,13 +73,6 @@ static inline char *registry_fix_url(char *url, size_t *len) {
73 }
74
75
76 -// ----------------------------------------------------------------------------
77 -// forward definition of functions
78 -
79 -extern REGISTRY_PERSON *registry_request_access(char *person_guid, char *machine_guid, char *url, char *name, time_t when);
80 -extern REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when);
81 -
82 -
76 // ----------------------------------------------------------------------------
77 // HELPERS
78
src/registry_internals.h
+2 -4
@@ -6,7 +6,7 @@
6 #define REGISTRY_URL_FLAGS_DEFAULT 0x00
7 #define REGISTRY_URL_FLAGS_EXPIRED 0x01
8
9 -#define DICTIONARY_FLAGS DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE | DICTIONARY_FLAG_NAME_LINK_DONT_CLONE | DICTIONARY_FLAG_SINGLE_THREADED
9 +#define DICTIONARY_FLAGS (DICTIONARY_FLAG_VALUE_LINK_DONT_CLONE | DICTIONARY_FLAG_NAME_LINK_DONT_CLONE | DICTIONARY_FLAG_SINGLE_THREADED)
10
11 // ----------------------------------------------------------------------------
12 // COMMON structures
@@ -59,8 +59,6 @@ struct registry {
59 netdata_mutex_t lock;
60 };
61
62 -extern int regenerate_guid(const char *guid, char *result);
63 -
62 #include "registry_url.h"
63 #include "registry_machine.h"
64 #include "registry_person.h"
@@ -74,7 +72,7 @@ extern REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine
72 extern REGISTRY_MACHINE *registry_request_machine(char *person_guid, char *machine_guid, char *url, char *request_machine, time_t when);
73
74 // REGISTRY LOG (in registry_log.c)
77 -extern void registry_log(const char action, REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name);
75 +extern void registry_log(char action, REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name);
76 extern int registry_log_open(void);
77 extern void registry_log_close(void);
78 extern void registry_log_recreate(void);
src/registry_log.c
+1 -1
@@ -1,6 +1,6 @@
1 #include "registry_internals.h"
2
3 -void registry_log(const char action, REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name) {
3 +void registry_log(char action, REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name) {
4 if(likely(registry.log_fp)) {
5 if(unlikely(fprintf(registry.log_fp, "%c\t%08x\t%s\t%s\t%s\t%s\n",
6 action,
src/registry_person.c
+1 -1
@@ -242,7 +242,7 @@ REGISTRY_PERSON_URL *registry_person_link_to_url(REGISTRY_PERSON *p, REGISTRY_MA
242 pu->machine = m;
243 }
244
245 - if(strcmp(pu->machine_name, name)) {
245 + if(strcmp(pu->machine_name, name) != 0) {
246 // the name of the PERSON_URL has changed !
247 pu = registry_person_url_reallocate(p, m, u, name, namelen, when, pu);
248 }
src/rrd2json.h
+1 -1
@@ -6,7 +6,7 @@
6 #define API_RELATIVE_TIME_MAX (3 * 365 * 86400)
7
8 // type of JSON generations
9 -#define DATASOURCE_INVALID -1
9 +#define DATASOURCE_INVALID (-1)
10 #define DATASOURCE_JSON 0
11 #define DATASOURCE_DATATABLE_JSON 1
12 #define DATASOURCE_DATATABLE_JSONP 2
src/rrdcalc.c
+15 -12
@@ -34,7 +34,9 @@ inline const char *rrdcalc_status2string(RRDCALC_STATUS status) {
34 }
35
36 static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
37 - debug(D_HEALTH, "Health linking alarm '%s.%s' to chart '%s' of host '%s'", rc->chart?rc->chart:"NOCHART", rc->name, st->id, st->rrdhost->hostname);
37 + RRDHOST *host = st->rrdhost;
38 +
39 + debug(D_HEALTH, "Health linking alarm '%s.%s' to chart '%s' of host '%s'", rc->chart?rc->chart:"NOCHART", rc->name, st->id, host->hostname);
40
41 rc->last_status_change = now_realtime_sec();
42 rc->rrdset = st;
@@ -67,17 +69,17 @@ static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
69
70 char fullname[RRDVAR_MAX_LENGTH + 1];
71 snprintfz(fullname, RRDVAR_MAX_LENGTH, "%s.%s", st->id, rc->name);
70 - rc->hostid = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, fullname, RRDVAR_TYPE_CALCULATED, &rc->value);
72 + rc->hostid = rrdvar_create_and_index("host", &host->rrdvar_root_index, fullname, RRDVAR_TYPE_CALCULATED, &rc->value);
73
74 snprintfz(fullname, RRDVAR_MAX_LENGTH, "%s.%s", st->name, rc->name);
73 - rc->hostname = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, fullname, RRDVAR_TYPE_CALCULATED, &rc->value);
75 + rc->hostname = rrdvar_create_and_index("host", &host->rrdvar_root_index, fullname, RRDVAR_TYPE_CALCULATED, &rc->value);
76
77 if(!rc->units) rc->units = strdupz(st->units);
78
79 {
80 time_t now = now_realtime_sec();
81 health_alarm_log(
80 - st->rrdhost,
82 + host,
83 rc->id,
84 rc->next_event_id++,
85 now,
@@ -110,10 +112,11 @@ static inline int rrdcalc_is_matching_this_rrdset(RRDCALC *rc, RRDSET *st) {
112
113 // this has to be called while the RRDHOST is locked
114 inline void rrdsetcalc_link_matching(RRDSET *st) {
115 + RRDHOST *host = st->rrdhost;
116 // debug(D_HEALTH, "find matching alarms for chart '%s'", st->id);
117
118 RRDCALC *rc;
116 - for(rc = st->rrdhost->alarms; rc ; rc = rc->next) {
119 + for(rc = host->alarms; rc ; rc = rc->next) {
120 if(unlikely(rc->rrdset))
121 continue;
122
@@ -132,10 +135,12 @@ inline void rrdsetcalc_unlink(RRDCALC *rc) {
135 return;
136 }
137
138 + RRDHOST *host = st->rrdhost;
139 +
140 {
141 time_t now = now_realtime_sec();
142 health_alarm_log(
138 - st->rrdhost,
143 + host,
144 rc->id,
145 rc->next_event_id++,
146 now,
@@ -157,8 +162,6 @@ inline void rrdsetcalc_unlink(RRDCALC *rc) {
162 );
163 }
164
160 - RRDHOST *host = st->rrdhost;
161 -
165 debug(D_HEALTH, "Health unlinking alarm '%s.%s' from chart '%s' of host '%s'", rc->chart?rc->chart:"NOCHART", rc->name, st->id, host->hostname);
166
167 // unlink it
@@ -173,16 +176,16 @@ inline void rrdsetcalc_unlink(RRDCALC *rc) {
176
177 rc->rrdset_prev = rc->rrdset_next = NULL;
178
176 - rrdvar_free(st->rrdhost, &st->rrdvar_root_index, rc->local);
179 + rrdvar_free(host, &st->rrdvar_root_index, rc->local);
180 rc->local = NULL;
181
179 - rrdvar_free(st->rrdhost, &st->rrdfamily->rrdvar_root_index, rc->family);
182 + rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rc->family);
183 rc->family = NULL;
184
182 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rc->hostid);
185 + rrdvar_free(host, &host->rrdvar_root_index, rc->hostid);
186 rc->hostid = NULL;
187
185 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rc->hostname);
188 + rrdvar_free(host, &host->rrdvar_root_index, rc->hostname);
189 rc->hostname = NULL;
190
191 rc->rrdset = NULL;
src/rrdcalctemplate.c
+4 -3
@@ -5,14 +5,15 @@
5 // RRDCALCTEMPLATE management
6
7 void rrdcalctemplate_link_matching(RRDSET *st) {
8 + RRDHOST *host = st->rrdhost;
9 RRDCALCTEMPLATE *rt;
10
10 - for(rt = st->rrdhost->templates; rt ; rt = rt->next) {
11 + for(rt = host->templates; rt ; rt = rt->next) {
12 if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context)
13 && (!rt->family_pattern || simple_pattern_matches(rt->family_pattern, st->family))) {
13 - RRDCALC *rc = rrdcalc_create(st->rrdhost, rt, st->id);
14 + RRDCALC *rc = rrdcalc_create(host, rt, st->id);
15 if(unlikely(!rc))
15 - info("Health tried to create alarm from template '%s' on chart '%s' of host '%s', but it failed", rt->name, st->id, st->rrdhost->hostname);
16 + info("Health tried to create alarm from template '%s' on chart '%s' of host '%s', but it failed", rt->name, st->id, host->hostname);
17
18 #ifdef NETDATA_INTERNAL_CHECKS
19 else if(rc->rrdset != st)
src/rrddim.c
+10 -5
@@ -99,6 +99,7 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
99 return rd;
100 }
101
102 + RRDHOST *host = st->rrdhost;
103 char filename[FILENAME_MAX + 1];
104 char fullfilename[FILENAME_MAX + 1];
105
@@ -247,7 +248,7 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
248 info("Dimension '%s' added on chart '%s' of host '%s' is not homogeneous to other dimensions already present (algorithm is '%s' vs '%s', multiplier is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ", divisor is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ").",
249 rd->name,
250 st->name,
250 - st->rrdhost->hostname,
251 + host->hostname,
252 rrd_algorithm_name(rd->algorithm), rrd_algorithm_name(td->algorithm),
253 rd->multiplier, td->multiplier,
254 rd->divisor, td->divisor
@@ -261,7 +262,7 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
262 td->next = rd;
263 }
264
264 - if(st->rrdhost->health_enabled) {
265 + if(host->health_enabled) {
266 rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, RRDVAR_OPTION_DEFAULT);
267 rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, RRDVAR_OPTION_DEFAULT);
268 rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, RRDVAR_OPTION_DEFAULT);
@@ -330,9 +331,11 @@ void rrddim_free(RRDSET *st, RRDDIM *rd)
331 int rrddim_hide(RRDSET *st, const char *id) {
332 debug(D_RRD_CALLS, "rrddim_hide() for chart %s, dimension %s", st->name, id);
333
334 + RRDHOST *host = st->rrdhost;
335 +
336 RRDDIM *rd = rrddim_find(st, id);
337 if(unlikely(!rd)) {
335 - error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, st->rrdhost->hostname);
338 + error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, host->hostname);
339 return 1;
340 }
341
@@ -343,9 +346,10 @@ int rrddim_hide(RRDSET *st, const char *id) {
346 int rrddim_unhide(RRDSET *st, const char *id) {
347 debug(D_RRD_CALLS, "rrddim_unhide() for chart %s, dimension %s", st->name, id);
348
349 + RRDHOST *host = st->rrdhost;
350 RRDDIM *rd = rrddim_find(st, id);
351 if(unlikely(!rd)) {
348 - error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, st->rrdhost->hostname);
352 + error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, host->hostname);
353 return 1;
354 }
355
@@ -372,9 +376,10 @@ inline collected_number rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_
376 }
377
378 collected_number rrddim_set(RRDSET *st, const char *id, collected_number value) {
379 + RRDHOST *host = st->rrdhost;
380 RRDDIM *rd = rrddim_find(st, id);
381 if(unlikely(!rd)) {
377 - error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, st->rrdhost->hostname);
382 + error("Cannot find dimension with id '%s' on stats '%s' (%s) on host '%s'.", id, st->name, st->id, host->hostname);
383 return 0;
384 }
385
src/rrddimvar.c
+16 -14
@@ -10,41 +10,42 @@
10 static inline void rrddimvar_free_variables(RRDDIMVAR *rs) {
11 RRDDIM *rd = rs->rrddim;
12 RRDSET *st = rd->rrdset;
13 + RRDHOST *host = st->rrdhost;
14
15 // CHART VARIABLES FOR THIS DIMENSION
16
16 - rrdvar_free(st->rrdhost, &st->rrdvar_root_index, rs->var_local_id);
17 + rrdvar_free(host, &st->rrdvar_root_index, rs->var_local_id);
18 rs->var_local_id = NULL;
19
19 - rrdvar_free(st->rrdhost, &st->rrdvar_root_index, rs->var_local_name);
20 + rrdvar_free(host, &st->rrdvar_root_index, rs->var_local_name);
21 rs->var_local_name = NULL;
22
23 // FAMILY VARIABLES FOR THIS DIMENSION
24
24 - rrdvar_free(st->rrdhost, &st->rrdfamily->rrdvar_root_index, rs->var_family_id);
25 + rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_id);
26 rs->var_family_id = NULL;
27
27 - rrdvar_free(st->rrdhost, &st->rrdfamily->rrdvar_root_index, rs->var_family_name);
28 + rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_name);
29 rs->var_family_name = NULL;
30
30 - rrdvar_free(st->rrdhost, &st->rrdfamily->rrdvar_root_index, rs->var_family_contextid);
31 + rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_contextid);
32 rs->var_family_contextid = NULL;
33
33 - rrdvar_free(st->rrdhost, &st->rrdfamily->rrdvar_root_index, rs->var_family_contextname);
34 + rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_contextname);
35 rs->var_family_contextname = NULL;
36
37 // HOST VARIABLES FOR THIS DIMENSION
38
38 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rs->var_host_chartidid);
39 + rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartidid);
40 rs->var_host_chartidid = NULL;
41
41 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rs->var_host_chartidname);
42 + rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartidname);
43 rs->var_host_chartidname = NULL;
44
44 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rs->var_host_chartnameid);
45 + rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartnameid);
46 rs->var_host_chartnameid = NULL;
47
47 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rs->var_host_chartnamename);
48 + rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_chartnamename);
49 rs->var_host_chartnamename = NULL;
50
51 // KEYS
@@ -79,6 +80,7 @@ static inline void rrddimvar_create_variables(RRDDIMVAR *rs) {
80
81 RRDDIM *rd = rs->rrddim;
82 RRDSET *st = rd->rrdset;
83 + RRDHOST *host = st->rrdhost;
84
85 char buffer[RRDDIMVAR_ID_MAX + 1];
86
@@ -141,10 +143,10 @@ static inline void rrddimvar_create_variables(RRDDIMVAR *rs) {
143 // - $chart-name.id
144 // - $chart-name.name
145
144 - rs->var_host_chartidid = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, rs->key_fullidid, rs->type, rs->value);
145 - rs->var_host_chartidname = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, rs->key_fullidname, rs->type, rs->value);
146 - rs->var_host_chartnameid = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, rs->key_fullnameid, rs->type, rs->value);
147 - rs->var_host_chartnamename = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, rs->key_fullnamename, rs->type, rs->value);
146 + rs->var_host_chartidid = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullidid, rs->type, rs->value);
147 + rs->var_host_chartidname = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullidname, rs->type, rs->value);
148 + rs->var_host_chartnameid = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullnameid, rs->type, rs->value);
149 + rs->var_host_chartnamename = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullnamename, rs->type, rs->value);
150 }
151
152 RRDDIMVAR *rrddimvar_create(RRDDIM *rd, RRDVAR_TYPE type, const char *prefix, const char *suffix, void *value, RRDVAR_OPTIONS options) {
src/rrdhost.c
+1 -1
@@ -342,7 +342,7 @@ RRDHOST *rrdhost_find_or_create(
342 else {
343 host->health_enabled = health_enabled;
344
345 - if(strcmp(host->hostname, hostname)) {
345 + if(strcmp(host->hostname, hostname) != 0) {
346 char *t = host->hostname;
347 host->hostname = strdupz(hostname);
348 host->hash_hostname = simple_hash(host->hostname);
src/rrdset.c
+24 -17
@@ -83,7 +83,7 @@ static inline RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name, ui
83 result = avl_search_lock(&host->rrdset_root_index_name, (avl *) (&(tmp.avlname)));
84 if(result) {
85 RRDSET *st = rrdset_from_avlname(result);
86 - if(strcmp(st->magic, RRDSET_MAGIC))
86 + if(strcmp(st->magic, RRDSET_MAGIC) != 0)
87 error("Search for RRDSET %s returned an invalid RRDSET %s (name %s)", name, st->id, st->name);
88
89 // fprintf(stderr, "FOUND: %s\n", name);
@@ -139,6 +139,8 @@ int rrdset_set_name(RRDSET *st, const char *name) {
139 if(unlikely(st->name && !strcmp(st->name, name)))
140 return 1;
141
142 + RRDHOST *host = st->rrdhost;
143 +
144 debug(D_RRD_CALLS, "rrdset_set_name() old: '%s', new: '%s'", st->name?st->name:"", name);
145
146 char b[CONFIG_MAX_VALUE + 1];
@@ -147,13 +149,13 @@ int rrdset_set_name(RRDSET *st, const char *name) {
149 snprintfz(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
150 rrdset_strncpyz_name(b, n, CONFIG_MAX_VALUE);
151
150 - if(rrdset_index_find_name(st->rrdhost, b, 0)) {
151 - error("RRDSET: chart name '%s' on host '%s' already exists.", b, st->rrdhost->hostname);
152 + if(rrdset_index_find_name(host, b, 0)) {
153 + error("RRDSET: chart name '%s' on host '%s' already exists.", b, host->hostname);
154 return 0;
155 }
156
157 if(st->name) {
156 - rrdset_index_del_name(st->rrdhost, st);
158 + rrdset_index_del_name(host, st);
159 st->name = config_set_default(st->config_section, "name", b);
160 st->hash_name = simple_hash(st->name);
161 rrdsetvar_rename_all(st);
@@ -169,20 +171,22 @@ int rrdset_set_name(RRDSET *st, const char *name) {
171 rrddimvar_rename_all(rd);
172 rrdset_unlock(st);
173
172 - if(unlikely(rrdset_index_add_name(st->rrdhost, st) != st))
174 + if(unlikely(rrdset_index_add_name(host, st) != st))
175 error("RRDSET: INTERNAL ERROR: attempted to index duplicate chart name '%s'", st->name);
176
177 return 1;
178 }
179
180 inline void rrdset_is_obsolete(RRDSET *st) {
181 + RRDHOST *host = st->rrdhost;
182 +
183 if(unlikely(!(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE)))) {
184 rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE);
185 rrdset_flag_clear(st, RRDSET_FLAG_EXPOSED_UPSTREAM);
186
187 // the chart will not get more updates (data collection)
188 // so, we have to push its definition now
185 - if(unlikely(st->rrdhost->rrdpush_send_enabled))
189 + if(unlikely(host->rrdpush_send_enabled))
190 rrdset_push_chart_definition(st);
191 }
192 }
@@ -198,6 +202,7 @@ inline void rrdset_isnot_obsolete(RRDSET *st) {
202 }
203
204 inline void rrdset_update_heterogeneous_flag(RRDSET *st) {
205 + RRDHOST *host = st->rrdhost;
206 RRDDIM *rd;
207
208 rrdset_flag_clear(st, RRDSET_FLAG_HOMEGENEOUS_CHECK);
@@ -213,7 +218,7 @@ inline void rrdset_update_heterogeneous_flag(RRDSET *st) {
218 info("Dimension '%s' added on chart '%s' of host '%s' is not homogeneous to other dimensions already present (algorithm is '%s' vs '%s', multiplier is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ", divisor is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ").",
219 rd->name,
220 st->name,
216 - st->rrdhost->hostname,
221 + host->hostname,
222 rrd_algorithm_name(rd->algorithm), rrd_algorithm_name(algorithm),
223 rd->multiplier, multiplier,
224 rd->divisor, divisor
@@ -294,7 +299,9 @@ static inline void last_updated_time_align(RRDSET *st) {
299 void rrdset_free(RRDSET *st) {
300 if(unlikely(!st)) return;
301
297 - rrdhost_check_wrlock(st->rrdhost); // make sure we have a write lock on the host
302 + RRDHOST *host = st->rrdhost;
303 +
304 + rrdhost_check_wrlock(host); // make sure we have a write lock on the host
305 rrdset_wrlock(st); // lock this RRDSET
306
307 // info("Removing chart '%s' ('%s')", st->id, st->name);
@@ -302,10 +309,10 @@ void rrdset_free(RRDSET *st) {
309 // ------------------------------------------------------------------------
310 // remove it from the indexes
311
305 - if(unlikely(rrdset_index_del(st->rrdhost, st) != st))
312 + if(unlikely(rrdset_index_del(host, st) != st))
313 error("RRDSET: INTERNAL ERROR: attempt to remove from index chart '%s', removed a different chart.", st->id);
314
308 - rrdset_index_del_name(st->rrdhost, st);
315 + rrdset_index_del_name(host, st);
316
317 // ------------------------------------------------------------------------
318 // free its children structures
@@ -314,25 +321,25 @@ void rrdset_free(RRDSET *st) {
321 while(st->alarms) rrdsetcalc_unlink(st->alarms);
322 while(st->dimensions) rrddim_free(st, st->dimensions);
323
317 - rrdfamily_free(st->rrdhost, st->rrdfamily);
324 + rrdfamily_free(host, st->rrdfamily);
325
319 - debug(D_RRD_CALLS, "RRDSET: Cleaning up remaining chart variables for host '%s', chart '%s'", st->rrdhost->hostname, st->id);
320 - rrdvar_free_remaining_variables(st->rrdhost, &st->rrdvar_root_index);
326 + debug(D_RRD_CALLS, "RRDSET: Cleaning up remaining chart variables for host '%s', chart '%s'", host->hostname, st->id);
327 + rrdvar_free_remaining_variables(host, &st->rrdvar_root_index);
328
329 // ------------------------------------------------------------------------
330 // unlink it from the host
331
325 - if(st == st->rrdhost->rrdset_root) {
326 - st->rrdhost->rrdset_root = st->next;
332 + if(st == host->rrdset_root) {
333 + host->rrdset_root = st->next;
334 }
335 else {
336 // find the previous one
337 RRDSET *s;
331 - for(s = st->rrdhost->rrdset_root; s && s->next != st ; s = s->next) ;
338 + for(s = host->rrdset_root; s && s->next != st ; s = s->next) ;
339
340 // bypass it
341 if(s) s->next = st->next;
335 - else error("Request to free RRDSET '%s': cannot find it under host '%s'", st->id, st->rrdhost->hostname);
342 + else error("Request to free RRDSET '%s': cannot find it under host '%s'", st->id, host->hostname);
343 }
344
345 rrdset_unlock(st);
src/rrdsetvar.c
+12 -8
@@ -7,26 +7,27 @@
7
8 static inline void rrdsetvar_free_variables(RRDSETVAR *rs) {
9 RRDSET *st = rs->rrdset;
10 + RRDHOST *host = st->rrdhost;
11
12 // ------------------------------------------------------------------------
13 // CHART
13 - rrdvar_free(st->rrdhost, &st->rrdvar_root_index, rs->var_local);
14 + rrdvar_free(host, &st->rrdvar_root_index, rs->var_local);
15 rs->var_local = NULL;
16
17 // ------------------------------------------------------------------------
18 // FAMILY
18 - rrdvar_free(st->rrdhost, &st->rrdfamily->rrdvar_root_index, rs->var_family);
19 + rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family);
20 rs->var_family = NULL;
21
21 - rrdvar_free(st->rrdhost, &st->rrdfamily->rrdvar_root_index, rs->var_family_name);
22 + rrdvar_free(host, &st->rrdfamily->rrdvar_root_index, rs->var_family_name);
23 rs->var_family_name = NULL;
24
25 // ------------------------------------------------------------------------
26 // HOST
26 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rs->var_host);
27 + rrdvar_free(host, &host->rrdvar_root_index, rs->var_host);
28 rs->var_host = NULL;
29
29 - rrdvar_free(st->rrdhost, &st->rrdhost->rrdvar_root_index, rs->var_host_name);
30 + rrdvar_free(host, &host->rrdvar_root_index, rs->var_host_name);
31 rs->var_host_name = NULL;
32
33 // ------------------------------------------------------------------------
@@ -40,6 +41,7 @@ static inline void rrdsetvar_free_variables(RRDSETVAR *rs) {
41
42 static inline void rrdsetvar_create_variables(RRDSETVAR *rs) {
43 RRDSET *st = rs->rrdset;
44 + RRDHOST *host = st->rrdhost;
45
46 // ------------------------------------------------------------------------
47 // free the old ones (if any)
@@ -67,8 +69,8 @@ static inline void rrdsetvar_create_variables(RRDSETVAR *rs) {
69
70 // ------------------------------------------------------------------------
71 // HOST
70 - rs->var_host = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, rs->key_fullid, rs->type, rs->value);
71 - rs->var_host_name = rrdvar_create_and_index("host", &st->rrdhost->rrdvar_root_index, rs->key_fullname, rs->type, rs->value);
72 + rs->var_host = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullid, rs->type, rs->value);
73 + rs->var_host_name = rrdvar_create_and_index("host", &host->rrdvar_root_index, rs->key_fullname, rs->type, rs->value);
74 }
75
76 RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, RRDVAR_TYPE type, void *value, RRDVAR_OPTIONS options) {
@@ -128,6 +130,8 @@ void rrdsetvar_free(RRDSETVAR *rs) {
130 // custom chart variables
131
132 RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name) {
133 + RRDHOST *host = st->rrdhost;
134 +
135 char *n = strdupz(name);
136 rrdvar_fix_name(n);
137 uint32_t hash = simple_hash(n);
@@ -144,7 +148,7 @@ RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name)
148 return rs;
149 }
150 else {
147 - error("RRDSETVAR: custom variable '%s' on chart '%s' of host '%s', conflicts with an internal chart variable", n, st->id, st->rrdhost->hostname);
151 + error("RRDSETVAR: custom variable '%s' on chart '%s' of host '%s', conflicts with an internal chart variable", n, st->id, host->hostname);
152 free(n);
153 return NULL;
154 }
src/rrdvar.c
+8 -5
@@ -205,10 +205,11 @@ static calculated_number rrdvar2number(RRDVAR *rv) {
205
206 int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result) {
207 RRDSET *st = rc->rrdset;
208 - RRDVAR *rv;
209 -
208 if(!st) return 0;
209
210 + RRDHOST *host = st->rrdhost;
211 + RRDVAR *rv;
212 +
213 rv = rrdvar_index_find(&st->rrdvar_root_index, variable, hash);
214 if(rv) {
215 *result = rrdvar2number(rv);
@@ -221,7 +222,7 @@ int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, cal
222 return 1;
223 }
224
224 - rv = rrdvar_index_find(&st->rrdhost->rrdvar_root_index, variable, hash);
225 + rv = rrdvar_index_find(&host->rrdvar_root_index, variable, hash);
226 if(rv) {
227 *result = rrdvar2number(rv);
228 return 1;
@@ -254,6 +255,8 @@ static int single_variable2json(void *entry, void *data) {
255 }
256
257 void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf) {
258 + RRDHOST *host = st->rrdhost;
259 +
260 struct variable2json_helper helper = {
261 .buf = buf,
262 .counter = 0
@@ -264,9 +267,9 @@ void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf) {
267 buffer_sprintf(buf, "\n\t},\n\t\"family\": \"%s\",\n\t\"family_variables\": {", st->family);
268 helper.counter = 0;
269 avl_traverse_lock(&st->rrdfamily->rrdvar_root_index, single_variable2json, (void *)&helper);
267 - buffer_sprintf(buf, "\n\t},\n\t\"host\": \"%s\",\n\t\"host_variables\": {", st->rrdhost->hostname);
270 + buffer_sprintf(buf, "\n\t},\n\t\"host\": \"%s\",\n\t\"host_variables\": {", host->hostname);
271 helper.counter = 0;
269 - avl_traverse_lock(&st->rrdhost->rrdvar_root_index, single_variable2json, (void *)&helper);
272 + avl_traverse_lock(&host->rrdvar_root_index, single_variable2json, (void *)&helper);
273 buffer_strcat(buf, "\n\t}\n}\n");
274 }
275
src/statistical.c
+18 -18
@@ -2,7 +2,7 @@
2
3 // --------------------------------------------------------------------------------------------------------------------
4
5 -inline long double sum_and_count(long double *series, size_t entries, size_t *count) {
5 +inline long double sum_and_count(const long double *series, size_t entries, size_t *count) {
6 if(unlikely(entries == 0)) {
7 if(likely(count))
8 *count = 0;
@@ -36,11 +36,11 @@ inline long double sum_and_count(long double *series, size_t entries, size_t *co
36 return sum;
37 }
38
39 -inline long double sum(long double *series, size_t entries) {
39 +inline long double sum(const long double *series, size_t entries) {
40 return sum_and_count(series, entries, NULL);
41 }
42
43 -inline long double average(long double *series, size_t entries) {
43 +inline long double average(const long double *series, size_t entries) {
44 size_t count = 0;
45 long double sum = sum_and_count(series, entries, &count);
46
@@ -52,7 +52,7 @@ inline long double average(long double *series, size_t entries) {
52
53 // --------------------------------------------------------------------------------------------------------------------
54
55 -long double moving_average(long double *series, size_t entries, size_t period) {
55 +long double moving_average(const long double *series, size_t entries, size_t period) {
56 if(unlikely(period <= 0))
57 return 0.0;
58
@@ -109,13 +109,13 @@ inline void sort_series(long double *series, size_t entries) {
109 qsort(series, entries, sizeof(long double), qsort_compare);
110 }
111
112 -inline long double *copy_series(long double *series, size_t entries) {
112 +inline long double *copy_series(const long double *series, size_t entries) {
113 long double *copy = mallocz(sizeof(long double) * entries);
114 memcpy(copy, series, sizeof(long double) * entries);
115 return copy;
116 }
117
118 -long double median_on_sorted_series(long double *series, size_t entries) {
118 +long double median_on_sorted_series(const long double *series, size_t entries) {
119 if(unlikely(entries == 0))
120 return NAN;
121
@@ -137,7 +137,7 @@ long double median_on_sorted_series(long double *series, size_t entries) {
137 return avg;
138 }
139
140 -long double median(long double *series, size_t entries) {
140 +long double median(const long double *series, size_t entries) {
141 if(unlikely(entries == 0))
142 return NAN;
143
@@ -158,7 +158,7 @@ long double median(long double *series, size_t entries) {
158
159 // --------------------------------------------------------------------------------------------------------------------
160
161 -long double moving_median(long double *series, size_t entries, size_t period) {
161 +long double moving_median(const long double *series, size_t entries, size_t period) {
162 if(entries <= period)
163 return median(series, entries);
164
@@ -177,7 +177,7 @@ long double moving_median(long double *series, size_t entries, size_t period) {
177 // --------------------------------------------------------------------------------------------------------------------
178
179 // http://stackoverflow.com/a/15150143/4525767
180 -long double running_median_estimate(long double *series, size_t entries) {
180 +long double running_median_estimate(const long double *series, size_t entries) {
181 long double median = 0.0f;
182 long double average = 0.0f;
183 size_t i;
@@ -195,7 +195,7 @@ long double running_median_estimate(long double *series, size_t entries) {
195
196 // --------------------------------------------------------------------------------------------------------------------
197
198 -long double standard_deviation(long double *series, size_t entries) {
198 +long double standard_deviation(const long double *series, size_t entries) {
199 if(unlikely(entries < 1))
200 return NAN;
201
@@ -243,7 +243,7 @@ long double standard_deviation(long double *series, size_t entries) {
243
244 // --------------------------------------------------------------------------------------------------------------------
245
246 -long double single_exponential_smoothing(long double *series, size_t entries, long double alpha) {
246 +long double single_exponential_smoothing(const long double *series, size_t entries, long double alpha) {
247 size_t i, count = 0;
248 long double level = 0, sum = 0;
249
@@ -267,7 +267,7 @@ long double single_exponential_smoothing(long double *series, size_t entries, lo
267 // --------------------------------------------------------------------------------------------------------------------
268
269 // http://grisha.org/blog/2016/02/16/triple-exponential-smoothing-forecasting-part-ii/
270 -long double double_exponential_smoothing(long double *series, size_t entries, long double alpha, long double beta, long double *forecast) {
270 +long double double_exponential_smoothing(const long double *series, size_t entries, long double alpha, long double beta, long double *forecast) {
271 size_t i, count = 0;
272 long double level = series[0], trend, sum;
273
@@ -327,17 +327,17 @@ long double double_exponential_smoothing(long double *series, size_t entries, lo
327 * s[t] = γ (Y[t] / a[t]) + (1-γ) s[t-p]
328 */
329 static int __HoltWinters(
330 - long double *series,
330 + const long double *series,
331 int entries, // start_time + h
332
333 long double alpha, // alpha parameter of Holt-Winters Filter.
334 long double beta, // beta parameter of Holt-Winters Filter. If set to 0, the function will do exponential smoothing.
335 long double gamma, // gamma parameter used for the seasonal component. If set to 0, an non-seasonal model is fitted.
336
337 - int *seasonal,
338 - int *period,
339 - long double *a, // Start value for level (a[0]).
340 - long double *b, // Start value for trend (b[0]).
337 + const int *seasonal,
338 + const int *period,
339 + const long double *a, // Start value for level (a[0]).
340 + const long double *b, // Start value for trend (b[0]).
341 long double *s, // Vector of start values for the seasonal component (s_1[0] ... s_p[0])
342
343 /* return values */
@@ -404,7 +404,7 @@ static int __HoltWinters(
404 return 1;
405 }
406
407 -long double holtwinters(long double *series, size_t entries, long double alpha, long double beta, long double gamma, long double *forecast) {
407 +long double holtwinters(const long double *series, size_t entries, long double alpha, long double beta, long double gamma, long double *forecast) {
408 if(unlikely(isnan(alpha)))
409 alpha = 0.3;
410
src/statistical.h
+13 -13
@@ -1,19 +1,19 @@
1 #ifndef NETDATA_STATISTICAL_H
2 #define NETDATA_STATISTICAL_H
3
4 -extern long double average(long double *series, size_t entries);
5 -extern long double moving_average(long double *series, size_t entries, size_t period);
6 -extern long double median(long double *series, size_t entries);
7 -extern long double moving_median(long double *series, size_t entries, size_t period);
8 -extern long double running_median_estimate(long double *series, size_t entries);
9 -extern long double standard_deviation(long double *series, size_t entries);
10 -extern long double single_exponential_smoothing(long double *series, size_t entries, long double alpha);
11 -extern long double double_exponential_smoothing(long double *series, size_t entries, long double alpha, long double beta, long double *forecast);
12 -extern long double holtwinters(long double *series, size_t entries, long double alpha, long double beta, long double gamma, long double *forecast);
13 -extern long double sum_and_count(long double *series, size_t entries, size_t *count);
14 -extern long double sum(long double *series, size_t entries);
15 -extern long double median_on_sorted_series(long double *series, size_t entries);
16 -extern long double *copy_series(long double *series, size_t entries);
4 +extern long double average(const long double *series, size_t entries);
5 +extern long double moving_average(const long double *series, size_t entries, size_t period);
6 +extern long double median(const long double *series, size_t entries);
7 +extern long double moving_median(const long double *series, size_t entries, size_t period);
8 +extern long double running_median_estimate(const long double *series, size_t entries);
9 +extern long double standard_deviation(const long double *series, size_t entries);
10 +extern long double single_exponential_smoothing(const long double *series, size_t entries, long double alpha);
11 +extern long double double_exponential_smoothing(const long double *series, size_t entries, long double alpha, long double beta, long double *forecast);
12 +extern long double holtwinters(const long double *series, size_t entries, long double alpha, long double beta, long double gamma, long double *forecast);
13 +extern long double sum_and_count(const long double *series, size_t entries, size_t *count);
14 +extern long double sum(const long double *series, size_t entries);
15 +extern long double median_on_sorted_series(const long double *series, size_t entries);
16 +extern long double *copy_series(const long double *series, size_t entries);
17 extern void sort_series(long double *series, size_t entries);
18
19 #endif //NETDATA_STATISTICAL_H
src/statsd.c
+14 -4
@@ -724,8 +724,6 @@ static void statsd_del_callback(int fd, int socktype, void *data) {
724
725 freez(data);
726 }
727 -
728 - return;
727 }
728
729 // Receive data
@@ -1065,6 +1063,12 @@ int statsd_readfile(const char *path, const char *filename) {
1063 statsd.apps = app;
1064 chart = NULL;
1065 dict = NULL;
1066 +
1067 + {
1068 + char lineandfile[FILENAME_MAX + 1];
1069 + snprintfz(lineandfile, FILENAME_MAX, "%zu@%s", line, filename);
1070 + app->source = strdupz(lineandfile);
1071 + }
1072 }
1073 else if(app) {
1074 if(!strcmp(s, "dictionary")) {
@@ -1090,6 +1094,12 @@ int statsd_readfile(const char *path, const char *filename) {
1094
1095 chart->next = app->charts;
1096 app->charts = chart;
1097 +
1098 + {
1099 + char lineandfile[FILENAME_MAX + 1];
1100 + snprintfz(lineandfile, FILENAME_MAX, "%zu@%s", line, filename);
1101 + chart->source = strdupz(lineandfile);
1102 + }
1103 }
1104 }
1105 else
@@ -1364,7 +1374,7 @@ static inline RRDSET *statsd_private_rrdset_create(
1374 , title // title
1375 , units // units
1376 , "statsd" // plugin
1367 - , NULL // module
1377 + , "private_chart" // module
1378 , priority // priority
1379 , update_every // update every
1380 , chart_type // chart type
@@ -1871,7 +1881,7 @@ static inline void statsd_update_app_chart(STATSD_APP *app, STATSD_APP_CHART *ch
1881 , chart->title // title
1882 , chart->units // units
1883 , "statsd" // plugin
1874 - , NULL // module
1884 + , chart->source // module
1885 , chart->priority // priority
1886 , statsd.update_every // update every
1887 , chart->chart_type // chart type
src/storage_number.c
-4
@@ -1,9 +1,5 @@
1 #include "common.h"
2
3 -extern char *print_number_lu_r(char *str, unsigned long uvalue);
4 -extern char *print_number_llu_r(char *str, unsigned long long uvalue);
5 -extern char *print_number_llu_r_smart(char *str, unsigned long long uvalue);
6 -
3 storage_number pack_storage_number(calculated_number value, uint32_t flags)
4 {
5 // bit 32 = sign 0:positive, 1:negative
src/sys_fs_cgroup.c
-1
@@ -1387,7 +1387,6 @@ static inline void find_all_cgroups() {
1387 }
1388
1389 debug(D_CGROUP, "done searching for cgroups");
1390 - return;
1390 }
1391
1392 // ----------------------------------------------------------------------------
src/web_buffer.c
+1 -1
@@ -21,7 +21,7 @@ static inline void _buffer_overflow_check(BUFFER *b, const char *file, const cha
21 b->len = b->size;
22 }
23
24 - if(b->buffer[b->size] != '\0' || strcmp(&b->buffer[b->size + 1], BUFFER_OVERFLOW_EOF)) {
24 + if(b->buffer[b->size] != '\0' || strcmp(&b->buffer[b->size + 1], BUFFER_OVERFLOW_EOF) != 0) {
25 error("BUFFER: detected overflow at line %lu, at function %s() of file '%s'.", line, function, file);
26 buffer_overflow_init(b);
27 }