Skip to content

Commit

Permalink
integrated exometer
Browse files Browse the repository at this point in the history
  • Loading branch information
uwiger committed Jun 17, 2014
1 parent f954548 commit 2aa8e34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
35 changes: 12 additions & 23 deletions src/riak_core_stat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,13 @@ start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).

register_stats() ->
register_stats(?APP, stats()).
[(catch exometer_entry:delete([?APP,Name])) || {Name,_} <- stats()],
[register_stat({?APP, Name}, Type) || {Name, Type} <- stats()],
riak_core_stat_cache:register_app(?APP, {?MODULE, produce_stats, []}).

%% @spec register_stats(App, Stats) -> ok
%% @doc (Re-)Register a list of metrics for App.
register_stats(App, Stats) ->
P = prefix(),
lists:foreach(fun(Stat) ->
register_stat_(P, App, Stat)
end, Stats).

register_stat_(P, App, Stat) ->
{Name, Type, Opts} = case Stat of
{N, T} -> {N, T, []};
{N, T, Os} -> {N, T, Os}
end,
exometer:re_register(stat_name(P,App,Name), Type, Opts).

stat_name(P, App, N) when is_atom(N) ->
[P, App, N];
stat_name(P, App, N) when is_list(N) ->
[P, App | N].
%% [(catch folsom_metrics:delete_metric({?APP, Name})) || {Name, _Type} <- stats()],
%% [register_stat({?APP, Name}, Type) || {Name, Type} <- stats()],
%% riak_core_stat_cache:register_app(?APP, {?MODULE, produce_stats, []}).

%% @spec get_stats() -> proplist()
%% @doc Get the current aggregation of stats.
Expand Down Expand Up @@ -120,7 +106,6 @@ update_value(converge_timer_end) -> timer_begin;
update_value(rebalance_timer_end) -> timer_begin;
update_value(_) -> 1.


%% private
stats() ->
[{ignored_gossip_total, counter},
Expand All @@ -130,8 +115,12 @@ stats() ->
{handoff_timeouts, counter},
{dropped_vnode_requests_total, counter},
{converge_delay, duration},
{rebalance_delay, duration}
].
{rebalance_delay, duration}].

register_stat(Name, Type) when is_tuple(Name) ->
exometer_entry:new(tuple_to_list(Name), Type);
register_stat(Name, Type) when is_list(Name) ->
exometer_entry:new(Name, Type).

gossip_stats() ->
lists:flatten([backwards_compat(Stat, Type, riak_core_stat_q:calc_stat({{?APP, Stat}, Type})) ||
Expand Down
14 changes: 9 additions & 5 deletions src/riak_core_stat_q.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@
-spec get_stats(path()) -> stats().
get_stats(Path) ->
%% get all the stats that are at Path
calculate_stats(exometer:select(
[{ {Path ++ '_','_',enabled}, [], ['$_'] }])).
NamesNTypes = names_and_types(Path),
calculate_stats(NamesNTypes).

%% @doc queries folsom's metrics table for stats that match our path
names_and_types(Path) ->
exometer_entry:find_entries(Path).

calculate_stats(NamesAndTypes) ->
[{Name, get_stat(Name)} || {Name, _, _} <- NamesAndTypes].
Expand All @@ -70,12 +74,12 @@ get_stat(Stat) ->
%% broken it stays that way. Should we delete
%% stats that are broken?
calc_stat({Name, _Type}) when is_tuple(Name) ->
stat_return(exometer:get_value(tuple_to_list(Name)));
stat_return(exometer_entry:get_value(tuple_to_list(Name)));
calc_stat({[_|_] = Name, _Type}) ->
stat_return(exometer:get_value(Name)).
stat_return(exometer_entry:get_value(Name)).

stat_return({error,not_found}) -> unavailable;
stat_return({ok, Value}) -> Value.
stat_return(Value) -> Value.

log_error(StatName, ErrClass, ErrReason) ->
lager:warning("Failed to calculate stat ~p with ~p:~p", [StatName, ErrClass, ErrReason]).
Expand Down

0 comments on commit 2aa8e34

Please sign in to comment.