Skip to content

Commit

Permalink
Remove APP part of stat identification, stats MUST have unique names
Browse files Browse the repository at this point in the history
  • Loading branch information
russelldb committed Apr 11, 2012
1 parent 2c545ca commit e95a295
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
23 changes: 16 additions & 7 deletions src/riak_core_metric_proc.erl
Expand Up @@ -24,7 +24,7 @@
-behaviour(gen_server).

%% API
-export([start_link/3, update/3, value/2, value/3]).
-export([start_link/2, update/2, value/1, value/2]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
Expand All @@ -36,16 +36,16 @@
%%% API
%%%===================================================================

start_link(_App, Name, Args) ->
start_link(Name, Args) ->
gen_server:start_link({local, Name}, ?MODULE, [{name, Name}|Args], []).

update(_App, Name, Args) ->
update(Name, Args) ->
gen_server:cast(Name, {update, Args}).

value(App, Name) ->
value(App, Name, []).
value(Name) ->
value(Name, []).

value(_App, Name, Presentation) ->
value(Name, Presentation) ->
{ok, Val} = gen_server:call(Name, {value, Presentation}),
Val.

Expand All @@ -56,7 +56,8 @@ init(Args) ->
Description = proplists:get_value(description, Args),
DisplaySpec = proplists:get_value(presentation, Args),
ModState = Mod:new(),
if Type == meter ->
DoTicks = do_ticks(Mod),
if DoTicks == true ->
%% start a tick
timer:send_interval(5000, tick);
true ->
Expand Down Expand Up @@ -105,3 +106,11 @@ mod_from_type({mod, Mod}) ->
Mod;
mod_from_type(ShortName) ->
list_to_atom("riak_core_metric_" ++ atom_to_list(ShortName)).

do_ticks(Mod) ->
case proplists:get_value(tick, Mod:module_info(exports)) of
1 ->
true;
_ ->
false
end.
2 changes: 1 addition & 1 deletion src/riak_core_metric_sup.erl
Expand Up @@ -68,7 +68,7 @@ mod_refs(App, Mod) ->
[stat_ref(App, Stat, Args) || {Stat, Args} <- Stats].

stat_ref(App, Stat, Args) ->
{{App, Stat}, {riak_core_metric_proc, start_link, [App, Stat, Args]},
{{App, Stat}, {riak_core_metric_proc, start_link, [Stat, Args]},
permanent, 5000, worker, [riak_core_metric_proc]}.

remove_slide_private_dirs() ->
Expand Down
24 changes: 11 additions & 13 deletions src/riak_core_stat.erl
Expand Up @@ -26,8 +26,6 @@
%% Metrics API
-export([stat_specs/0]).

-define(APP, riak_core).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
Expand Down Expand Up @@ -59,24 +57,24 @@ get_stats(_Moment) ->
%% @doc Update the given stat
-spec update(Stat::atom()) -> ok.
update(converge_timer_begin) ->
riak_core_metric_proc:update(?APP, converge_delay, start);
riak_core_metric_proc:update(converge_delay, start);
update(converge_timer_end) ->
riak_core_metric_proc:update(?APP, converge_delay, stop);
riak_core_metric_proc:update(converge_delay, stop);
update(rebalance_timer_begin) ->
riak_core_metric_proc:update(?APP, rebalance_delay, start);
riak_core_metric_proc:update(rebalance_delay, start);
update(rebalance_timer_end) ->
riak_core_metric_proc:update(?APP, rebalance_delay, stop);
riak_core_metric_proc:update(rebalance_delay, stop);
update(rejected_handoffs) ->
riak_core_metric_proc:update(?APP, rejected_handoffs, 1);
riak_core_metric_proc:update(rejected_handoffs, 1);
update(handoff_timeouts) ->
riak_core_metric_proc:update(?APP, handoff_timeouts, 1);
riak_core_metric_proc:update(handoff_timeouts, 1);
update(ignored_gossip) ->
riak_core_metric_proc:update(?APP, ignored_gossip_totals, 1);
riak_core_metric_proc:update(ignored_gossip_totals, 1);
update(gossip_received) ->
riak_core_metric_proc:update(?APP, gossip_received, {1, slide:moment()});
riak_core_metric_proc:update(gossip_received, {1, slide:moment()});
update(rings_reconciled) ->
riak_core_metric_proc:update(?APP, rings_reconciled, {1, slide:moment()}),
riak_core_metric_proc:update(?APP, rings_reconciled_total, 1);
riak_core_metric_proc:update(rings_reconciled, {1, slide:moment()}),
riak_core_metric_proc:update(rings_reconciled_total, 1);
update(_) ->
ok.

Expand All @@ -93,7 +91,7 @@ produce_stats(Presentation) ->
%% @spec gossip_stats(integer()) -> proplist()
%% @doc Get the gossip stats proplist.
gossip_stats(Presentation) ->
GossipStats = [riak_core_metric_proc:value(?APP, Name, Presentation) || {Name, Spec} <- stat_specs(), lists:keyfind(gossip, 2, Spec) /= false],
GossipStats = [riak_core_metric_proc:value(Name, Presentation) || {Name, Spec} <- stat_specs(), lists:keyfind(gossip, 2, Spec) /= false],
lists:flatten( GossipStats ).

%% Provide aggregate stats for vnode queues. Compute instantaneously for now,
Expand Down

0 comments on commit e95a295

Please sign in to comment.