Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
We already know the metric type, so supply it directly
  • Loading branch information
chewbranca committed Aug 17, 2015
1 parent a842f3b commit 9ba5201399d8b277940d049c3d712e0f5de83c70
Showing 1 changed file with 15 additions and 16 deletions.
@@ -77,47 +77,46 @@ list() ->

-spec increment_counter(any()) -> response().
increment_counter(Name) ->
notify(Name, {inc, 1}).
notify_existing_metric(Name, {inc, 1}, counter).

-spec increment_counter(any(), pos_integer()) -> response().
increment_counter(Name, Value) ->
notify(Name, {inc, Value}).
notify_existing_metric(Name, {inc, Value}, counter).

-spec decrement_counter(any()) -> response().
decrement_counter(Name) ->
notify(Name, {dec, 1}).
notify_existing_metric(Name, {dec, 1}, counter).

-spec decrement_counter(any(), pos_integer()) -> response().
decrement_counter(Name, Value) ->
notify(Name, {dec, Value}).
notify_existing_metric(Name, {dec, Value}, counter).

-spec update_histogram(any(), number()) -> response();
(any(), function()) -> any().
update_histogram(Name, Fun) when is_function(Fun, 0) ->
Begin = os:timestamp(),
Result = Fun(),
Duration = timer:now_diff(os:timestamp(), Begin) div 1000,
case notify(Name, Duration) of
case notify_existing_metric(Name, Duration, histogram) of
ok ->
Result;
{error, unknown_metric} ->
throw({unknown_metric, Name})
end;
update_histogram(Name, Value) when is_number(Value) ->
notify(Name, Value).
notify_existing_metric(Name, Value, histogram).

-spec update_gauge(any(), number()) -> response().
update_gauge(Name, Value) ->
notify(Name, Value).

-spec notify(any(), any()) -> response().
notify(Name, Op) ->
case folsom_metrics:notify(Name, Op) of
ok ->
ok;
_ ->
couch_log:notice("unknown metric: ~p", [Name]),
{error, unknown_metric}
notify_existing_metric(Name, Value, gauge).

-spec notify_existing_metric(any(), any(), any()) -> response().
notify_existing_metric(Name, Op, Type) ->
try
ok = folsom_metrics:notify_existing_metric(Name, Op, Type)
catch _:_ ->
couch_log:notice("unknown metric: ~p", [Name]),
{error, unknown_metric}
end.

-spec sample_type(any(), atom()) -> stat().

0 comments on commit 9ba5201

Please sign in to comment.