+// RRD HOST
+
+struct rrdhost {
+ avl avl; // the index of hosts
+
+ char *hostname; // the hostname of this host
+ uint32_t hash_hostname; // the hostname hash
+
+ char machine_guid[GUID_LEN + 1]; // the unique ID of this host
+ uint32_t hash_machine_guid; // the hash of the unique ID
+
+ int rrd_update_every; // the update frequency of the host
+ int rrd_history_entries; // the number of history entries for the host's charts
+
+ 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; // the host charts
+
+ pthread_rwlock_t rrdhost_rwlock; // lock for this RRDHOST
+
+ 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; // the host's chart families index
+ avl_tree_lock variables_root_index; // the host's chart variables index
+
+ char *cache_dir; // the directory to save RRD cache files
+ char *varlib_dir; // the directory to save health log
+
+ // 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;
+
+ ALARM_LOG health_log; // alarms historical events (event log)
+
+ // templates of alarms
+ // these are used to create alarms when charts
+ // are created or renamed, that match them
+ RRDCALCTEMPLATE *templates;
+
+ // health / alarm settings
+ char *health_default_exec;
+ char *health_default_recipient;
+ char *health_log_filename;
+ size_t health_log_entries_written;
+ FILE *health_log_fp;
+
+ struct rrdhost *next;
+};
+typedef struct rrdhost RRDHOST;
+extern RRDHOST *localhost;
+
+#define rrdhost_rdlock(h) pthread_rwlock_rdlock(&((h)->rrdhost_rwlock))
+#define rrdhost_wrlock(h) pthread_rwlock_wrlock(&((h)->rrdhost_rwlock))
+#define rrdhost_unlock(h) pthread_rwlock_unlock(&((h)->rrdhost_rwlock))
+
+extern void rrd_init(char *hostname);
+
+extern RRDHOST *rrdhost_find(const char *guid, uint32_t hash);
+extern RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid);
+
+#ifdef NETDATA_INTERNAL_CHECKS
+#define rrdhost_check_rdlock(host) rrdhost_check_rdlock_int(host, __FILE__, __FUNCTION__, __LINE__)
+#define rrdhost_check_wrlock(host) rrdhost_check_wrlock_int(host, __FILE__, __FUNCTION__, __LINE__)
+#define rrd_check_rdlock() rrd_check_rdlock_int(__FILE__, __FUNCTION__, __LINE__)
+#define rrd_check_wrlock() rrd_check_wrlock_int(__FILE__, __FUNCTION__, __LINE__)
+#else
+#define rrdhost_check_rdlock(host) (void)0
+#define rrdhost_check_wrlock(host) (void)0
+#define rrd_check_rdlock() (void)0
+#define rrd_check_wrlock() (void)0
+#endif
+
+extern void rrdhost_check_wrlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line);
+extern void rrdhost_check_rdlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line);
+
+// ----------------------------------------------------------------------------
+// global lock for all RRDHOSTs
+
+extern pthread_rwlock_t rrd_rwlock;
+#define rrd_rdlock() pthread_rwlock_rdlock(&rrd_rwlock)
+#define rrd_wrlock() pthread_rwlock_wrlock(&rrd_rwlock)
+#define rrd_unlock() pthread_rwlock_unlock(&rrd_rwlock)
+
+
+// ----------------------------------------------------------------------------
+// RRDSET functions