pthread_rwlock_t rrd_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+time_t rrdhost_free_orphan_time = 3600;
// ----------------------------------------------------------------------------
// RRDHOST index
.rwlock = AVL_LOCK_INITIALIZER
};
-RRDHOST *rrdhost_find(const char *guid, uint32_t hash) {
+RRDHOST *rrdhost_find_guid(const char *guid, uint32_t hash) {
debug(D_RRDHOST, "Searching in index for host with guid '%s'", guid);
RRDHOST tmp;
}
else {
info("Host '%s' with guid '%s' initialized"
- ", os: %s"
- ", update every: %d"
- ", memory mode: %s"
- ", history entries: %d"
- ", streaming: %s"
- " to: '%s' (api key: '%s')"
- ", health: %s"
- ", cache_dir: '%s'"
- ", varlib_dir: '%s'"
- ", health_log: '%s'"
- ", alarms default handler: '%s'"
- ", alarms default recipient: '%s'"
+ ", os %s"
+ ", update every %d"
+ ", memory mode %s"
+ ", history entries %d"
+ ", streaming %s"
+ " (to '%s' with api key '%s')"
+ ", health %s"
+ ", cache_dir '%s'"
+ ", varlib_dir '%s'"
+ ", health_log '%s'"
+ ", alarms default handler '%s'"
+ ", alarms default recipient '%s'"
, host->hostname
, host->machine_guid
, host->os
, rrd_memory_mode_name(host->rrd_memory_mode)
, host->rrd_history_entries
, host->rrdpush_enabled?"enabled":"disabled"
- , host->rrdpush_destination
- , host->rrdpush_api_key
+ , host->rrdpush_destination?host->rrdpush_destination:""
+ , host->rrdpush_api_key?host->rrdpush_api_key:""
, host->health_enabled?"enabled":"disabled"
, host->cache_dir
, host->varlib_dir
) {
debug(D_RRDHOST, "Searching for host '%s' with guid '%s'", hostname, guid);
- RRDHOST *host = rrdhost_find(guid, 0);
+ RRDHOST *host = rrdhost_find_guid(guid, 0);
if(!host) {
host = rrdhost_create(
hostname
error("Host '%s' has memory mode '%s', but the wanted one is '%s'.", host->hostname, rrd_memory_mode_name(host->rrd_memory_mode), rrd_memory_mode_name(mode));
}
+ rrdhost_cleanup_remote_stale(host);
+
return host;
}
+void rrdhost_cleanup_remote_stale(RRDHOST *protected) {
+ rrd_wrlock();
+
+ RRDHOST *h;
+ rrdhost_foreach_write(h) {
+ if(h != protected
+ && h != localhost
+ && !h->connected_senders
+ && h->senders_disconnected_time + rrdhost_free_orphan_time > now_realtime_sec()) {
+ info("Host '%s' with machine guid '%s' is obsolete - cleaning up.", h->hostname, h->machine_guid);
+ rrdhost_save(h);
+ rrdhost_free(h);
+ break;
+ }
+ }
+
+ rrd_unlock();
+}
+
// ----------------------------------------------------------------------------
// RRDHOST global / startup initialization
// ------------------------------------------------------------------------
// free it
- if(host->rrdpush_spawn) {
- pthread_cancel(host->rrdpush_thread);
- rrdpush_sender_thread_cleanup(host);
- }
+ rrdpush_sender_thread_stop(host);
freez(host->os);
freez(host->cache_dir);