master
c 58 lines 2.18 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "stream-replication-tracking.h"
4 #include "database/rrd.h"
5 #include "stream-receiver-internals.h"
6
7 #ifdef REPLICATION_TRACKING
8
9 void replication_tracking_counters(struct rrdhost *host, struct replay_who_counters *c) {
10 if(!rrdhost_flag_check(host, RRDHOST_FLAG_COLLECTOR_ONLINE))
11 return;
12
13 bool is_host_local = host == localhost || rrdhost_option_check(host, RRDHOST_OPTION_VIRTUAL_HOST);
14 bool is_host_sending = rrdhost_flag_check(host, RRDHOST_FLAG_STREAM_SENDER_READY_4_METRICS);
15
16 RRDSET *st;
17 rrdset_foreach_read(st, host) {
18 RRDSET_FLAGS st_flags = rrdset_flag_get(st);
19
20 if(st_flags & RRDSET_FLAG_OBSOLETE)
21 continue;
22
23 if(!is_host_local && !(st_flags & RRDSET_FLAG_ANOMALY_DETECTION)) {
24 REPLAY_WHO rcv = st->stream.rcv.who;
25 if (rcv <= 0 || rcv >= REPLAY_WHO_MAX)
26 rcv = REPLAY_WHO_UNKNOWN;
27 c->rcv[rcv]++;
28
29 #ifdef NETDATA_LOG_STREAM_RECEIVER
30 if(rcv == REPLAY_WHO_ME || rcv == REPLAY_WHO_THEM) {
31 char buf[1024];
32 snprintfz(buf, sizeof(buf), "### REPLICATION RECEIVE waits on %s for chart '%s'\n",
33 rcv == REPLAY_WHO_ME ? "me" : "them", rrdset_id(st));
34 stream_receiver_log_payload(host->receiver, buf, STREAM_TRAFFIC_TYPE_METADATA, rcv == REPLAY_WHO_THEM);
35 }
36 #endif
37 }
38
39 if(is_host_sending && (st_flags & RRDSET_FLAG_UPSTREAM_SEND) && !(st_flags & RRDSET_FLAG_UPSTREAM_IGNORE)) {
40 REPLAY_WHO snd = st->stream.snd.who;
41 if (snd <= 0 || snd >= REPLAY_WHO_MAX)
42 snd = REPLAY_WHO_UNKNOWN;
43 c->snd[snd]++;
44
45 #ifdef NETDATA_LOG_STREAM_SENDER
46 if(snd == REPLAY_WHO_ME || snd == REPLAY_WHO_THEM) {
47 char buf[1024];
48 snprintfz(buf, sizeof(buf), "### REPLICATION SEND waits on %s for chart '%s'\n",
49 snd == REPLAY_WHO_ME ? "me" : "them", rrdset_id(st));
50 stream_receiver_log_payload(host->receiver, buf, STREAM_TRAFFIC_TYPE_METADATA, snd == REPLAY_WHO_THEM);
51 }
52 #endif
53 }
54 }
55 rrdset_foreach_done(st);
56 }
57
58 #endif