feat: implement beam_stats_msg_graphite:of_memory/3
[beam_stats.git] / src / beam_stats_msg_graphite.erl
CommitLineData
a9ed8751
SK
1-module(beam_stats_msg_graphite).
2
3-include("include/beam_stats.hrl").
4-include("include/beam_stats_msg_graphite.hrl").
5
6-export_type(
7 [ t/0
8 ]).
9
10-export(
11 [ of_beam_stats/1
12 %, to_bin/1
13 ]).
14
15-define(T, #?MODULE).
16
17-type t() ::
18 ?T{}.
19
20-spec of_beam_stats(beam_stats:t()) ->
21 [t()].
22of_beam_stats(#beam_stats{node_id=NodeID}=BeamStats) ->
23 NodeIDBin = node_id_to_bin(NodeID),
24 of_beam_stats(BeamStats, NodeIDBin).
25
26-spec of_beam_stats(beam_stats:t(), binary()) ->
27 [t()].
28of_beam_stats(#beam_stats
29 { timestamp = Timestamp
30 , node_id = _
31 , memory = Memory
32 % TODO: Handle the rest of data point
33 },
34 <<NodeID/binary>>
35) ->
36 of_memory(Memory, NodeID, Timestamp).
37
38-spec of_memory([{atom(), non_neg_integer()}], binary(), erlang:timestamp()) ->
39 [t()].
40of_memory(Memory, <<NodeID/binary>>, Timestamp) ->
41 ComponentToMessage =
42 fun ({Key, Value}) ->
43 KeyBin = atom_to_binary(Key, latin1),
44 ?T
45 { path = [NodeID, <<"memory">>, KeyBin]
46 , value = Value
47 , timestamp = Timestamp
48 }
49 end,
50 lists:map(ComponentToMessage, Memory).
51
52-spec node_id_to_bin(node()) ->
53 binary().
54node_id_to_bin(NodeID) ->
55 NodeIDBin = atom_to_binary(NodeID, utf8),
56 re:replace(NodeIDBin, "[\@\.]", "_", [global, {return, binary}]).
This page took 0.029619 seconds and 4 git commands to generate.