@cryptotaxi247 / netdata-1 / commits / 68c2da451

external plugins can now work for a specific host

Costa Tsaousis (ktsaou) committed Feb 18, 2017 at 13:38 UTC 68c2da451261559ce966935a6087d51a6d8460c4
4 files changed +45 -5
src/plugins_d.c
+20 -1
@@ -206,6 +206,25 @@ void *pluginsd_worker_thread(void *arg) {
206
207 count++;
208 }
209 + else if(likely(hash == HOST_HASH && !strcmp(s, "HOST"))) {
210 + char *guid = words[1];
211 + char *hostname = words[2];
212 +
213 + if(unlikely(!guid || !*guid)) {
214 + error("PLUGINSD: '%s' is requesting a HOST, without a guid. Disabling it.", cd->fullfilename);
215 + cd->enabled = 0;
216 + killpid(cd->pid, SIGTERM);
217 + break;
218 + }
219 + if(unlikely(!hostname || !*hostname)) {
220 + error("PLUGINSD: '%s' is requesting a HOST, without a hostname. Disabling it.", cd->fullfilename);
221 + cd->enabled = 0;
222 + killpid(cd->pid, SIGTERM);
223 + break;
224 + }
225 +
226 + host = rrdhost_find_or_create(hostname, guid);
227 + }
228 else if(likely(hash == FLUSH_HASH && !strcmp(s, "FLUSH"))) {
229 debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a FLUSH", cd->fullfilename);
230 st = NULL;
@@ -246,7 +265,7 @@ void *pluginsd_worker_thread(void *arg) {
265 if(likely(update_every_s)) update_every = str2i(update_every_s);
266 if(unlikely(!update_every)) update_every = cd->update_every;
267
249 - int chart_type = RRDSET_TYPE_LINE;
268 + RRDSET_TYPE chart_type = RRDSET_TYPE_LINE;
269 if(unlikely(chart)) chart_type = rrdset_type_id(chart);
270
271 if(unlikely(noname || !name || !*name || strcasecmp(name, "NULL") == 0 || strcasecmp(name, "(NULL)") == 0)) name = NULL;
src/plugins_d.h
+1 -1
@@ -11,7 +11,7 @@ struct plugind {
11
12 char filename[FILENAME_MAX+1]; // just the filename
13 char fullfilename[FILENAME_MAX+1]; // with path
14 - char cmd[PLUGINSD_CMD_MAX+1]; // the command that is executes
14 + char cmd[PLUGINSD_CMD_MAX+1]; // the command that it executes
15
16 pid_t pid;
17 pthread_t thread;
src/rrd.h
+1
@@ -335,6 +335,7 @@ extern RRDHOST *localhost;
335 extern void rrd_init(char *hostname);
336
337 extern RRDHOST *rrdhost_find(const char *guid, uint32_t hash);
338 +extern RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid);
339
340 #ifdef NETDATA_INTERNAL_CHECKS
341 #define rrdhost_check_wrlock(host) rrdhost_check_wrlock_int(host, __FILE__, __FUNCTION__, __LINE__)
src/rrdhost.c
+23 -3
@@ -16,6 +16,8 @@ avl_tree_lock rrdhost_root_index = {
16 };
17
18 RRDHOST *rrdhost_find(const char *guid, uint32_t hash) {
19 + debug(D_RRDHOST, "Searching in index for host with guid '%s'", guid);
20 +
21 RRDHOST tmp;
22 strncpyz(tmp.machine_guid, guid, GUID_LEN);
23 tmp.hash_machine_guid = (hash)?hash:simple_hash(tmp.machine_guid);
@@ -46,6 +48,8 @@ static inline void rrdhost_init_machine_guid(RRDHOST *host, const char *machine_
48 // RRDHOST - add a host
49
50 RRDHOST *rrdhost_create(const char *hostname, const char *guid) {
51 + debug(D_RRDHOST, "Adding host '%s' with guid '%s'", hostname, guid);
52 +
53 RRDHOST *host = callocz(1, sizeof(RRDHOST));
54
55 pthread_rwlock_init(&(host->rrdset_root_rwlock), NULL);
@@ -68,7 +72,17 @@ RRDHOST *rrdhost_create(const char *hostname, const char *guid) {
72 if(rrdhost_index_add(host) != host)
73 fatal("Cannot add host '%s' to index. It already exists.", hostname);
74
71 - debug(D_RRDHOST, "Added host '%s'", host->hostname);
75 + debug(D_RRDHOST, "Added host '%s' with guid '%s'", host->hostname, host->machine_guid);
76 + return host;
77 +}
78 +
79 +RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid) {
80 + debug(D_RRDHOST, "Searching for host '%s' with guid '%s'", hostname, guid);
81 +
82 + RRDHOST *host = rrdhost_find(guid, 0);
83 + if(!host)
84 + host = rrdhost_create(hostname, guid);
85 +
86 return host;
87 }
88
@@ -78,6 +92,7 @@ RRDHOST *rrdhost_create(const char *hostname, const char *guid) {
92 RRDHOST *localhost = NULL;
93
94 void rrd_init(char *hostname) {
95 + debug(D_RRDHOST, "Initializing localhost with hostname '%s'", hostname);
96 localhost = rrdhost_create(hostname, registry_get_this_machine_guid());
97 }
98
@@ -85,27 +100,32 @@ void rrd_init(char *hostname) {
100 // RRDHOST - locks
101
102 void rrdhost_rwlock(RRDHOST *host) {
103 + debug(D_RRDHOST, "Write lock host '%s'", host->hostname);
104 pthread_rwlock_wrlock(&host->rrdset_root_rwlock);
105 }
106
107 void rrdhost_rdlock(RRDHOST *host) {
108 + debug(D_RRDHOST, "Read lock host '%s'", host->hostname);
109 pthread_rwlock_rdlock(&host->rrdset_root_rwlock);
110 }
111
112 void rrdhost_unlock(RRDHOST *host) {
113 + debug(D_RRDHOST, "Unlock host '%s'", host->hostname);
114 pthread_rwlock_unlock(&host->rrdset_root_rwlock);
115 }
116
117 void rrdhost_check_rdlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line) {
100 - int ret = pthread_rwlock_trywrlock(&host->rrdset_root_rwlock);
118 + debug(D_RRDHOST, "Read lock host '%s'", host->hostname);
119
120 + int ret = pthread_rwlock_trywrlock(&host->rrdset_root_rwlock);
121 if(ret == 0)
122 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);
123 }
124
125 void rrdhost_check_wrlock_int(RRDHOST *host, const char *file, const char *function, const unsigned long line) {
107 - int ret = pthread_rwlock_tryrdlock(&host->rrdset_root_rwlock);
126 + debug(D_RRDHOST, "Write lock host '%s'", host->hostname);
127
128 + int ret = pthread_rwlock_tryrdlock(&host->rrdset_root_rwlock);
129 if(ret == 0)
130 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);
131 }