feat: use new msg abstractions in StatsD consumer.
[beam_stats.git] / src / beam_stats_msg_graphite.erl
index 5b4e6e2..c88e327 100644 (file)
 
 -export(
     [ of_beam_stats/1
+    , of_beam_stats/2
     , to_bin/1
+    , path_to_bin/1
+    , add_path_prefix/2
+    , node_id_to_bin/1
     ]).
 
 -define(T, #?MODULE).
@@ -69,12 +73,28 @@ to_bin(
     , timestamp = Timestamp
     }
 ) ->
-    PathBin = bin_join(Path, <<".">>),
+    PathBin = path_to_bin(Path),
     ValueBin = integer_to_binary(Value),
     TimestampInt = timestamp_to_integer(Timestamp),
     TimestampBin = integer_to_binary(TimestampInt),
     <<PathBin/binary, " ", ValueBin/binary, " ", TimestampBin/binary>>.
 
+-spec add_path_prefix(t(), binary()) ->
+    t().
+add_path_prefix(?T{path=Path}=T, <<Prefix/binary>>) ->
+    T?T{path = [Prefix | Path]}.
+
+-spec path_to_bin([binary()]) ->
+    binary().
+path_to_bin(Path) ->
+    bin_join(Path, <<".">>).
+
+-spec node_id_to_bin(node()) ->
+    binary().
+node_id_to_bin(NodeID) ->
+    NodeIDBin = atom_to_binary(NodeID, utf8),
+    re:replace(NodeIDBin, "[\@\.]", "_", [global, {return, binary}]).
+
 %% ============================================================================
 %% Helpers
 %% ============================================================================
@@ -179,10 +199,10 @@ of_process(
     OriginAndPid = [OriginBin, PidBin],
     Ts = Timestamp,
     N  = NodeID,
-    [ cons([N, <<"process_memory">>            , OriginAndPid], Memory        , Ts)
-    , cons([N, <<"process_total_heap_size">>   , OriginAndPid], TotalHeapSize , Ts)
-    , cons([N, <<"process_stack_size">>        , OriginAndPid], StackSize     , Ts)
-    , cons([N, <<"process_message_queue_len">> , OriginAndPid], MsgQueueLen   , Ts)
+    [ cons([N, <<"process_memory">>            | OriginAndPid], Memory        , Ts)
+    , cons([N, <<"process_total_heap_size">>   | OriginAndPid], TotalHeapSize , Ts)
+    , cons([N, <<"process_stack_size">>        | OriginAndPid], StackSize     , Ts)
+    , cons([N, <<"process_message_queue_len">> | OriginAndPid], MsgQueueLen   , Ts)
     ].
 
 -spec proc_origin_to_bin(beam_stats_process:best_known_origin()) ->
@@ -245,9 +265,3 @@ cons(Path, Value, Timestamp) ->
     , value     = Value
     , timestamp = Timestamp
     }.
-
--spec node_id_to_bin(node()) ->
-    binary().
-node_id_to_bin(NodeID) ->
-    NodeIDBin = atom_to_binary(NodeID, utf8),
-    re:replace(NodeIDBin, "[\@\.]", "_", [global, {return, binary}]).
This page took 0.027193 seconds and 4 git commands to generate.