count++;
}
+ else if(likely(hash == HOST_HASH && !strcmp(s, "HOST"))) {
+ char *guid = words[1];
+ char *hostname = words[2];
+
+ if(unlikely(!guid || !*guid)) {
+ error("PLUGINSD: '%s' is requesting a HOST, without a guid. Disabling it.", cd->fullfilename);
+ cd->enabled = 0;
+ killpid(cd->pid, SIGTERM);
+ break;
+ }
+ if(unlikely(!hostname || !*hostname)) {
+ error("PLUGINSD: '%s' is requesting a HOST, without a hostname. Disabling it.", cd->fullfilename);
+ cd->enabled = 0;
+ killpid(cd->pid, SIGTERM);
+ break;
+ }
+
+ host = rrdhost_find_or_create(hostname, guid);
+ }
else if(likely(hash == FLUSH_HASH && !strcmp(s, "FLUSH"))) {
debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a FLUSH", cd->fullfilename);
st = NULL;
if(likely(update_every_s)) update_every = str2i(update_every_s);
if(unlikely(!update_every)) update_every = cd->update_every;
- int chart_type = RRDSET_TYPE_LINE;
+ RRDSET_TYPE chart_type = RRDSET_TYPE_LINE;
if(unlikely(chart)) chart_type = rrdset_type_id(chart);
if(unlikely(noname || !name || !*name || strcasecmp(name, "NULL") == 0 || strcasecmp(name, "(NULL)") == 0)) name = NULL;
};
RRDHOST *rrdhost_find(const char *guid, uint32_t hash) {
+ debug(D_RRDHOST, "Searching in index for host with guid '%s'", guid);
+
RRDHOST tmp;
strncpyz(tmp.machine_guid, guid, GUID_LEN);
tmp.hash_machine_guid = (hash)?hash:simple_hash(tmp.machine_guid);
// RRDHOST - add a host
RRDHOST *rrdhost_create(const char *hostname, const char *guid) {
+ debug(D_RRDHOST, "Adding host '%s' with guid '%s'", hostname, guid);
+
RRDHOST *host = callocz(1, sizeof(RRDHOST));
pthread_rwlock_init(&(host->rrdset_root_rwlock), NULL);
if(rrdhost_index_add(host) != host)
fatal("Cannot add host '%s' to index. It already exists.", hostname);
- debug(D_RRDHOST, "Added host '%s'", host->hostname);
+ debug(D_RRDHOST, "Added host '%s' with guid '%s'", host->hostname, host->machine_guid);
+ return host;
+}
+
+RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid) {
+ debug(D_RRDHOST, "Searching for host '%s' with guid '%s'", hostname, guid);
+
+ RRDHOST *host = rrdhost_find(guid, 0);
+ if(!host)
+ host = rrdhost_create(hostname, guid);
+
return host;
}
RRDHOST *localhost = NULL;
void rrd_init(char *hostname) {
+ debug(D_RRDHOST, "Initializing localhost with hostname '%s'", hostname);
localhost = rrdhost_create(hostname, registry_get_this_machine_guid());
}
// RRDHOST - locks
void rrdhost_rwlock(RRDHOST *host) {
+ debug(D_RRDHOST, "Write lock host '%s'", host->hostname);
pthread_rwlock_wrlock(&host->rrdset_root_rwlock);
}
void rrdhost_rdlock(RRDHOST *host) {
+ debug(D_RRDHOST, "Read lock host '%s'", host->hostname);
pthread_rwlock_rdlock(&host->rrdset_root_rwlock);
}
void rrdhost_unlock(RRDHOST *host) {
+ debug(D_RRDHOST, "Unlock host '%s'", host->hostname);
pthread_rwlock_unlock(&host->rrdset_root_rwlock);
}
void rrdhost_check_rdlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line) {
- int ret = pthread_rwlock_trywrlock(&host->rrdset_root_rwlock);
+ debug(D_RRDHOST, "Read lock host '%s'", host->hostname);
+ int ret = pthread_rwlock_trywrlock(&host->rrdset_root_rwlock);
if(ret == 0)
fatal("RRDHOST '%s' should be read-locked, but it is not, at function %s() at line %lu of file '%s'", host->hostname, function, line, file);
}
void rrdhost_check_wrlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line) {
- int ret = pthread_rwlock_tryrdlock(&host->rrdset_root_rwlock);
+ debug(D_RRDHOST, "Write lock host '%s'", host->hostname);
+ int ret = pthread_rwlock_tryrdlock(&host->rrdset_root_rwlock);
if(ret == 0)
fatal("RRDHOST '%s' should be write-locked, but it is not, at function %s() at line %lu of file '%s'", host->hostname, function, line, file);
}