prevent remote hosts from taking the localhost position
Costa Tsaousis (ktsaou) committed
Feb 24, 2017 at 23:48 UTC
bd94cac548d286105ca436997d50250a4b429ad6
3 files changed
+24
-15
src/main.c
+6
-6
@@ -902,6 +902,12 @@ int main(int argc, char **argv) {
902
}
903
904
905
+ // ------------------------------------------------------------------------
906
+ // initialize rrd host
907
+
908
+ rrd_init(netdata_configured_hostname);
909
+
910
+
911
// --------------------------------------------------------------------
912
// find we need to send data to another netdata
913
@@ -920,12 +926,6 @@ int main(int argc, char **argv) {
926
registry_init();
927
928
923
- // ------------------------------------------------------------------------
924
- // initialize rrd host
925
-
926
- rrd_init(netdata_configured_hostname);
927
-
928
-
929
if(check_config)
930
exit(1);
931
src/rrdhost.c
+17
-8
@@ -64,7 +64,9 @@ RRDHOST *rrdhost_create(const char *hostname,
64
int update_every,
65
int entries,
66
RRD_MEMORY_MODE memory_mode,
67
- int health_enabled) {
67
+ int health_enabled,
68
+ int is_localhost
69
+) {
70
71
debug(D_RRDHOST, "Host '%s': adding with guid '%s'", hostname, guid);
72
@@ -113,8 +115,7 @@ RRDHOST *rrdhost_create(const char *hostname,
115
116
char filename[FILENAME_MAX + 1];
117
116
- if(!localhost) {
117
- // this is localhost
118
+ if(is_localhost) {
119
120
host->cache_dir = strdupz(netdata_configured_cache_dir);
121
host->varlib_dir = strdupz(netdata_configured_varlib_dir);
@@ -174,9 +175,16 @@ RRDHOST *rrdhost_create(const char *hostname,
175
176
rrd_wrlock();
177
177
- if(localhost) {
178
- host->next = localhost->next;
179
- localhost->next = host;
178
+ if(is_localhost) {
179
+ host->next = localhost;
180
+ localhost = host;
181
+ }
182
+ else {
183
+ if(localhost) {
184
+ host->next = localhost->next;
185
+ localhost->next = host;
186
+ }
187
+ else localhost = host;
188
}
189
190
if(rrdhost_index_add(host) != host)
@@ -193,7 +201,7 @@ RRDHOST *rrdhost_find_or_create(const char *hostname, const char *guid, const ch
201
202
RRDHOST *host = rrdhost_find(guid, 0);
203
if(!host) {
196
- host = rrdhost_create(hostname, guid, os, update_every, history, mode, health_enabled);
204
+ host = rrdhost_create(hostname, guid, os, update_every, history, mode, health_enabled, 0);
205
}
206
else {
207
host->health_enabled = health_enabled;
@@ -230,7 +238,8 @@ void rrd_init(char *hostname) {
238
default_rrd_update_every,
239
default_rrd_history_entries,
240
default_rrd_memory_mode,
233
- default_health_enabled
241
+ default_health_enabled,
242
+ 1
243
);
244
}
245
src/rrdpush.c
+1
-1
@@ -571,7 +571,7 @@ void rrdpush_sender_thread_spawn(RRDHOST *host) {
571
572
int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url) {
573
(void)host;
574
-
574
+
575
info("STREAM [receive from [%s]:%s]: new client connection.", w->client_ip, w->client_port);
576
577
char *key = NULL, *hostname = NULL, *machine_guid = NULL, *os = NULL;