@cryptotaxi247 / netdata-1 / commits / c35f24c5b

memory mode and health configuration per host

Costa Tsaousis (ktsaou) committed Feb 18, 2017 at 18:06 UTC c35f24c5b566a25f62a140b58fc8f930a0e2f12a
11 files changed +42 -40
src/health.c
+5 -8
@@ -3,7 +3,7 @@
3
4 #define RRDVAR_MAX_LENGTH 1024
5
6 -int health_enabled = 1;
6 +int default_localhost_health_enabled = 1;
7
8 // ----------------------------------------------------------------------------
9 // RRDVAR management
@@ -1075,7 +1075,7 @@ inline char *health_config_dir(void) {
1075 void health_init(void) {
1076 debug(D_HEALTH, "Health configuration initializing");
1077
1078 - if(!(health_enabled = config_get_boolean("health", "enabled", 1))) {
1078 + if(!(default_localhost_health_enabled = config_get_boolean("health", "enabled", 1))) {
1079 debug(D_HEALTH, "Health is disabled.");
1080 return;
1081 }
@@ -1098,11 +1098,6 @@ inline void health_free_host_nolock(RRDHOST *host) {
1098 }
1099
1100 void health_reload_host(RRDHOST *host) {
1101 - if(!health_enabled) {
1102 - error("Health reload is requested, but health is not enabled.");
1103 - return;
1104 - }
1105 -
1101 char *path = health_config_dir();
1102
1103 // free all running alarms
@@ -1406,7 +1401,7 @@ void *health_main(void *ptr) {
1401 BUFFER *wb = buffer_create(100);
1402
1403 unsigned int loop = 0;
1409 - while(health_enabled && !netdata_exit) {
1404 + while(!netdata_exit) {
1405 loop++;
1406 debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
1407
@@ -1420,6 +1415,8 @@ void *health_main(void *ptr) {
1415
1416 RRDHOST *host;
1417 for(host = localhost; host ; host = host->next) {
1418 + if(unlikely(!host->health_enabled)) continue;
1419 +
1420 rrdhost_rdlock(host);
1421
1422 // the first loop is to lookup values from the db
src/health.h
+1 -1
@@ -1,7 +1,7 @@
1 #ifndef NETDATA_HEALTH_H
2 #define NETDATA_HEALTH_H
3
4 -extern int health_enabled;
4 +extern int default_localhost_health_enabled;
5
6 extern int rrdvar_compare(void *a, void *b);
7
src/health_config.c
+2
@@ -828,6 +828,8 @@ int health_readfile(RRDHOST *host, const char *path, const char *filename) {
828 }
829
830 void health_readdir(RRDHOST *host, const char *path) {
831 + if(!host->health_enabled) return;
832 +
833 size_t pathlen = strlen(path);
834
835 debug(D_HEALTH, "Health configuration reading directory '%s'", path);
src/health_json.c
+1 -1
@@ -227,7 +227,7 @@ void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) {
227 "\n\t\"alarms\": {\n",
228 host->hostname,
229 (host->health_log.next_log_id > 0)?(host->health_log.next_log_id - 1):0,
230 - health_enabled?"true":"false",
230 + host->health_enabled?"true":"false",
231 (unsigned long)now_realtime_sec());
232
233 RRDCALC *rc;
src/main.c
+1 -1
@@ -639,7 +639,7 @@ int main(int argc, char **argv) {
639
640 // --------------------------------------------------------------------
641
642 - rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(rrd_memory_mode)));
642 + default_localhost_rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(default_localhost_rrd_memory_mode)));
643
644 // --------------------------------------------------------------------
645
src/rrd.c
+3 -3
@@ -13,7 +13,7 @@ int rrd_delete_unupdated_dimensions = 0;
13
14 int rrd_update_every = UPDATE_EVERY;
15 int rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
16 -RRD_MEMORY_MODE rrd_memory_mode = RRD_MEMORY_MODE_SAVE;
16 +RRD_MEMORY_MODE default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_SAVE;
17
18
19 // ----------------------------------------------------------------------------
@@ -113,7 +113,7 @@ const char *rrdset_type_name(RRDSET_TYPE chart_type) {
113 // ----------------------------------------------------------------------------
114 // RRD - cache directory
115
116 -char *rrdset_cache_dir(const char *id) {
116 +char *rrdset_cache_dir(RRDHOST *host, const char *id) {
117 char *ret = NULL;
118
119 char b[FILENAME_MAX + 1];
@@ -123,7 +123,7 @@ char *rrdset_cache_dir(const char *id) {
123 snprintfz(n, FILENAME_MAX, "%s/%s", netdata_configured_cache_dir, b);
124 ret = config_get(id, "cache directory", n);
125
126 - if(rrd_memory_mode == RRD_MEMORY_MODE_MAP || rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
126 + if(host->rrd_memory_mode == RRD_MEMORY_MODE_MAP || host->rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
127 int r = mkdir(ret, 0775);
128 if(r != 0 && errno != EEXIST)
129 error("Cannot create directory '%s'", ret);
src/rrd.h
+16 -16
@@ -47,7 +47,7 @@ typedef enum rrd_memory_mode {
47 #define RRD_MEMORY_MODE_MAP_NAME "map"
48 #define RRD_MEMORY_MODE_SAVE_NAME "save"
49
50 -RRD_MEMORY_MODE rrd_memory_mode;
50 +extern RRD_MEMORY_MODE default_localhost_rrd_memory_mode;
51
52 extern const char *rrd_memory_mode_name(RRD_MEMORY_MODE id);
53 extern RRD_MEMORY_MODE rrd_memory_mode_id(const char *name);
@@ -294,32 +294,32 @@ typedef struct rrdset RRDSET;
294 // RRD HOST
295
296 struct rrdhost {
297 - avl avl;
297 + avl avl; // the index of hosts
298
299 - char *hostname;
300 - uint32_t hash_hostname;
299 + char *hostname; // the hostname of this host
300 + uint32_t hash_hostname; // the hostname hash
301
302 - char machine_guid[GUID_LEN + 1];
303 - uint32_t hash_machine_guid;
302 + char machine_guid[GUID_LEN + 1]; // the unique ID of this host
303 + uint32_t hash_machine_guid; // the hash of the unique ID
304
305 - uint32_t flags;
305 + int health_enabled; // 1 when this host has health enabled
306 + RRD_MEMORY_MODE rrd_memory_mode; // the memory more for the charts of this host
307
307 - RRDSET *rrdset_root;
308 - pthread_rwlock_t rrdset_root_rwlock;
308 + RRDSET *rrdset_root; // the host charts
309 + pthread_rwlock_t rrdset_root_rwlock; // lock for the host charts
310
310 - avl_tree_lock rrdset_root_index;
311 - avl_tree_lock rrdset_root_index_name;
311 + avl_tree_lock rrdset_root_index; // the host's charts index (by id)
312 + avl_tree_lock rrdset_root_index_name; // the host's charts index (by name)
313
313 - avl_tree_lock rrdfamily_root_index;
314 - avl_tree_lock variables_root_index;
314 + avl_tree_lock rrdfamily_root_index; // the host's chart families index
315 + avl_tree_lock variables_root_index; // the host's chart variables index
316
317 // all RRDCALCs are primarily allocated and linked here
318 // RRDCALCs may be linked to charts at any point
319 // (charts may or may not exist when these are loaded)
320 RRDCALC *alarms;
321
321 - // alarms historical events
322 - ALARM_LOG health_log;
322 + ALARM_LOG health_log; // alarms historical events (event log)
323
324 // templates of alarms
325 // these are used to create alarms when charts
@@ -455,7 +455,7 @@ extern collected_number rrddim_set(RRDSET *st, const char *id, collected_number
455 extern avl_tree_lock rrdhost_root_index;
456
457 extern char *rrdset_strncpyz_name(char *to, const char *from, size_t length);
458 -extern char *rrdset_cache_dir(const char *id);
458 +extern char *rrdset_cache_dir(RRDHOST *host, const char *id);
459
460 extern void rrdset_reset(RRDSET *st);
461
src/rrddim.c
+4 -4
@@ -71,15 +71,15 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, collected_numbe
71 rrdset_strncpyz_name(filename, id, FILENAME_MAX);
72 snprintfz(fullfilename, FILENAME_MAX, "%s/%s.db", st->cache_dir, filename);
73
74 - if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) {
75 - rd = (RRDDIM *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP) ? MAP_SHARED : MAP_PRIVATE), 1);
74 + if(st->rrdhost->rrd_memory_mode != RRD_MEMORY_MODE_RAM) {
75 + rd = (RRDDIM *)mymmap(fullfilename, size, ((st->rrdhost->rrd_memory_mode == RRD_MEMORY_MODE_MAP) ? MAP_SHARED : MAP_PRIVATE), 1);
76 if(likely(rd)) {
77 // we have a file mapped for rd
78
79 rd->id = NULL;
80 rd->name = NULL;
81 rd->cache_filename = NULL;
82 - rd->memory_mode = rrd_memory_mode;
82 + rd->memory_mode = st->rrdhost->rrd_memory_mode;
83 rd->flags = 0x00000000;
84 rd->variables = NULL;
85 rd->next = NULL;
@@ -184,7 +184,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, collected_numbe
184 td->next = rd;
185 }
186
187 - if(health_enabled) {
187 + if(st->rrdhost->health_enabled) {
188 rrddimvar_create(rd, RRDVAR_TYPE_CALCULATED, NULL, NULL, &rd->last_stored_value, 0);
189 rrddimvar_create(rd, RRDVAR_TYPE_COLLECTED, NULL, "_raw", &rd->last_collected_value, 0);
190 rrddimvar_create(rd, RRDVAR_TYPE_TIME_T, NULL, "_last_collected_t", &rd->last_collected_time.tv_sec, 0);
src/rrdhost.c
+3
@@ -54,6 +54,9 @@ RRDHOST *rrdhost_create(const char *hostname, const char *guid) {
54
55 RRDHOST *host = callocz(1, sizeof(RRDHOST));
56
57 + host->rrd_memory_mode = default_localhost_rrd_memory_mode;
58 + host->health_enabled = default_localhost_health_enabled;
59 +
60 pthread_rwlock_init(&(host->rrdset_root_rwlock), NULL);
61
62 rrdhost_init_hostname(host, hostname);
src/rrdset.c
+4 -4
@@ -242,12 +242,12 @@ RRDSET *rrdset_create(RRDHOST *host, const char *type, const char *id, const cha
242 if(!enabled) entries = 5;
243
244 unsigned long size = sizeof(RRDSET);
245 - char *cache_dir = rrdset_cache_dir(fullid);
245 + char *cache_dir = rrdset_cache_dir(host, fullid);
246
247 debug(D_RRD_CALLS, "Creating RRD_STATS for '%s.%s'.", type, id);
248
249 snprintfz(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir);
250 - if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) st = (RRDSET *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 0);
250 + if(host->rrd_memory_mode != RRD_MEMORY_MODE_RAM) st = (RRDSET *)mymmap(fullfilename, size, ((host->rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 0);
251 if(st) {
252 if(strcmp(st->magic, RRDSET_MAGIC) != 0) {
253 errno = 0;
@@ -291,7 +291,7 @@ RRDSET *rrdset_create(RRDHOST *host, const char *type, const char *id, const cha
291 st->units = NULL;
292 st->dimensions = NULL;
293 st->next = NULL;
294 - st->mapped = rrd_memory_mode;
294 + st->mapped = host->rrd_memory_mode;
295 st->variables = NULL;
296 st->alarms = NULL;
297 memset(&st->rwlock, 0, sizeof(pthread_rwlock_t));
@@ -372,7 +372,7 @@ RRDSET *rrdset_create(RRDHOST *host, const char *type, const char *id, const cha
372 st->next = host->rrdset_root;
373 host->rrdset_root = st;
374
375 - if(health_enabled) {
375 + if(host->health_enabled) {
376 rrdsetvar_create(st, "last_collected_t", RRDVAR_TYPE_TIME_T, &st->last_collected_time.tv_sec, 0);
377 rrdsetvar_create(st, "collected_total_raw", RRDVAR_TYPE_TOTAL, &st->last_collected_total, 0);
378 rrdsetvar_create(st, "green", RRDVAR_TYPE_CALCULATED, &st->green, 0);
src/unit_test.c
+2 -2
@@ -884,7 +884,7 @@ int run_test(struct test *test)
884 {
885 fprintf(stderr, "\nRunning test '%s':\n%s\n", test->name, test->description);
886
887 - rrd_memory_mode = RRD_MEMORY_MODE_RAM;
887 + default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
888 rrd_update_every = test->update_every;
889
890 char name[101];
@@ -1091,7 +1091,7 @@ int unit_test(long delay, long shift)
1091 snprintfz(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
1092
1093 //debug_flags = 0xffffffff;
1094 - rrd_memory_mode = RRD_MEMORY_MODE_RAM;
1094 + default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
1095 rrd_update_every = 1;
1096
1097 int do_abs = 1;