summaryrefslogtreecommitdiffstats
path: root/src/rrdhost.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rrdhost.c')
-rw-r--r--src/rrdhost.c105
1 files changed, 65 insertions, 40 deletions
diff --git a/src/rrdhost.c b/src/rrdhost.c
index ff8aa5617..831cc46c8 100644
--- a/src/rrdhost.c
+++ b/src/rrdhost.c
@@ -86,6 +86,15 @@ static inline void rrdhost_init_os(RRDHOST *host, const char *os) {
freez(old);
}
+static inline void rrdhost_init_timezone(RRDHOST *host, const char *timezone) {
+ if(host->timezone && timezone && !strcmp(host->timezone, timezone))
+ return;
+
+ void *old = (void *)host->timezone;
+ host->timezone = strdupz((timezone && *timezone)?timezone:"unknown");
+ freez(old);
+}
+
static inline void rrdhost_init_machine_guid(RRDHOST *host, const char *machine_guid) {
strncpy(host->machine_guid, machine_guid, GUID_LEN);
host->machine_guid[GUID_LEN] = '\0';
@@ -100,6 +109,7 @@ RRDHOST *rrdhost_create(const char *hostname,
const char *registry_hostname,
const char *guid,
const char *os,
+ const char *timezone,
const char *tags,
int update_every,
long entries,
@@ -120,33 +130,34 @@ RRDHOST *rrdhost_create(const char *hostname,
host->rrd_history_entries = align_entries_to_pagesize(memory_mode, entries);
host->rrd_memory_mode = memory_mode;
host->health_enabled = (memory_mode == RRD_MEMORY_MODE_NONE)? 0 : health_enabled;
- host->rrdpush_enabled = (rrdpush_enabled && rrdpush_destination && *rrdpush_destination && rrdpush_api_key && *rrdpush_api_key);
- host->rrdpush_destination = (host->rrdpush_enabled)?strdupz(rrdpush_destination):NULL;
- host->rrdpush_api_key = (host->rrdpush_enabled)?strdupz(rrdpush_api_key):NULL;
+ host->rrdpush_send_enabled = (rrdpush_enabled && rrdpush_destination && *rrdpush_destination && rrdpush_api_key && *rrdpush_api_key);
+ host->rrdpush_send_destination = (host->rrdpush_send_enabled)?strdupz(rrdpush_destination):NULL;
+ host->rrdpush_send_api_key = (host->rrdpush_send_enabled)?strdupz(rrdpush_api_key):NULL;
- host->rrdpush_pipe[0] = -1;
- host->rrdpush_pipe[1] = -1;
- host->rrdpush_socket = -1;
+ host->rrdpush_sender_pipe[0] = -1;
+ host->rrdpush_sender_pipe[1] = -1;
+ host->rrdpush_sender_socket = -1;
- netdata_mutex_init(&host->rrdpush_mutex);
+ netdata_mutex_init(&host->rrdpush_sender_buffer_mutex);
netdata_rwlock_init(&host->rrdhost_rwlock);
rrdhost_init_hostname(host, hostname);
rrdhost_init_machine_guid(host, guid);
rrdhost_init_os(host, os);
+ rrdhost_init_timezone(host, timezone);
rrdhost_init_tags(host, tags);
host->registry_hostname = strdupz((registry_hostname && *registry_hostname)?registry_hostname:hostname);
avl_init_lock(&(host->rrdset_root_index), rrdset_compare);
avl_init_lock(&(host->rrdset_root_index_name), rrdset_compare_name);
avl_init_lock(&(host->rrdfamily_root_index), rrdfamily_compare);
- avl_init_lock(&(host->variables_root_index), rrdvar_compare);
+ avl_init_lock(&(host->rrdvar_root_index), rrdvar_compare);
if(config_get_boolean(CONFIG_SECTION_GLOBAL, "delete obsolete charts files", 1))
- rrdhost_flag_set(host, RRDHOST_DELETE_OBSOLETE_CHARTS);
+ rrdhost_flag_set(host, RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS);
if(config_get_boolean(CONFIG_SECTION_GLOBAL, "delete orphan hosts files", 1) && !is_localhost)
- rrdhost_flag_set(host, RRDHOST_DELETE_ORPHAN_HOST);
+ rrdhost_flag_set(host, RRDHOST_FLAG_DELETE_ORPHAN_HOST);
// ------------------------------------------------------------------------
@@ -251,7 +262,8 @@ RRDHOST *rrdhost_create(const char *hostname,
}
else {
info("Host '%s' (at registry as '%s') with guid '%s' initialized"
- ", os %s"
+ ", os '%s'"
+ ", timezone '%s'"
", tags '%s'"
", update every %d"
", memory mode %s"
@@ -268,13 +280,14 @@ RRDHOST *rrdhost_create(const char *hostname,
, host->registry_hostname
, host->machine_guid
, host->os
+ , host->timezone
, (host->tags)?host->tags:""
, host->rrd_update_every
, rrd_memory_mode_name(host->rrd_memory_mode)
, host->rrd_history_entries
- , host->rrdpush_enabled?"enabled":"disabled"
- , host->rrdpush_destination?host->rrdpush_destination:""
- , host->rrdpush_api_key?host->rrdpush_api_key:""
+ , host->rrdpush_send_enabled?"enabled":"disabled"
+ , host->rrdpush_send_destination?host->rrdpush_send_destination:""
+ , host->rrdpush_send_api_key?host->rrdpush_send_api_key:""
, host->health_enabled?"enabled":"disabled"
, host->cache_dir
, host->varlib_dir
@@ -294,6 +307,7 @@ RRDHOST *rrdhost_find_or_create(
, const char *registry_hostname
, const char *guid
, const char *os
+ , const char *timezone
, const char *tags
, int update_every
, long history
@@ -313,6 +327,7 @@ RRDHOST *rrdhost_find_or_create(
, registry_hostname
, guid
, os
+ , timezone
, tags
, update_every
, history
@@ -346,16 +361,18 @@ RRDHOST *rrdhost_find_or_create(
// update host tags
rrdhost_init_tags(host, tags);
}
- rrd_unlock();
- rrdhost_cleanup_orphan_hosts(host);
+ rrdhost_cleanup_orphan_hosts_nolock(host);
+
+ rrd_unlock();
return host;
}
-static inline int rrdhost_should_be_removed(RRDHOST *host, RRDHOST *protected, time_t now) {
+inline int rrdhost_should_be_removed(RRDHOST *host, RRDHOST *protected, time_t now) {
if(host != protected
&& host != localhost
+ && rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN)
&& !host->connected_senders
&& host->senders_disconnected_time
&& host->senders_disconnected_time + rrdhost_free_orphan_time < now)
@@ -364,11 +381,9 @@ static inline int rrdhost_should_be_removed(RRDHOST *host, RRDHOST *protected, t
return 0;
}
-void rrdhost_cleanup_orphan_hosts(RRDHOST *protected) {
+void rrdhost_cleanup_orphan_hosts_nolock(RRDHOST *protected) {
time_t now = now_realtime_sec();
- rrd_wrlock();
-
RRDHOST *host;
restart_after_removal:
@@ -376,17 +391,15 @@ restart_after_removal:
if(rrdhost_should_be_removed(host, protected, now)) {
info("Host '%s' with machine guid '%s' is obsolete - cleaning up.", host->hostname, host->machine_guid);
- if(rrdset_flag_check(host, RRDHOST_DELETE_ORPHAN_HOST) && rrdset_flag_check(host, RRDHOST_ORPHAN))
- rrdhost_delete(host);
+ if(rrdhost_flag_check(host, RRDHOST_FLAG_DELETE_ORPHAN_HOST))
+ rrdhost_delete_charts(host);
else
- rrdhost_save(host);
+ rrdhost_save_charts(host);
rrdhost_free(host);
goto restart_after_removal;
}
}
-
- rrd_unlock();
}
// ----------------------------------------------------------------------------
@@ -406,6 +419,7 @@ void rrd_init(char *hostname) {
, registry_get_this_machine_hostname()
, registry_get_this_machine_guid()
, os_type
+ , netdata_configured_timezone
, config_get(CONFIG_SECTION_BACKEND, "host tags", "")
, default_rrd_update_every
, default_rrd_history_entries
@@ -473,12 +487,19 @@ void rrdhost_free(RRDHOST *host) {
// ------------------------------------------------------------------------
// release its children resources
- while(host->rrdset_root) rrdset_free(host->rrdset_root);
+ while(host->rrdset_root)
+ rrdset_free(host->rrdset_root);
- while(host->alarms) rrdcalc_free(host, host->alarms);
- while(host->templates) rrdcalctemplate_free(host, host->templates);
- health_alarm_log_free(host);
+ while(host->alarms)
+ rrdcalc_unlink_and_free(host, host->alarms);
+ while(host->templates)
+ rrdcalctemplate_unlink_and_free(host, host->templates);
+
+ debug(D_RRD_CALLS, "RRDHOST: Cleaning up remaining host variables for host '%s'", host->hostname);
+ rrdvar_free_remaining_variables(host, &host->rrdvar_root_index);
+
+ health_alarm_log_free(host);
// ------------------------------------------------------------------------
// remove it from the indexes
@@ -508,10 +529,11 @@ void rrdhost_free(RRDHOST *host) {
freez((void *)host->tags);
freez((void *)host->os);
+ freez((void *)host->timezone);
freez(host->cache_dir);
freez(host->varlib_dir);
- freez(host->rrdpush_api_key);
- freez(host->rrdpush_destination);
+ freez(host->rrdpush_send_api_key);
+ freez(host->rrdpush_send_destination);
freez(host->health_default_exec);
freez(host->health_default_recipient);
freez(host->health_log_filename);
@@ -534,7 +556,7 @@ void rrdhost_free_all(void) {
// ----------------------------------------------------------------------------
// RRDHOST - save host files
-void rrdhost_save(RRDHOST *host) {
+void rrdhost_save_charts(RRDHOST *host) {
if(!host) return;
info("Saving/Closing database of host '%s'...", host->hostname);
@@ -557,7 +579,7 @@ void rrdhost_save(RRDHOST *host) {
// ----------------------------------------------------------------------------
// RRDHOST - delete host files
-void rrdhost_delete(RRDHOST *host) {
+void rrdhost_delete_charts(RRDHOST *host) {
if(!host) return;
info("Deleting database of host '%s'...", host->hostname);
@@ -582,12 +604,13 @@ void rrdhost_delete(RRDHOST *host) {
// ----------------------------------------------------------------------------
// RRDHOST - cleanup host files
-void rrdhost_cleanup(RRDHOST *host) {
+void rrdhost_cleanup_charts(RRDHOST *host) {
if(!host) return;
info("Cleaning up database of host '%s'...", host->hostname);
RRDSET *st;
+ uint32_t rrdhost_delete_obsolete_charts = rrdhost_flag_check(host, RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS);
// we get a write lock
// to ensure only one thread is saving the database
@@ -596,7 +619,7 @@ void rrdhost_cleanup(RRDHOST *host) {
rrdset_foreach_write(st, host) {
rrdset_rdlock(st);
- if(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE) && rrdhost_flag_check(host, RRDHOST_DELETE_OBSOLETE_CHARTS))
+ if(rrdhost_delete_obsolete_charts && rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE))
rrdset_delete(st);
else
rrdset_save(st);
@@ -618,7 +641,7 @@ void rrdhost_save_all(void) {
RRDHOST *host;
rrdhost_foreach_read(host)
- rrdhost_save(host);
+ rrdhost_save_charts(host);
rrd_unlock();
}
@@ -633,10 +656,10 @@ void rrdhost_cleanup_all(void) {
RRDHOST *host;
rrdhost_foreach_read(host) {
- if(host != localhost && rrdhost_flag_check(host, RRDHOST_DELETE_OBSOLETE_CHARTS) && !host->connected_senders)
- rrdhost_delete(host);
+ if(host != localhost && rrdhost_flag_check(host, RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS) && !host->connected_senders)
+ rrdhost_delete_charts(host);
else
- rrdhost_cleanup(host);
+ rrdhost_cleanup_charts(host);
}
rrd_unlock();
@@ -651,6 +674,8 @@ void rrdhost_cleanup_obsolete_charts(RRDHOST *host) {
RRDSET *st;
+ uint32_t rrdhost_delete_obsolete_charts = rrdhost_flag_check(host, RRDHOST_FLAG_DELETE_OBSOLETE_CHARTS);
+
restart_after_removal:
rrdset_foreach_write(st, host) {
if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_OBSOLETE)
@@ -661,7 +686,7 @@ restart_after_removal:
rrdset_rdlock(st);
- if(rrdhost_flag_check(host, RRDHOST_DELETE_OBSOLETE_CHARTS))
+ if(rrdhost_delete_obsolete_charts)
rrdset_delete(st);
else
rrdset_save(st);