master
c 54 lines 1.87 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define RRDHOST_INTERNALS
4 #include "rrd.h"
5 #include "rrd-metadata.h"
6 #include "contexts/rrdcontext-context-registry.h"
7
8 // Collect metrics metadata from all hosts
9 RRDSTATS_METADATA rrdstats_metadata_collect(void) {
10 RRDSTATS_METADATA metadata = {
11 .nodes = { .total = 0, .receiving = 0, .sending = 0, .archived = 0 },
12 .metrics = { .collected = 0, .available = 0 },
13 .instances = { .collected = 0, .available = 0 },
14 .contexts = { .collected = 0, .available = 0, .unique = 0 }
15 };
16
17 rrd_rdlock();
18
19 if(!rrdhost_root_index) {
20 rrd_rdunlock();
21 return metadata;
22 }
23
24 RRDHOST *host;
25 dfe_start_read(rrdhost_root_index, host) {
26 metadata.nodes.total++;
27
28 metadata.metrics.available += __atomic_load_n(&host->rrdctx.metrics_count, __ATOMIC_RELAXED);
29 metadata.instances.available += __atomic_load_n(&host->rrdctx.instances_count, __ATOMIC_RELAXED);
30 metadata.contexts.available += __atomic_load_n(&host->rrdctx.contexts_count, __ATOMIC_RELAXED);
31
32 if(rrdhost_flag_check(host, RRDHOST_FLAG_STREAM_SENDER_CONNECTED))
33 metadata.nodes.sending++;
34
35 if (rrdhost_is_online(host)) {
36 metadata.metrics.collected += __atomic_load_n(&host->collected.metrics_count, __ATOMIC_RELAXED);
37 metadata.instances.collected += __atomic_load_n(&host->collected.instances_count, __ATOMIC_RELAXED);
38 metadata.contexts.collected += __atomic_load_n(&host->collected.contexts_count, __ATOMIC_RELAXED);
39
40 if(host != localhost)
41 metadata.nodes.receiving++;
42 }
43 else
44 metadata.nodes.archived++;
45 }
46 dfe_done(host);
47
48 rrd_rdunlock();
49
50 // Get the count of unique contexts from our registry
51 metadata.contexts.unique = rrdcontext_context_registry_unique_count();
52
53 return metadata;
54 }