summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2021-07-07 13:23:45 +0300
committerGitHub <noreply@github.com>2021-07-07 13:23:45 +0300
commit59394b5f9d8891cb59c42ac87fd8f0d41b28db94 (patch)
treef600bc11081534e8fc5188843a1bb16b9124ff7e
parentcd7eafaf34bcfa1c75e6ad8562330912f9136f2c (diff)
Add hop count for children (#11311)
-rw-r--r--daemon/main.c1
-rw-r--r--database/rrd.h1
-rw-r--r--streaming/rrdpush.c4
-rw-r--r--streaming/sender.c3
-rw-r--r--web/api/web_api_v1.c4
5 files changed, 9 insertions, 4 deletions
diff --git a/daemon/main.c b/daemon/main.c
index e040d70b3b..c0ba3cb105 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -1230,6 +1230,7 @@ int main(int argc, char **argv) {
netdata_anonymous_statistics_enabled=-1;
struct rrdhost_system_info *system_info = calloc(1, sizeof(struct rrdhost_system_info));
get_system_info(system_info);
+ system_info->hops = 0;
if(rrd_init(netdata_configured_hostname, system_info))
fatal("Cannot initialize localhost instance with name '%s'.", netdata_configured_hostname);
diff --git a/database/rrd.h b/database/rrd.h
index 6179ec5574..5ea26caafe 100644
--- a/database/rrd.h
+++ b/database/rrd.h
@@ -740,6 +740,7 @@ struct rrdhost_system_info {
char *container;
char *container_detection;
char *is_k8s_node;
+ uint16_t hops;
};
struct rrdhost {
diff --git a/streaming/rrdpush.c b/streaming/rrdpush.c
index 854336e118..038383b55b 100644
--- a/streaming/rrdpush.c
+++ b/streaming/rrdpush.c
@@ -471,7 +471,7 @@ int rrdpush_receiver_thread_spawn(struct web_client *w, char *url) {
char buf[GUID_LEN + 1];
struct rrdhost_system_info *system_info = callocz(1, sizeof(struct rrdhost_system_info));
-
+ system_info->hops = 1;
while(url) {
char *value = mystrsep(&url, "&");
if(!value || !*value) continue;
@@ -498,6 +498,8 @@ int rrdpush_receiver_thread_spawn(struct web_client *w, char *url) {
abbrev_timezone = value;
else if(!strcmp(name, "utc_offset"))
utc_offset = (int32_t)strtol(value, NULL, 0);
+ else if(!strcmp(name, "hops"))
+ system_info->hops = (uint16_t) strtoul(value, NULL, 0);
else if(!strcmp(name, "tags"))
tags = value;
else if(!strcmp(name, "ver"))
diff --git a/streaming/sender.c b/streaming/sender.c
index d25001d355..60cf3f2445 100644
--- a/streaming/sender.c
+++ b/streaming/sender.c
@@ -214,7 +214,7 @@ static int rrdpush_sender_thread_connect_to_parent(RRDHOST *host, int default_po
char http[HTTP_HEADER_SIZE + 1];
int eol = snprintfz(http, HTTP_HEADER_SIZE,
- "STREAM key=%s&hostname=%s&registry_hostname=%s&machine_guid=%s&update_every=%d&os=%s&timezone=%s&abbrev_timezone=%s&utc_offset=%d&tags=%s&ver=%u"
+ "STREAM key=%s&hostname=%s&registry_hostname=%s&machine_guid=%s&update_every=%d&os=%s&timezone=%s&abbrev_timezone=%s&utc_offset=%d&hops=%d&tags=%s&ver=%u"
"&NETDATA_SYSTEM_OS_NAME=%s"
"&NETDATA_SYSTEM_OS_ID=%s"
"&NETDATA_SYSTEM_OS_ID_LIKE=%s"
@@ -252,6 +252,7 @@ static int rrdpush_sender_thread_connect_to_parent(RRDHOST *host, int default_po
, host->timezone
, host->abbrev_timezone
, host->utc_offset
+ , host->system_info->hops + 1
, (host->tags) ? host->tags : ""
, STREAMING_PROTOCOL_CURRENT_VERSION
, se.os_name
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c
index c58a86af0f..f0a3ea146c 100644
--- a/web/api/web_api_v1.c
+++ b/web/api/web_api_v1.c
@@ -867,8 +867,8 @@ static inline void web_client_api_request_v1_info_mirrored_hosts(BUFFER *wb) {
netdata_mutex_lock(&host->receiver_lock);
buffer_sprintf(
- wb, "\t\t{ \"guid\": \"%s\", \"reachable\": %s, \"claim_id\": ", host->machine_guid,
- (host->receiver || host == localhost) ? "true" : "false");
+ wb, "\t\t{ \"guid\": \"%s\", \"reachable\": %s, \"hops\": %d, \"claim_id\": ", host->machine_guid,
+ (host->receiver || host == localhost) ? "true" : "false", host->system_info ? host->system_info->hops : (host == localhost) ? 0 : 1);
netdata_mutex_unlock(&host->receiver_lock);
rrdhost_aclk_state_lock(host);