1 |
|
-module(mongoose_metrics_probe_cets). |
2 |
|
-behaviour(mongoose_metrics_probe). |
3 |
|
-include("mongoose_logger.hrl"). |
4 |
|
|
5 |
|
%% Init the metrics |
6 |
|
-export([start/0]). |
7 |
|
|
8 |
|
%% Probe callbacks |
9 |
|
-export([sample/0, datapoints/0]). |
10 |
|
|
11 |
|
%% GraphQL helper |
12 |
|
-export([format_probe_cets/1]). |
13 |
|
|
14 |
|
start() -> |
15 |
6 |
Interval = mongoose_metrics:get_report_interval(), |
16 |
6 |
M = [{callback_module, ?MODULE}, |
17 |
|
{sample_interval, Interval}], |
18 |
6 |
mongoose_metrics:ensure_metric(global, [cets, system], {probe, M}), |
19 |
6 |
ok. |
20 |
|
|
21 |
|
format_probe_cets(#{available_nodes := AvNodes, |
22 |
|
unavailable_nodes := UnNodes, |
23 |
|
joined_nodes := Joined, |
24 |
|
discovered_nodes := DiscoNodes, |
25 |
|
discovery_works := DiscoveryWorks, |
26 |
|
remote_nodes_without_disco := NoDisco, |
27 |
|
remote_nodes_with_unknown_tables := UnkNodes, |
28 |
|
remote_unknown_tables := UnkTabs, |
29 |
|
remote_nodes_with_missing_tables := MissNodes, |
30 |
|
remote_missing_tables := MissTabs, |
31 |
|
conflict_nodes := ConNodes, |
32 |
|
conflict_tables := ConTabs}) -> |
33 |
:-( |
#{<<"type">> => <<"cets_system">>, |
34 |
|
<<"available_nodes">> => AvNodes, |
35 |
|
<<"unavailable_nodes">> => UnNodes, |
36 |
|
<<"joined_nodes">> => Joined, |
37 |
|
<<"discovered_nodes">> => DiscoNodes, |
38 |
|
<<"discovery_works">> => DiscoveryWorks, |
39 |
|
<<"remote_nodes_without_disco">> => NoDisco, |
40 |
|
<<"remote_nodes_with_unknown_tables">> => UnkNodes, |
41 |
|
<<"remote_unknown_tables">> => UnkTabs, |
42 |
|
<<"remote_nodes_with_missing_tables">> => MissNodes, |
43 |
|
<<"remote_missing_tables">> => MissTabs, |
44 |
|
<<"conflict_nodes">> => ConNodes, |
45 |
|
<<"conflict_tables">> => ConTabs}. |
46 |
|
|
47 |
|
all_zeros() -> |
48 |
:-( |
#{<<"available_nodes">> => 0, |
49 |
|
<<"unavailable_nodes">> => 0, |
50 |
|
<<"joined_nodes">> => 0, |
51 |
|
<<"discovered_nodes">> => 0, |
52 |
|
<<"discovery_works">> => 0, |
53 |
|
<<"remote_nodes_without_disco">> => 0, |
54 |
|
<<"remote_nodes_with_unknown_tables">> => 0, |
55 |
|
<<"remote_unknown_tables">> => 0, |
56 |
|
<<"remote_nodes_with_missing_tables">> => 0, |
57 |
|
<<"remote_missing_tables">> => 0, |
58 |
|
<<"conflict_nodes">> => 0, |
59 |
|
<<"conflict_tables">> => 0}. |
60 |
|
|
61 |
|
datapoints() -> |
62 |
:-( |
[available_nodes, |
63 |
|
unavailable_nodes, |
64 |
|
joined_nodes, |
65 |
|
discovered_nodes, |
66 |
|
discovery_works, |
67 |
|
remote_nodes_without_disco, |
68 |
|
remote_nodes_with_unknown_tables, |
69 |
|
remote_unknown_tables, |
70 |
|
remote_nodes_with_missing_tables, |
71 |
|
remote_missing_tables, |
72 |
|
conflict_nodes, |
73 |
|
conflict_tables]. |
74 |
|
|
75 |
|
sample() -> |
76 |
2 |
try cets_status:status(mongoose_cets_discovery) of |
77 |
|
#{available_nodes := AvNodes, |
78 |
|
unavailable_nodes := UnNodes, |
79 |
|
joined_nodes := Joined, |
80 |
|
discovered_nodes := DiscoNodes, |
81 |
|
discovery_works := DiscoveryWorks, |
82 |
|
remote_nodes_without_disco := NoDisco, |
83 |
|
remote_nodes_with_unknown_tables := UnkNodes, |
84 |
|
remote_unknown_tables := UnkTabs, |
85 |
|
remote_nodes_with_missing_tables := MissNodes, |
86 |
|
remote_missing_tables := MissTabs, |
87 |
|
conflict_nodes := ConNodes, |
88 |
|
conflict_tables := ConTabs} -> |
89 |
2 |
#{available_nodes => length(AvNodes), |
90 |
|
unavailable_nodes => length(UnNodes), |
91 |
|
joined_nodes => length(Joined), |
92 |
|
discovered_nodes => length(DiscoNodes), |
93 |
|
discovery_works => boolean_to_integer(DiscoveryWorks), |
94 |
|
remote_nodes_without_disco => length(NoDisco), |
95 |
|
remote_nodes_with_unknown_tables => length(UnkNodes), |
96 |
|
remote_unknown_tables => length(UnkTabs), |
97 |
|
remote_nodes_with_missing_tables => length(MissNodes), |
98 |
|
remote_missing_tables => length(MissTabs), |
99 |
|
conflict_nodes => length(ConNodes), |
100 |
|
conflict_tables => length(ConTabs)} |
101 |
|
catch Class:Reason:Stacktrace -> |
102 |
:-( |
?LOG_ERROR(#{what => cets_system_info_failed, class => Class, |
103 |
:-( |
reason => Reason, stacktrace => Stacktrace}), |
104 |
:-( |
all_zeros() |
105 |
|
end. |
106 |
|
|
107 |
1 |
boolean_to_integer(true) -> 1; |
108 |
1 |
boolean_to_integer(false) -> 0. |