From: Siraaj Khandkar Date: Fri, 25 Sep 2015 12:25:09 +0000 (-0400) Subject: feat: prefix Graphite paths with current schema version X-Git-Tag: 0.13.0^0 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=8fe744e7d00da9039d59d3551d4f05a0e1b007d2;p=beam_stats.git feat: prefix Graphite paths with current schema version --- diff --git a/src/beam_stats.app.src b/src/beam_stats.app.src index 24f8b70..a9b621d 100644 --- a/src/beam_stats.app.src +++ b/src/beam_stats.app.src @@ -1,7 +1,7 @@ {application, beam_stats, [ {description, "Periodic VM stats production and consumption."}, - {vsn, "0.12.0"}, + {vsn, "0.13.0"}, {registered, []}, {applications, [ kernel diff --git a/src/beam_stats_consumer_graphite.erl b/src/beam_stats_consumer_graphite.erl index 036f6c9..5122479 100644 --- a/src/beam_stats_consumer_graphite.erl +++ b/src/beam_stats_consumer_graphite.erl @@ -32,7 +32,6 @@ -type state() :: #state{}. --define(PATH_PREFIX , <<"beam_stats">>). -define(DEFAULT_HOST , "localhost"). -define(DEFAULT_PORT , 2003). -define(DEFAULT_TIMEOUT , 5000). @@ -115,8 +114,5 @@ beam_stats_queue_to_binary(Q) -> -spec beam_stats_to_bins(beam_stats:t()) -> [binary()]. beam_stats_to_bins(#beam_stats{}=BeamStats) -> - MsgAddPrefix = - fun (M) -> beam_stats_msg_graphite:add_path_prefix(M, ?PATH_PREFIX) end, - Msgs1 = beam_stats_msg_graphite:of_beam_stats(BeamStats), - Msgs2 = lists:map(MsgAddPrefix, Msgs1), - lists:map(fun beam_stats_msg_graphite:to_bin/1, Msgs2). + Msgs = beam_stats_msg_graphite:of_beam_stats(BeamStats), + lists:map(fun beam_stats_msg_graphite:to_bin/1, Msgs). diff --git a/src/beam_stats_consumer_statsd.erl b/src/beam_stats_consumer_statsd.erl index 06945e1..644fb63 100644 --- a/src/beam_stats_consumer_statsd.erl +++ b/src/beam_stats_consumer_statsd.erl @@ -41,8 +41,6 @@ -type state() :: #state{}. --define(PATH_PREFIX, <<"beam_stats">>). - %% ============================================================================ %% Consumer implementation %% ============================================================================ @@ -154,10 +152,7 @@ beam_stats_queue_to_packets(Q, NumMsgsPerPacket, StaticNodeNameOpt) -> 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). diff --git a/src/beam_stats_msg_graphite.erl b/src/beam_stats_msg_graphite.erl index 87dae3e..bb89320 100644 --- a/src/beam_stats_msg_graphite.erl +++ b/src/beam_stats_msg_graphite.erl @@ -16,7 +16,6 @@ , of_beam_stats/2 , to_bin/1 , path_to_bin/1 - , add_path_prefix/2 , node_id_to_bin/1 ]). @@ -53,15 +52,17 @@ of_beam_stats(#beam_stats ) -> 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(). @@ -78,11 +79,6 @@ to_bin( TimestampBin = integer_to_binary(TimestampInt), <>. --spec add_path_prefix(t(), binary()) -> - t(). -add_path_prefix(?T{path=Path}=T, <>) -> - T?T{path = [Prefix | Path]}. - -spec path_to_bin([binary()]) -> binary(). path_to_bin(Path) -> @@ -98,6 +94,21 @@ node_id_to_bin(NodeID) -> %% 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, <>) -> + T?T{path = [Prefix | Path]}. + +-spec schema_version() -> + binary(). +schema_version() -> + <<"beam_stats_v0">>. + -spec bin_join([binary()], binary()) -> binary(). bin_join([] , <<_/binary>> ) -> <<>>; diff --git a/test/beam_stats_consumer_statsd_SUITE.erl b/test/beam_stats_consumer_statsd_SUITE.erl index f151c32..2283ed9 100644 --- a/test/beam_stats_consumer_statsd_SUITE.erl +++ b/test/beam_stats_consumer_statsd_SUITE.erl @@ -93,46 +93,46 @@ t_full_cycle(_Cfg) -> >>, 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 =