feat: aggregate ETS per-table data, by table name 0.14.0
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 25 Sep 2015 13:49:04 +0000 (09:49 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Fri, 25 Sep 2015 13:57:23 +0000 (09:57 -0400)
src/beam_stats.app.src
src/beam_stats_ets_table.erl
src/beam_stats_msg_graphite.erl
test/beam_stats_consumer_statsd_SUITE.erl

index a9b621d..81e9182 100644 (file)
@@ -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
index 622c0f2..e310cf3 100644 (file)
@@ -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).
index bb89320..26751a5 100644 (file)
@@ -136,8 +136,9 @@ of_memory(Memory, <<NodeID/binary>>, Timestamp) ->
     [t()].
 of_ets(PerTableStats, <<NodeID/binary>>, 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
     <<NodeID/binary>>,
     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)
     ].
index 2283ed9..b8b3d30 100644 (file)
@@ -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
     }.
This page took 0.030357 seconds and 4 git commands to generate.