-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68c2c02
commit e6f3df8
Showing
6 changed files
with
202 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
defmodule TelemetryPollerVM do | ||
def attach do | ||
Enum.each( | ||
[ | ||
[:vm, :memory], | ||
[:vm, :total_run_queue_lengths], | ||
[:vm, :system_counts] | ||
], | ||
fn [:vm, namespace] = event_name -> | ||
handler_id = "vm.#{Atom.to_string(namespace)}" | ||
|
||
:telemetry.attach(handler_id, event_name, &TelemetryPollerVM.handle/4, _config = []) | ||
end | ||
) | ||
end | ||
|
||
def handle( | ||
[:vm, :memory], | ||
event_measurements, | ||
_event_metadata, | ||
_handler_config | ||
) do | ||
# Do something with the measurements | ||
IO.puts( | ||
"memory\n" <> | ||
"------\n" <> | ||
" atom: #{event_measurements.atom}\n" <> | ||
" atom_used: #{event_measurements.atom_used}\n" <> | ||
" binary: #{event_measurements.binary}\n" <> | ||
" code: #{event_measurements.code}\n" <> | ||
" ets: #{event_measurements.ets}\n" <> | ||
" processes: #{event_measurements.processes}\n" <> | ||
" processes_used: #{event_measurements.processes_used}\n" <> | ||
" system: #{event_measurements.system}\n" <> | ||
" total: #{event_measurements.total}\n" | ||
) | ||
end | ||
|
||
def handle( | ||
[:vm, :total_run_queue_lengths], | ||
event_measurements, | ||
_event_metadata, | ||
_handler_config | ||
) do | ||
# Do something with the measurements | ||
IO.puts( | ||
"total_run_queue_lengths\n" <> | ||
"-----------------------\n" <> | ||
" cpu: #{event_measurements.cpu}\n" <> | ||
" io: #{event_measurements.io}\n" <> | ||
" total: #{event_measurements.total}\n" | ||
) | ||
end | ||
|
||
def handle( | ||
[:vm, :system_counts], | ||
event_measurements, | ||
_event_metadata, | ||
_handler_config | ||
) do | ||
# Do something with the measurements | ||
IO.puts( | ||
"system_counts\n" <> | ||
"-------------\n" <> | ||
" atom_count: #{event_measurements.atom_count}\n" <> | ||
" port_count: #{event_measurements.port_count}\n" <> | ||
" process_count: #{event_measurements.process_count}\n" | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
-module(telemetry_poller_vm). | ||
|
||
-export([attach/0]). | ||
-export([handle/4]). | ||
|
||
attach() -> | ||
lists:foreach( | ||
fun([vm, Namespace] = EventName) -> | ||
NamespaceBin = atom_to_binary(Namespace), | ||
HandlerId = <<"vm.", NamespaceBin/binary>>, | ||
telemetry:attach(HandlerId, EventName, fun telemetry_poller_vm:handle/4, _Config = []) | ||
end, | ||
[ | ||
[vm, memory], | ||
[vm, total_run_queue_lengths], | ||
[vm, system_counts] | ||
] | ||
). | ||
|
||
handle([vm, memory], EventMeasurements, _EventMetadata, _HandlerConfig) -> | ||
#{ | ||
atom := Atom, | ||
atom_used := AtomUser, | ||
binary := Binary, | ||
code := Code, | ||
ets := ETS, | ||
processes := Processes, | ||
processes_used := ProcessesUsed, | ||
system := System, | ||
total := Total | ||
} = EventMeasurements, | ||
% Do something with the measurements | ||
io:format( | ||
"memory~n" | ||
"------~n" | ||
" atom: ~p~n" | ||
" atom_used: ~p~n" | ||
" binary: ~p~n" | ||
" code: ~p~n" | ||
" ets: ~p~n" | ||
" processes: ~p~n" | ||
" processes_used: ~p~n" | ||
" system: ~p~n" | ||
" total: ~p~n~n", | ||
[ | ||
Atom, | ||
AtomUser, | ||
Binary, | ||
Code, | ||
ETS, | ||
Processes, | ||
ProcessesUsed, | ||
System, | ||
Total | ||
] | ||
); | ||
handle([vm, total_run_queue_lengths], EventMeasurements, _EventMetadata, _HandlerConfig) -> | ||
#{ | ||
cpu := CPU, | ||
io := IO, | ||
total := Total | ||
} = EventMeasurements, | ||
% Do something with the measurements | ||
io:format( | ||
"total_run_queue_lengths~n" | ||
"-----------------------~n" | ||
" cpu: ~p~n" | ||
" io: ~p~n" | ||
" total: ~p~n~n", | ||
[ | ||
CPU, | ||
IO, | ||
Total | ||
] | ||
); | ||
handle([vm, system_counts], EventMeasurements, _EventMetadata, _HandlerConfig) -> | ||
#{ | ||
atom_count := AtomCount, | ||
port_count := PortCount, | ||
process_count := ProcessCount | ||
} = EventMeasurements, | ||
% Do something with the measurements | ||
io:format( | ||
"system_counts~n" | ||
"-------------~n" | ||
" atom_count: ~p~n" | ||
" port_count: ~p~n" | ||
" process_count: ~p~n~n", | ||
[ | ||
AtomCount, | ||
PortCount, | ||
ProcessCount | ||
] | ||
). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters