Skip to content

Commit 411675d

Browse files
authored
Add vm.system_counts measurements with atom, port, process limits (#79)
1 parent fefb3e9 commit 411675d

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Allows to periodically collect measurements and dispatch them as Telemetry event
99

1010
* `[vm, memory]` - contains the total memory, process memory, and all other keys in `erlang:memory/0`
1111
* `[vm, total_run_queue_lengths]` - returns the run queue lengths for CPU and IO schedulers. It contains the `total`, `cpu` and `io` measurements
12-
* `[vm, system_counts]` - returns the current process, atom and port count as per `erlang:system_info/1`
12+
* `[vm, system_counts]` - returns the current process, atom and port count as well as their respective limits as per `erlang:system_info/1`
1313
* `[vm, persistent_term]` - number of terms and memory byte size for `persistent_term`
1414

1515
You can directly consume those events after adding `telemetry_poller` as a dependency.

examples/TelemetryPollerVM.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ defmodule TelemetryPollerVM do
6464
"-------------\n" <>
6565
" atom_count: #{event_measurements.atom_count}\n" <>
6666
" port_count: #{event_measurements.port_count}\n" <>
67-
" process_count: #{event_measurements.process_count}\n"
67+
" process_count: #{event_measurements.process_count}\n" <>
68+
" atom_limit: #{event_measurements.atom_limit}\n" <>
69+
" port_limit: #{event_measurements.port_limit}\n" <>
70+
" process_limit: #{event_measurements.process_limit}\n"
6871
)
6972
end
7073
end

examples/telemetry_poller_vm.erl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,27 @@ handle([vm, system_counts], EventMeasurements, _EventMetadata, _HandlerConfig) -
7777
#{
7878
atom_count := AtomCount,
7979
port_count := PortCount,
80-
process_count := ProcessCount
80+
process_count := ProcessCount,
81+
atom_limit := AtomLimit,
82+
port_limit := PortLimit,
83+
process_limit := ProcessLimit
8184
} = EventMeasurements,
8285
% Do something with the measurements
8386
io:format(
8487
"system_counts~n"
8588
"-------------~n"
8689
" atom_count: ~p~n"
8790
" port_count: ~p~n"
88-
" process_count: ~p~n~n",
91+
" process_count: ~p~n"
92+
" atom_limit: ~p~n"
93+
" port_limit: ~p~n"
94+
" process_limit: ~p~n~n",
8995
[
9096
AtomCount,
9197
PortCount,
92-
ProcessCount
98+
ProcessCount,
99+
AtomLimit,
100+
PortLimit,
101+
ProcessLimit
93102
]
94103
).

src/telemetry_poller.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ The measurement includes:
8383
* `process_count` - the number of processes currently existing at the local node
8484
* `atom_count` - the number of atoms currently existing at the local node
8585
* `port_count` - the number of ports currently existing at the local node
86+
* `process_limit` - the maximum number of processes allowed at the local node
87+
* `atom_limit` - the maximum number of atoms allowed at the local node
88+
* `port_limit` - the maximum number of ports allowed at the local node
8689
8790
### Persistent term (since 1.2.0)
8891

src/telemetry_poller_builtin.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ system_counts() ->
4646
ProcessCount = erlang:system_info(process_count),
4747
AtomCount = erlang:system_info(atom_count),
4848
PortCount = erlang:system_info(port_count),
49+
ProcessLimit = erlang:system_info(process_limit),
50+
AtomLimit = erlang:system_info(atom_limit),
51+
PortLimit = erlang:system_info(port_limit),
4952
telemetry:execute([vm, system_counts], #{
5053
process_count => ProcessCount,
5154
atom_count => AtomCount,
52-
port_count => PortCount
55+
port_count => PortCount,
56+
process_limit => ProcessLimit,
57+
atom_limit => AtomLimit,
58+
port_limit => PortLimit
5359
}).
5460

5561
-spec persistent_term() -> ok.

test/telemetry_poller_SUITE.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ dispatches_system_counts(_Config) ->
128128
{ok, _Poller} = telemetry_poller:start_link([{measurements, [system_counts]},{period, 100}]),
129129
HandlerId = attach_to([vm, system_counts]),
130130
receive
131-
{event, [vm, system_counts], #{process_count := _, atom_count := _, port_count := _}, _} ->
131+
{event, [vm, system_counts], #{process_count := _, atom_count := _, port_count := _,
132+
process_limit := _, atom_limit := _, port_limit := _}, _} ->
132133
telemetry:detach(HandlerId),
133134
?assert(true)
134135
after

0 commit comments

Comments
 (0)