-type state() ::
#state{}.
--define(PATH_PREFIX, <<"beam_stats">>).
-
%% ============================================================================
%% Consumer implementation
%% ============================================================================
beam_stats_to_bins(#beam_stats{node_id=NodeID}=BeamStats, StaticNodeNameOpt) ->
NodeIDBinDefault = beam_stats_msg_graphite:node_id_to_bin(NodeID),
NodeIDBin = hope_option:get(StaticNodeNameOpt, NodeIDBinDefault),
- GraphiteMsgAddPrefix =
- fun (M) -> beam_stats_msg_graphite:add_path_prefix(M, ?PATH_PREFIX) end,
- MsgsGraphite1 = beam_stats_msg_graphite:of_beam_stats(BeamStats, NodeIDBin),
- MsgsGraphite2 = lists:map(GraphiteMsgAddPrefix, MsgsGraphite1),
+ MsgsGraphite = beam_stats_msg_graphite:of_beam_stats(BeamStats, NodeIDBin),
MsgsStatsD =
- lists:map(fun beam_stats_msg_statsd_gauge:of_msg_graphite/1, MsgsGraphite2),
+ lists:map(fun beam_stats_msg_statsd_gauge:of_msg_graphite/1, MsgsGraphite),
lists:map(fun beam_stats_msg_statsd_gauge:to_bin/1, MsgsStatsD).
, of_beam_stats/2
, to_bin/1
, path_to_bin/1
- , add_path_prefix/2
, node_id_to_bin/1
]).
) ->
Ts = Timestamp,
N = NodeID,
- [ cons([N, <<"io">> , <<"bytes_in">> ], IOBytesIn , Ts)
- , cons([N, <<"io">> , <<"bytes_out">>], IOBytesOut , Ts)
- , cons([N, <<"context_switches">> ], ContextSwitches, Ts)
- , cons([N, <<"reductions">> ], Reductions , Ts)
- , cons([N, <<"run_queue">> ], RunQueue , Ts)
- | of_memory(Memory, NodeID, Ts)
- ]
- ++ of_ets(ETS, NodeID, Ts)
- ++ of_processes(Processes, NodeID, Ts).
+ Msgs =
+ [ cons([N, <<"io">> , <<"bytes_in">> ], IOBytesIn , Ts)
+ , cons([N, <<"io">> , <<"bytes_out">>], IOBytesOut , Ts)
+ , cons([N, <<"context_switches">> ], ContextSwitches, Ts)
+ , cons([N, <<"reductions">> ], Reductions , Ts)
+ , cons([N, <<"run_queue">> ], RunQueue , Ts)
+ | of_memory(Memory, NodeID, Ts)
+ ]
+ ++ of_ets(ETS, NodeID, Ts)
+ ++ of_processes(Processes, NodeID, Ts),
+ lists:map(fun path_prefix_schema_version/1, Msgs).
-spec to_bin(t()) ->
binary().
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) ->
%% Helpers
%% ============================================================================
+-spec path_prefix_schema_version(t()) ->
+ t().
+path_prefix_schema_version(?T{}=T) ->
+ path_prefix(T, schema_version()).
+
+-spec path_prefix(t(), binary()) ->
+ t().
+path_prefix(?T{path=Path}=T, <<Prefix/binary>>) ->
+ T?T{path = [Prefix | Path]}.
+
+-spec schema_version() ->
+ binary().
+schema_version() ->
+ <<"beam_stats_v0">>.
+
-spec bin_join([binary()], binary()) ->
binary().
bin_join([] , <<_/binary>> ) -> <<>>;
>>,
ct:log("PacketsCombined: ~n~s~n", [PacketsCombined]),
MsgsExpected =
- [ <<"beam_stats.node_foo_host_bar.io.bytes_in:3|g">>
- , <<"beam_stats.node_foo_host_bar.io.bytes_out:7|g">>
- , <<"beam_stats.node_foo_host_bar.context_switches:5|g">>
- , <<"beam_stats.node_foo_host_bar.reductions:9|g">>
- , <<"beam_stats.node_foo_host_bar.run_queue:17|g">>
- , <<"beam_stats.node_foo_host_bar.memory.mem_type_foo:1|g">>
- , <<"beam_stats.node_foo_host_bar.memory.mem_type_bar:2|g">>
- , <<"beam_stats.node_foo_host_bar.memory.mem_type_baz:3|g">>
- , <<"beam_stats.node_foo_host_bar.ets_table.size.foo.foo:5|g">>
- , <<"beam_stats.node_foo_host_bar.ets_table.memory.foo.foo:40|g">>
- , <<"beam_stats.node_foo_host_bar.ets_table.size.bar.37:8|g">>
- , <<"beam_stats.node_foo_host_bar.ets_table.memory.bar.37:64|g">>
+ [ <<"beam_stats_v0.node_foo_host_bar.io.bytes_in:3|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.io.bytes_out:7|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.context_switches:5|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.reductions:9|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.run_queue:17|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.memory.mem_type_foo:1|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.memory.mem_type_bar:2|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.memory.mem_type_baz:3|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.ets_table.size.foo.foo:5|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.ets_table.memory.foo.foo:40|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.ets_table.size.bar.37:8|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.ets_table.memory.bar.37:64|g">>
% Processes totals
- , <<"beam_stats.node_foo_host_bar.processes_count_all:4|g">>
- , <<"beam_stats.node_foo_host_bar.processes_count_exiting:0|g">>
- , <<"beam_stats.node_foo_host_bar.processes_count_garbage_collecting:0|g">>
- , <<"beam_stats.node_foo_host_bar.processes_count_registered:1|g">>
- , <<"beam_stats.node_foo_host_bar.processes_count_runnable:0|g">>
- , <<"beam_stats.node_foo_host_bar.processes_count_running:3|g">>
- , <<"beam_stats.node_foo_host_bar.processes_count_suspended:0|g">>
- , <<"beam_stats.node_foo_host_bar.processes_count_waiting:1|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_all:4|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_exiting:0|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_garbage_collecting:0|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_registered:1|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_runnable:0|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_running:3|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_suspended:0|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.processes_count_waiting:1|g">>
% Process 1
- , <<"beam_stats.node_foo_host_bar.process_memory.named--reg_name_foo:15|g">>
- , <<"beam_stats.node_foo_host_bar.process_total_heap_size.named--reg_name_foo:25|g">>
- , <<"beam_stats.node_foo_host_bar.process_stack_size.named--reg_name_foo:10|g">>
- , <<"beam_stats.node_foo_host_bar.process_message_queue_len.named--reg_name_foo:0|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_memory.named--reg_name_foo:15|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_total_heap_size.named--reg_name_foo:25|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_stack_size.named--reg_name_foo:10|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_message_queue_len.named--reg_name_foo:0|g">>
% Process 2
- , <<"beam_stats.node_foo_host_bar.process_memory.spawned-via--bar_mod-bar_fun-1--NONE--NONE:25|g">>
- , <<"beam_stats.node_foo_host_bar.process_total_heap_size.spawned-via--bar_mod-bar_fun-1--NONE--NONE:35|g">>
- , <<"beam_stats.node_foo_host_bar.process_stack_size.spawned-via--bar_mod-bar_fun-1--NONE--NONE:40|g">>
- , <<"beam_stats.node_foo_host_bar.process_message_queue_len.spawned-via--bar_mod-bar_fun-1--NONE--NONE:5|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_memory.spawned-via--bar_mod-bar_fun-1--NONE--NONE:25|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_total_heap_size.spawned-via--bar_mod-bar_fun-1--NONE--NONE:35|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_stack_size.spawned-via--bar_mod-bar_fun-1--NONE--NONE:40|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_message_queue_len.spawned-via--bar_mod-bar_fun-1--NONE--NONE:5|g">>
% Process 3 and 4, aggregated by origin
- , <<"beam_stats.node_foo_host_bar.process_memory.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:30|g">>
- , <<"beam_stats.node_foo_host_bar.process_total_heap_size.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:45|g">>
- , <<"beam_stats.node_foo_host_bar.process_stack_size.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:55|g">>
- , <<"beam_stats.node_foo_host_bar.process_message_queue_len.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:1|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_memory.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:30|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_total_heap_size.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:45|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_stack_size.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:55|g">>
+ , <<"beam_stats_v0.node_foo_host_bar.process_message_queue_len.spawned-via--baz_mod-baz_fun-3--baz_otp_mod-baz_otp_fun-2--PID-PID:1|g">>
],
MsgsReceived = binary:split(PacketsCombined, <<"\n">>, [global, trim]),
RemoveExpectedFromReceived =