1 -module(beam_stats_msg_graphite).
3 -include("include/beam_stats.hrl").
4 -include("include/beam_stats_ets_table.hrl").
5 -include("include/beam_stats_msg_graphite.hrl").
21 -spec of_beam_stats(beam_stats:t()) ->
23 of_beam_stats(#beam_stats{node_id=NodeID}=BeamStats) ->
24 NodeIDBin = node_id_to_bin(NodeID),
25 of_beam_stats(BeamStats, NodeIDBin).
27 -spec of_beam_stats(beam_stats:t(), binary()) ->
29 of_beam_stats(#beam_stats
30 { timestamp = Timestamp
33 % TODO: Handle the rest of data points
34 , io_bytes_in = IOBytesIn
35 , io_bytes_out = IOBytesOut
36 , context_switches = ContextSwitches
37 , reductions = Reductions
38 , run_queue = RunQueue
40 , processes = _Processes
46 [ cons([N, <<"io">> , <<"bytes_in">> ], IOBytesIn , Ts)
47 , cons([N, <<"io">> , <<"bytes_out">>], IOBytesOut , Ts)
48 , cons([N, <<"context_switches">> ], ContextSwitches, Ts)
49 , cons([N, <<"reductions">> ], Reductions , Ts)
50 , cons([N, <<"run_queue">> ], RunQueue , Ts)
51 | of_memory(Memory, NodeID, Ts)
53 ++ of_ets(ETS, NodeID, Ts)
56 -spec of_memory([{atom(), non_neg_integer()}], binary(), erlang:timestamp()) ->
58 of_memory(Memory, <<NodeID/binary>>, Timestamp) ->
61 KeyBin = atom_to_binary(Key, latin1),
62 cons([NodeID, <<"memory">>, KeyBin], Value, Timestamp)
64 lists:map(ComponentToMessage, Memory).
66 -spec of_ets(beam_stats_ets_table:t(), binary(), erlang:timestamp()) ->
68 of_ets(PerTableStats, <<NodeID/binary>>, Timestamp) ->
69 OfEtsTable = fun (Table) -> of_ets_table(Table, NodeID, Timestamp) end,
70 NestedMsgs = lists:map(OfEtsTable, PerTableStats),
71 lists:append(NestedMsgs).
73 -spec of_ets_table(beam_stats_ets_table:t(), binary(), erlang:timestamp()) ->
75 of_ets_table(#beam_stats_ets_table
84 IDBin = beam_stats_ets_table:id_to_bin(ID),
85 NameBin = atom_to_binary(Name, latin1),
86 NameAndID = [NameBin, IDBin],
87 [ cons([NodeID, <<"ets_table">>, <<"size">> | NameAndID], Size , Timestamp)
88 , cons([NodeID, <<"ets_table">>, <<"memory">> | NameAndID], Memory, Timestamp)
91 -spec cons([binary()], integer(), erlang:timestamp()) ->
93 cons(Path, Value, Timestamp) ->
97 , timestamp = Timestamp
100 -spec node_id_to_bin(node()) ->
102 node_id_to_bin(NodeID) ->
103 NodeIDBin = atom_to_binary(NodeID, utf8),
104 re:replace(NodeIDBin, "[\@\.]", "_", [global, {return, binary}]).