• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

esl / MongooseIM / 16499779126

24 Jul 2025 02:03PM UTC coverage: 85.593% (-0.02%) from 85.614%
16499779126

Pull #4549

github

jacekwegr
Add TODO comments
Pull Request #4549: Support Erlang 28

50 of 68 new or added lines in 5 files covered. (73.53%)

289 existing lines in 7 files now uncovered.

28945 of 33817 relevant lines covered (85.59%)

51736.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.18
/src/mongoose_system_probes.erl
1
-module(mongoose_system_probes).
2

3
-behaviour(mongoose_instrument_probe).
4

5
%% API
6
-export([start/0, stop/0]).
7

8
%% Behaviour callbacks
9
-export([probe/2]).
10

11
%% API for tests
12
-export([instrumentation/0]).
13

14
-ignore_xref([instrumentation/0]).
15

16
-include("mongoose.hrl").
17

18
-spec start() -> ok.
19
start() ->
20
    mongoose_instrument:set_up(instrumentation()).
1,072✔
21

22
-spec stop() -> ok.
23
stop() ->
24
    mongoose_instrument:tear_down(instrumentation()).
1,072✔
25

26
-spec instrumentation() -> [mongoose_instrument:spec()].
27
instrumentation() ->
28
    [{system_up_time, #{},
2,155✔
29
      #{metrics => gauges([seconds]), probe => #{module => ?MODULE}}},
30
     {system_tcp_ports, #{},
31
      #{metrics => gauges([count]), probe => #{module => ?MODULE}}},
32
     {system_process_queue_lengths, #{},
33
      #{metrics => gauges([total]), probe => #{module => ?MODULE}}},
34
     {system_info, #{},
35
      #{metrics => gauges(system_info_metrics()), probe => #{module => ?MODULE}}},
36
     {system_memory, #{},
37
      #{metrics => gauges(proplists:get_keys(erlang:memory())), probe => #{module => ?MODULE}}},
38
     {system_dist_data, #{},
39
      #{metrics => gauges([connections | inet_stats()]), probe => #{module => ?MODULE}}} |
40
     mongoose_internal_databases:instrumentation()].
41

42
-spec probe(mongoose_instrument:event_name(), mongoose_instrument:labels()) ->
43
          mongoose_instrument:measurements().
44
probe(system_up_time, #{}) ->
45
    #{seconds => up_time()};
2,414✔
46
probe(system_tcp_ports, #{}) ->
47
    #{count => count_tcp_ports()};
2,403✔
48
probe(system_process_queue_lengths, #{}) ->
49
    #{total => total_process_queue_length()};
2,403✔
50
probe(system_info, #{}) ->
51
    maps:from_list([{Metric, erlang:system_info(Metric)} || Metric <- system_info_metrics()]);
2,404✔
52
probe(system_memory, #{}) ->
53
    maps:from_list(erlang:memory());
2,404✔
54
probe(system_dist_data, #{}) ->
55
    dist_data_stats().
2,412✔
56

57
-spec up_time() -> non_neg_integer().
58
up_time() ->
59
    {UpTime, _} = erlang:statistics(wall_clock),
2,414✔
60
    UpTime div timer:seconds(1).
2,414✔
61

62
-spec count_tcp_ports() -> non_neg_integer().
63
count_tcp_ports() ->
64
    length([Port || Port <- erlang:ports(), erlang:port_info(Port, name) =:= {name, "tcp_inet"}]).
2,403✔
65

66
-spec total_process_queue_length() -> non_neg_integer().
67
total_process_queue_length() ->
68
    lists:foldl(fun(Pid, TotalLen) ->
2,403✔
69
                        case erlang:process_info(Pid, message_queue_len) of
4,941,230✔
70
                            {message_queue_len, Len} -> TotalLen + Len;
4,938,466✔
71
                            _ -> TotalLen
2,764✔
72
                        end
73
                end, 0, erlang:processes()).
74

75
-spec system_info_metrics() -> [mongoose_instrument:metric_name()].
76
system_info_metrics() ->
77
    [port_count, port_limit, process_count, process_limit, ets_count, ets_limit].
4,559✔
78

79
-spec dist_data_stats() -> mongoose_instrument:measurements().
80
dist_data_stats() ->
81
    DistCtrl = erlang:system_info(dist_ctrl),
2,412✔
82
    Stats = lists:foldl(fun try_get_dist_inet_stats/2, #{}, DistCtrl),
2,412✔
83
    Stats#{connections => length(DistCtrl)}.
2,412✔
84

85
-spec try_get_dist_inet_stats({node(), pid() | port()}, mongoose_instrument:measurements()) ->
86
          mongoose_instrument:measurements().
87
try_get_dist_inet_stats({_Node, PortOrPid}, StatsIn) ->
88
    try dist_inet_stats(PortOrPid) of
9,399✔
89
        PidStats ->
90
            maps:merge_with(fun merge_stat/3, StatsIn, maps:from_list(PidStats))
9,399✔
91
    catch C:R:S ->
92
            ?LOG_INFO(#{what => dist_inet_stats_failed, class => C, reason => R, stacktrace => S}),
×
93
            StatsIn
×
94
    end.
95

96
-spec dist_inet_stats(pid() | port()) -> [{mongoose_instrument:metric_name(), non_neg_integer()}].
97
dist_inet_stats(Pid) when is_pid(Pid) ->
98
    {status, _Pid, _Mod, RawInfo} = sys:get_status(Pid),
703✔
99
    case find_port(RawInfo) of
703✔
100
        {ok, Port} ->
101
            inet_stats(Port);
703✔
102
        not_found ->
NEW
103
            []
×
104
    end;
105
dist_inet_stats(Port) ->
106
    inet_stats(Port).
8,696✔
107

108
-spec inet_stats(port()) -> [{mongoose_instrument:metric_name(), non_neg_integer()}].
109
inet_stats(Port) ->
110
    {ok, Stats} = inet:getstat(Port, inet_stats()),
9,399✔
111
    Stats.
9,399✔
112

113
-spec inet_stats() -> [mongoose_instrument:metric_name()].
114
inet_stats() ->
115
    [recv_oct, recv_cnt, recv_max, send_oct, send_cnt, send_max, send_pend].
11,554✔
116

117
-spec find_port(term()) -> {ok, port()} | not_found.
118
find_port([Tag, _, _, Port | _]) when (Tag == env orelse Tag == static),
119
                                      is_port(Port) ->
120
    {ok, Port};
703✔
121
find_port(Tuple) when is_tuple(Tuple) ->
122
    find_port(tuple_to_list(Tuple));
15,466✔
123
find_port([]) ->
124
    not_found;
2,109✔
125
find_port([H | _] = List) when is_list(List), is_integer(H) ->
126
    not_found;
6,327✔
127
find_port(List) when is_list(List) ->
128
    lists:foldl(fun fold_find_port/2, not_found, List);
18,981✔
129
find_port(_) ->
130
    not_found.
21,793✔
131

132
-spec fold_find_port(term(), {ok, port()} | not_found) -> {ok, port()} | not_found.
133
fold_find_port(_, {ok, _} = Found) ->
134
    Found;
1,406✔
135
fold_find_port(Elem, not_found) ->
136
    find_port(Elem).
49,210✔
137

138
-spec merge_stat(mongoose_instrument:metric_name(), non_neg_integer(), non_neg_integer()) ->
139
          non_neg_integer().
140
merge_stat(recv_max, V1, V2) ->
141
    max(V1, V2);
6,987✔
142
merge_stat(send_max, V1, V2) ->
143
    max(V1, V2);
6,987✔
144
merge_stat(_, V1, V2) ->
145
    V1 + V2.
34,935✔
146

147
-spec gauges([mongoose_instrument:metric_name()]) -> mongoose_instrument:metrics().
148
gauges(Keys) ->
149
    maps:from_keys(Keys, gauge).
12,930✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc