#define RRDVAR_MAX_LENGTH 1024
-int health_enabled = 1;
+int default_localhost_health_enabled = 1;
// ----------------------------------------------------------------------------
// RRDVAR management
void health_init(void) {
debug(D_HEALTH, "Health configuration initializing");
- if(!(health_enabled = config_get_boolean("health", "enabled", 1))) {
+ if(!(default_localhost_health_enabled = config_get_boolean("health", "enabled", 1))) {
debug(D_HEALTH, "Health is disabled.");
return;
}
}
void health_reload_host(RRDHOST *host) {
- if(!health_enabled) {
- error("Health reload is requested, but health is not enabled.");
- return;
- }
-
char *path = health_config_dir();
// free all running alarms
BUFFER *wb = buffer_create(100);
unsigned int loop = 0;
- while(health_enabled && !netdata_exit) {
+ while(!netdata_exit) {
loop++;
debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
RRDHOST *host;
for(host = localhost; host ; host = host->next) {
+ if(unlikely(!host->health_enabled)) continue;
+
rrdhost_rdlock(host);
// the first loop is to lookup values from the db
#ifndef NETDATA_HEALTH_H
#define NETDATA_HEALTH_H
-extern int health_enabled;
+extern int default_localhost_health_enabled;
extern int rrdvar_compare(void *a, void *b);
}
void health_readdir(RRDHOST *host, const char *path) {
+ if(!host->health_enabled) return;
+
size_t pathlen = strlen(path);
debug(D_HEALTH, "Health configuration reading directory '%s'", path);
"\n\t\"alarms\": {\n",
host->hostname,
(host->health_log.next_log_id > 0)?(host->health_log.next_log_id - 1):0,
- health_enabled?"true":"false",
+ host->health_enabled?"true":"false",
(unsigned long)now_realtime_sec());
RRDCALC *rc;
// --------------------------------------------------------------------
- rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(rrd_memory_mode)));
+ default_localhost_rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(default_localhost_rrd_memory_mode)));
// --------------------------------------------------------------------
int rrd_update_every = UPDATE_EVERY;
int rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
-RRD_MEMORY_MODE rrd_memory_mode = RRD_MEMORY_MODE_SAVE;
+RRD_MEMORY_MODE default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_SAVE;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// RRD - cache directory
-char *rrdset_cache_dir(const char *id) {
+char *rrdset_cache_dir(RRDHOST *host, const char *id) {
char *ret = NULL;
char b[FILENAME_MAX + 1];
snprintfz(n, FILENAME_MAX, "%s/%s", netdata_configured_cache_dir, b);
ret = config_get(id, "cache directory", n);
- if(rrd_memory_mode == RRD_MEMORY_MODE_MAP || rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
+ if(host->rrd_memory_mode == RRD_MEMORY_MODE_MAP || host->rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
int r = mkdir(ret, 0775);
if(r != 0 && errno != EEXIST)
error("Cannot create directory '%s'", ret);
#define RRD_MEMORY_MODE_MAP_NAME "map"
#define RRD_MEMORY_MODE_SAVE_NAME "save"
-RRD_MEMORY_MODE rrd_memory_mode;
+extern RRD_MEMORY_MODE default_localhost_rrd_memory_mode;
extern const char *rrd_memory_mode_name(RRD_MEMORY_MODE id);
extern RRD_MEMORY_MODE rrd_memory_mode_id(const char *name);
// RRD HOST
struct rrdhost {
- avl avl;
+ avl avl; // the index of hosts
- char *hostname;
- uint32_t hash_hostname;
+ char *hostname; // the hostname of this host
+ uint32_t hash_hostname; // the hostname hash
- char machine_guid[GUID_LEN + 1];
- uint32_t hash_machine_guid;
+ char machine_guid[GUID_LEN + 1]; // the unique ID of this host
+ uint32_t hash_machine_guid; // the hash of the unique ID
- uint32_t flags;
+ int health_enabled; // 1 when this host has health enabled
+ RRD_MEMORY_MODE rrd_memory_mode; // the memory more for the charts of this host
- RRDSET *rrdset_root;
- pthread_rwlock_t rrdset_root_rwlock;
+ RRDSET *rrdset_root; // the host charts
+ pthread_rwlock_t rrdset_root_rwlock; // lock for the host charts
- avl_tree_lock rrdset_root_index;
- avl_tree_lock rrdset_root_index_name;
+ avl_tree_lock rrdset_root_index; // the host's charts index (by id)
+ avl_tree_lock rrdset_root_index_name; // the host's charts index (by name)
- avl_tree_lock rrdfamily_root_index;
- avl_tree_lock variables_root_index;
+ avl_tree_lock rrdfamily_root_index; // the host's chart families index
+ avl_tree_lock variables_root_index; // the host's chart variables index
// all RRDCALCs are primarily allocated and linked here
// RRDCALCs may be linked to charts at any point
// (charts may or may not exist when these are loaded)
RRDCALC *alarms;
- // alarms historical events
- ALARM_LOG health_log;
+ ALARM_LOG health_log; // alarms historical events (event log)
// templates of alarms
// these are used to create alarms when charts
extern avl_tree_lock rrdhost_root_index;
extern char *rrdset_strncpyz_name(char *to, const char *from, size_t length);
-extern char *rrdset_cache_dir(const char *id);
+extern char *rrdset_cache_dir(RRDHOST *host, const char *id);
extern void rrdset_reset(RRDSET *st);
rrdset_strncpyz_name(filename, id, FILENAME_MAX);
snprintfz(fullfilename, FILENAME_MAX, "%s/%s.db", st->cache_dir, filename);
- if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) {
- rd = (RRDDIM *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP) ? MAP_SHARED : MAP_PRIVATE), 1);
+ if(st->rrdhost->rrd_memory_mode != RRD_MEMORY_MODE_RAM) {
+ rd = (RRDDIM *)mymmap(fullfilename, size, ((st->rrdhost->rrd_memory_mode == RRD_MEMORY_MODE_MAP) ? MAP_SHARED : MAP_PRIVATE), 1);
if(likely(rd)) {
// we have a file mapped for rd
rd->id = NULL;
rd->name = NULL;
rd->cache_filename = NULL;
- rd->memory_mode = rrd_memory_mode;
+ rd->memory_mode = st->rrdhost->rrd_memory_mode;
rd->flags = 0x00000000;
rd->variables = NULL;
rd->next = NULL;
td->next = rd;
}
- if(health_enabled) {
+ 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);
RRDHOST *host = callocz(1, sizeof(RRDHOST));
+ host->rrd_memory_mode = default_localhost_rrd_memory_mode;
+ host->health_enabled = default_localhost_health_enabled;
+
pthread_rwlock_init(&(host->rrdset_root_rwlock), NULL);
rrdhost_init_hostname(host, hostname);
if(!enabled) entries = 5;
unsigned long size = sizeof(RRDSET);
- char *cache_dir = rrdset_cache_dir(fullid);
+ char *cache_dir = rrdset_cache_dir(host, fullid);
debug(D_RRD_CALLS, "Creating RRD_STATS for '%s.%s'.", type, id);
snprintfz(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir);
- 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);
+ 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);
if(st) {
if(strcmp(st->magic, RRDSET_MAGIC) != 0) {
errno = 0;
st->units = NULL;
st->dimensions = NULL;
st->next = NULL;
- st->mapped = rrd_memory_mode;
+ st->mapped = host->rrd_memory_mode;
st->variables = NULL;
st->alarms = NULL;
memset(&st->rwlock, 0, sizeof(pthread_rwlock_t));
st->next = host->rrdset_root;
host->rrdset_root = st;
- if(health_enabled) {
+ 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);
{
fprintf(stderr, "\nRunning test '%s':\n%s\n", test->name, test->description);
- rrd_memory_mode = RRD_MEMORY_MODE_RAM;
+ default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
rrd_update_every = test->update_every;
char name[101];
snprintfz(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
//debug_flags = 0xffffffff;
- rrd_memory_mode = RRD_MEMORY_MODE_RAM;
+ default_localhost_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
rrd_update_every = 1;
int do_abs = 1;