From 142c0796ba129bf10a47dfa447b460bb8fa123a5 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 24 Aug 2015 20:33:22 -0400 Subject: [PATCH] Add reductions delta. --- include/beam_stats.hrl | 1 + src/beam_stats.app.src | 2 +- src/beam_stats_consumer_statsd.erl | 11 +++++++++++ src/beam_stats_state.erl | 8 ++++++++ test/beam_stats_consumer_statsd_SUITE.erl | 2 ++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/beam_stats.hrl b/include/beam_stats.hrl index ae0b48a..8089595 100644 --- a/include/beam_stats.hrl +++ b/include/beam_stats.hrl @@ -5,6 +5,7 @@ , io_bytes_in :: non_neg_integer() , io_bytes_out :: non_neg_integer() , context_switches :: non_neg_integer() + , reductions :: non_neg_integer() %, statistics :: [{atom() , term()}] %, system :: [{atom() , term()}] %, process :: [{atom() , term()}] diff --git a/src/beam_stats.app.src b/src/beam_stats.app.src index 00697fc..6fc53a2 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.3.0"}, + {vsn, "0.4.0"}, {registered, []}, {applications, [ kernel diff --git a/src/beam_stats_consumer_statsd.erl b/src/beam_stats_consumer_statsd.erl index 5b2f818..c434429 100644 --- a/src/beam_stats_consumer_statsd.erl +++ b/src/beam_stats_consumer_statsd.erl @@ -145,6 +145,7 @@ beam_stats_to_bins(#beam_stats , io_bytes_in = IOBytesIn , io_bytes_out = IOBytesOut , context_switches = ContextSwitches + , reductions = Reductions } ) -> NodeIDBin = node_id_to_bin(NodeID), @@ -152,11 +153,21 @@ beam_stats_to_bins(#beam_stats [ io_bytes_in_to_msg(IOBytesIn) , io_bytes_out_to_msg(IOBytesOut) , context_switches_to_msg(ContextSwitches) + , reductions_to_msg(Reductions) | memory_to_msgs(Memory) ], Msgs2 = [statsd_msg_add_name_prefix(M, NodeIDBin) || M <- Msgs1], [statsd_msg_to_bin(M) || M <- Msgs2]. +-spec reductions_to_msg(non_neg_integer()) -> + statsd_msg(). +reductions_to_msg(Reductions) -> + #statsd_msg + { name = <<"reductions">> + , value = Reductions + , type = gauge + }. + -spec context_switches_to_msg(non_neg_integer()) -> statsd_msg(). context_switches_to_msg(ContextSwitches) -> diff --git a/src/beam_stats_state.erl b/src/beam_stats_state.erl index 17f9c90..4dcadd6 100644 --- a/src/beam_stats_state.erl +++ b/src/beam_stats_state.erl @@ -24,6 +24,8 @@ , previous_context_switches :: non_neg_integer() , current_context_switches :: non_neg_integer() + + , reductions :: non_neg_integer() }). -define(T, #?MODULE). @@ -38,6 +40,7 @@ new() -> , {output , CurrentIOBytesOut} } = erlang:statistics(io), {CurrentContextSwitches, 0} = erlang:statistics(context_switches), + {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions), ?T { timestamp = os:timestamp() , node_id = erlang:node() @@ -48,6 +51,7 @@ new() -> , current_io_bytes_out = CurrentIOBytesOut , previous_context_switches = 0 , current_context_switches = CurrentContextSwitches + , reductions = ReductionsDelta }. -spec update(t()) -> @@ -62,6 +66,7 @@ update(?T , {output , CurrentIOBytesOut} } = erlang:statistics(io), {CurrentContextSwitches, 0} = erlang:statistics(context_switches), + {_ReductionsTotal, ReductionsDelta} = erlang:statistics(reductions), ?T { timestamp = os:timestamp() , node_id = erlang:node() @@ -72,6 +77,7 @@ update(?T , current_io_bytes_out = CurrentIOBytesOut , previous_context_switches = PreviousContextSwitches , current_context_switches = CurrentContextSwitches + , reductions = ReductionsDelta }. -spec export(t()) -> @@ -87,6 +93,7 @@ export( , current_io_bytes_out = CurrentIOBytesOut , previous_context_switches = PreviousContextSwitches , current_context_switches = CurrentContextSwitches + , reductions = Reductions } ) -> #beam_stats @@ -96,4 +103,5 @@ export( , io_bytes_in = CurrentIOBytesIn - PreviousIOBytesIn , io_bytes_out = CurrentIOBytesOut - PreviousIOBytesOut , context_switches = CurrentContextSwitches - PreviousContextSwitches + , reductions = Reductions }. diff --git a/test/beam_stats_consumer_statsd_SUITE.erl b/test/beam_stats_consumer_statsd_SUITE.erl index 87f5dd3..32864f0 100644 --- a/test/beam_stats_consumer_statsd_SUITE.erl +++ b/test/beam_stats_consumer_statsd_SUITE.erl @@ -40,6 +40,7 @@ t_send(_Cfg) -> , io_bytes_in = 3 , io_bytes_out = 7 , context_switches = 5 + , reductions = 9 }, ServerPort = 8125, {ok, ServerSocket} = gen_udp:open(ServerPort, [binary, {active, false}]), @@ -54,5 +55,6 @@ t_send(_Cfg) -> << "beam_stats.node_foo_host_bar.io.bytes_in:3|g\n" , "beam_stats.node_foo_host_bar.io.bytes_out:7|g\n" , "beam_stats.node_foo_host_bar.context_switches:5|g\n" + , "beam_stats.node_foo_host_bar.reductions:9|g\n" , "beam_stats.node_foo_host_bar.memory.mem_type_foo:1|g\n" >> = Data. -- 2.20.1