Skip to content

Commit aaa6fb4

Browse files
authored
Add node_queue_size metric to dist collector (#94)
Add node_queue_size_bytes metric to dist collector. erlang/otp#2270 is available since Erlang/OTP 22.1, released 17th of September 2019, time to ship this feature 🚢 Thanks @essen!
1 parent 39c6595 commit aaa6fb4

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ cache:
1111
directories:
1212
- $HOME/.cache/rebar3/
1313
otp_release:
14-
- 20.1
15-
- 20.0
14+
- 21.3
15+
- 22.3
1616
script: "./bin/checks.sh && ./rebar3 as test coveralls send"

doc/prometheus_vm_dist_collector.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ The current state of the distribution link.<br />
128128
The state is represented as a numerical value where `pending=1`,
129129
`up_pending=2` and `up=3`.
130130

131+
* `erlang_vm_dist_node_queue_size_bytes`<br/>
132+
Type: gauge.<br/>
133+
The number of bytes in the output distribution queue.<br/>
134+
This queue sits between the Erlang code and the port driver.
131135

132136

133137
### <a name="Configuration">Configuration</a> ###
@@ -185,5 +189,6 @@ Available options:
185189

186190
* `node_state` for `erlang_vm_dist_node_state`.
187191

192+
* `node_queue_size_bytes` for `erlang_vm_dist_node_queue_size_bytes`.
188193

189194
By default all metrics are enabled.

src/collectors/vm/prometheus_vm_dist_collector.erl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@
142142
%% The state is represented as a numerical value where `pending=1',
143143
%% `up_pending=2' and `up=3'.
144144
%% </li>
145+
%% <li>
146+
%% `erlang_vm_dist_node_queue_size_bytes'<br/>
147+
%% Type: gauge.<br/>
148+
%% The number of bytes in the output distribution queue.<br/>
149+
%% This queue sits between the Erlang code and the port driver.
150+
%% </li>
145151
%% </ul>
146152
%%
147153
%% ==Configuration==
@@ -223,6 +229,9 @@
223229
%% <li>
224230
%% `node_state' for `erlang_vm_dist_node_state'.
225231
%% </li>
232+
%% <li>
233+
%% `node_queue_size_bytes' for `erlang_vm_dist_node_queue_size_bytes'.
234+
%% </li>
226235
%% </ul>
227236
%%
228237
%% By default all metrics are enabled.
@@ -239,6 +248,8 @@
239248

240249
-behaviour(prometheus_collector).
241250

251+
-dialyzer({nowarn_function, node_queue_size/1}).
252+
242253
%%====================================================================
243254
%% Macros
244255
%%====================================================================
@@ -360,7 +371,11 @@ metrics1() ->
360371
"The current state of the distribution link. "
361372
"The state is represented as a numerical value where `pending=1', "
362373
"`up_pending=2' and `up=3'.",
363-
metric_node_state(Data)}].
374+
metric_node_state(Data)},
375+
{node_queue_size_bytes, gauge,
376+
"The number of bytes in the output distribution queue. "
377+
"This queue sits between the Erlang code and the port driver.",
378+
metric_node_queue_size(Data)}].
364379

365380
enabled_metrics() ->
366381
application:get_env(prometheus, vm_dist_collector_metrics, all).
@@ -482,3 +497,17 @@ metric_node_state(Data) ->
482497
node_state(pending) -> 1;
483498
node_state(up_pending) -> 2;
484499
node_state(up) -> 3.
500+
501+
metric_node_queue_size(Data) ->
502+
[
503+
{[{peer, Node}], node_queue_size(Node)}
504+
|| {Node, _} <- Data].
505+
506+
node_queue_size(Node) ->
507+
ConnId = ets:lookup_element(sys_dist, Node, 3),
508+
{ok, _, _, QueueSize} = erlang:dist_get_stat(ConnId),
509+
case QueueSize of
510+
false -> 0;
511+
true -> -1;
512+
_ -> QueueSize
513+
end.

test/eunit/collectors/vm/prometheus_vm_dist_collector_tests.erl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ test_no_distribution(_) ->
3535
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_proc_message_queue_len")),
3636
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_proc_reductions")),
3737
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_proc_status")),
38-
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_node_state"))
38+
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_node_state")),
39+
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_node_queue_size_bytes"))
3940
].
4041

4142

@@ -81,7 +82,8 @@ test_default_metrics(_) ->
8182
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_message_queue_len{peer")),
8283
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_reductions{peer")),
8384
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_status{peer")),
84-
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_state{peer"))
85+
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_state{peer")),
86+
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_queue_size_bytes{peer"))
8587
].
8688

8789

@@ -112,7 +114,8 @@ test_all_metrics(_) ->
112114
proc_message_queue_len,
113115
proc_reductions,
114116
proc_status,
115-
node_state
117+
node_state,
118+
node_queue_size_bytes
116119
]),
117120
prometheus_registry:register_collector(prometheus_vm_dist_collector),
118121
Metrics = prometheus_text_format:format(),
@@ -140,7 +143,8 @@ test_all_metrics(_) ->
140143
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_message_queue_len")),
141144
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_reductions")),
142145
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_status")),
143-
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_state"))
146+
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_state")),
147+
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_queue_size_bytes"))
144148
]
145149

146150
after
@@ -188,7 +192,8 @@ test_custom_metrics(_) ->
188192
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_proc_message_queue_len")),
189193
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_reductions")),
190194
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_proc_status")),
191-
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_state"))
195+
?_assertMatch({match, _}, re:run(Metrics, "erlang_vm_dist_node_state")),
196+
?_assertMatch(nomatch, re:run(Metrics, "erlang_vm_dist_node_queue_size_bytes"))
192197
]
193198

194199
after

0 commit comments

Comments
 (0)