Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/telemetry_poller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ The following measurements are supported:
* `memory` (default)
* `total_run_queue_lengths` (default)
* `system_counts` (default)
* `persistent_term` (default)
* `{process_info, Proplist}`
* `{Module, Function, Args}`

We will discuss each measurement in detail. Also note that the
`telemetry_poller` application ships with a built-in poller that
measures `memory`, `total_run_queue_lengths` and `system_counts`. This takes
measures `memory`, `total_run_queue_lengths`, `system_counts`, and `persistent_term`. This takes
the VM measurement out of the way so your application can focus
on what is specific to its behaviour.

Expand Down Expand Up @@ -83,6 +84,14 @@ The measurement includes:
* `atom_count` - the number of atoms currently existing at the local node
* `port_count` - the number of ports currently existing at the local node

### Persistent term (since 1.2.0)

An event emitted as `[vm, persistent_term]`. The measurement includes information
about persistent terms in the system, as returned by `persistent_term:info/0`:

* `count` - The number of persistent terms
* `memory` - The total amount of memory (measured in bytes) used by all persistent terms

### Process info

A measurement with information about a given process. It must be specified
Expand Down Expand Up @@ -315,6 +324,7 @@ A measurement for the poller.
memory
| total_run_queue_lengths
| system_counts
| persistent_term
| {process_info, [{name, atom()} | {event, [atom()]} | {keys, [atom()]}]}
| {module(), atom(), list()}.

Expand Down Expand Up @@ -425,6 +435,8 @@ parse_measurement(total_run_queue_lengths) ->
{telemetry_poller_builtin, total_run_queue_lengths, []};
parse_measurement(system_counts) ->
{telemetry_poller_builtin, system_counts, []};
parse_measurement(persistent_term) ->
{telemetry_poller_builtin, persistent_term, []};
parse_measurement({process_info, List}) when is_list(List) ->
Name = case proplists:get_value(name, List) of
undefined -> erlang:error({badarg, "Expected `name' key to be given under process_info measurement"});
Expand Down
7 changes: 6 additions & 1 deletion src/telemetry_poller_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ start(_StartType, _StartArgs) ->
PollerOpts ->
Default = #{
name => telemetry_poller_default,
measurements => [memory, total_run_queue_lengths, system_counts]
measurements => [
memory,
total_run_queue_lengths,
system_counts,
persistent_term
]
},
FinalOpts = maps:to_list(maps:merge(Default, maps:from_list(PollerOpts))),
[telemetry_poller:child_spec(FinalOpts)]
Expand Down
6 changes: 6 additions & 0 deletions src/telemetry_poller_builtin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
memory/0,
total_run_queue_lengths/0,
system_counts/0,
persistent_term/0,
process_info/3
]).

Expand Down Expand Up @@ -65,3 +66,8 @@ total_run_queue_lengths() ->
port_count => PortCount
}).
-endif.

-spec persistent_term() -> ok.
persistent_term() ->
Info = persistent_term:info(),
telemetry:execute([vm, persistent_term], Info, #{}).
17 changes: 17 additions & 0 deletions test/telemetry_poller_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ all() -> [
can_configure_sampling_period,
dispatches_custom_mfa,
dispatches_memory,
dispatches_persistent_term,
dispatches_process_info,
dispatches_system_counts,
dispatches_total_run_queue_lengths,
Expand Down Expand Up @@ -154,6 +155,22 @@ dispatches_process_info(_Config) ->
ct:fail(timeout_receive_echo)
end.

dispatches_persistent_term(_Config) ->
{ok, _Poller} = telemetry_poller:start_link([{measurements, [persistent_term]}, {period, 100}]),
HandlerId = attach_to([vm, persistent_term]),
receive
{event, [vm, persistent_term], #{count := Count, memory := Memory}, _} ->
?assert(is_integer(Count)),
?assert(Count >= 0),
?assert(is_integer(Memory)),
?assert(Memory >= 0),
telemetry:detach(HandlerId),
?assert(true)
after
1000 ->
ct:fail(timeout_receive_echo)
end.

attach_to(Event) ->
HandlerId = make_ref(),
telemetry:attach(HandlerId, Event, fun test_handler:echo_event/4, #{caller => erlang:self()}),
Expand Down