From: Siraaj Khandkar Date: Fri, 25 Sep 2015 13:49:04 +0000 (-0400) Subject: feat: aggregate ETS per-table data, by table name X-Git-Tag: 0.14.0 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=990c1d4f6e21e1e59de2b8ee5dcac641bb8dd7b6;p=beam_stats.git feat: aggregate ETS per-table data, by table name --- diff --git a/src/beam_stats.app.src b/src/beam_stats.app.src index a9b621d..81e9182 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.13.0"}, + {vsn, "0.14.0"}, {registered, []}, {applications, [ kernel diff --git a/src/beam_stats_ets_table.erl b/src/beam_stats_ets_table.erl index 622c0f2..e310cf3 100644 --- a/src/beam_stats_ets_table.erl +++ b/src/beam_stats_ets_table.erl @@ -9,7 +9,6 @@ -export( [ of_id/1 - , id_to_bin/1 ]). -type id() :: @@ -35,10 +34,3 @@ of_id(ID) -> , size = beam_stats_source:ets_info(ID, size) , memory = NumberOfBytes }. - --spec id_to_bin(atom() | ets:tid()) -> - binary(). -id_to_bin(ID) when is_atom(ID) -> - atom_to_binary(ID, latin1); -id_to_bin(ID) when is_integer(ID) -> - integer_to_binary(ID). diff --git a/src/beam_stats_msg_graphite.erl b/src/beam_stats_msg_graphite.erl index bb89320..26751a5 100644 --- a/src/beam_stats_msg_graphite.erl +++ b/src/beam_stats_msg_graphite.erl @@ -136,8 +136,9 @@ of_memory(Memory, <>, Timestamp) -> [t()]. of_ets(PerTableStats, <>, Timestamp) -> OfEtsTable = fun (Table) -> of_ets_table(Table, NodeID, Timestamp) end, - NestedMsgs = lists:map(OfEtsTable, PerTableStats), - lists:append(NestedMsgs). + MsgsNested = lists:map(OfEtsTable, PerTableStats), + MsgsFlattened = lists:append(MsgsNested), + aggregate_by_path(MsgsFlattened, Timestamp). -spec of_ets_table(beam_stats_ets_table:t(), binary(), erlang:timestamp()) -> [t()]. @@ -150,9 +151,13 @@ of_ets_table(#beam_stats_ets_table <>, Timestamp ) -> - IDBin = beam_stats_ets_table:id_to_bin(ID), + IDType = + case ID =:= Name + of true -> <<"NAMED">> + ; false -> <<"TID">> + end, NameBin = atom_to_binary(Name, latin1), - NameAndID = [NameBin, IDBin], + NameAndID = [NameBin, IDType], [ cons([NodeID, <<"ets_table">>, <<"size">> | NameAndID], Size , Timestamp) , cons([NodeID, <<"ets_table">>, <<"memory">> | NameAndID], Memory, Timestamp) ]. diff --git a/test/beam_stats_consumer_statsd_SUITE.erl b/test/beam_stats_consumer_statsd_SUITE.erl index 2283ed9..b8b3d30 100644 --- a/test/beam_stats_consumer_statsd_SUITE.erl +++ b/test/beam_stats_consumer_statsd_SUITE.erl @@ -101,10 +101,10 @@ t_full_cycle(_Cfg) -> , <<"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">> + , <<"beam_stats_v0.node_foo_host_bar.ets_table.size.foo.NAMED:5|g">> + , <<"beam_stats_v0.node_foo_host_bar.ets_table.memory.foo.NAMED:40|g">> + , <<"beam_stats_v0.node_foo_host_bar.ets_table.size.bar.TID:16|g">> + , <<"beam_stats_v0.node_foo_host_bar.ets_table.memory.bar.TID:128|g">> % Processes totals , <<"beam_stats_v0.node_foo_host_bar.processes_count_all:4|g">> @@ -247,13 +247,20 @@ meck_expect_beam_stats(Overrides) -> , size = 5 , memory = 40 }, - ETSTableStatsBar = + ETSTableStatsBarA = #beam_stats_ets_table { id = 37 , name = bar , size = 8 , memory = 64 }, + ETSTableStatsBarB = + #beam_stats_ets_table + { id = 38 + , name = bar + , size = 8 + , memory = 64 + }, meck:expect(beam_stats_source, erlang_memory, fun () -> [{mem_type_foo, 1}, {mem_type_bar, 2}, {mem_type_baz, 3}] end), meck:expect(beam_stats_source, erlang_node, @@ -268,16 +275,21 @@ meck_expect_beam_stats(Overrides) -> end ), meck:expect(beam_stats_source, ets_all, - fun () -> [foo, 37] end), + fun () -> [foo, 37, 38] end), meck:expect(beam_stats_source, erlang_system_info, fun (wordsize) -> 8 end), meck:expect(beam_stats_source, ets_info, fun (foo, memory) -> 5 ; (foo, name ) -> foo ; (foo, size ) -> 5 + ; (37 , memory) -> 8 ; (37 , name ) -> bar ; (37 , size ) -> 8 + + ; (38 , memory) -> 8 + ; (38 , name ) -> bar + ; (38 , size ) -> 8 end ), meck:expect(beam_stats_source, erlang_processes, @@ -348,6 +360,6 @@ meck_expect_beam_stats(Overrides) -> , context_switches = ContextSwitches , reductions = 9 , run_queue = 17 - , ets = [ETSTableStatsFoo, ETSTableStatsBar] + , ets = [ETSTableStatsFoo, ETSTableStatsBarA, ETSTableStatsBarB] , processes = Processes }.