Skip to content
Permalink
Browse files
Merge pull request #60 from puzza007/safe-histogram
Add safe histogram notify functions
  • Loading branch information
joewilliams committed Jun 12, 2013
2 parents 3732005 + 31a348b commit e9be9f7fb35e2ff7ea451372ec8a12495677a3bb
Showing 2 changed files with 31 additions and 1 deletion.
@@ -64,7 +64,11 @@
histogram_timed_update/3,
histogram_timed_update/4,
histogram_timed_begin/1,
histogram_timed_notify/1
histogram_timed_notify/1,
safely_histogram_timed_update/2,
safely_histogram_timed_update/3,
safely_histogram_timed_update/4,
safely_histogram_timed_notify/1
]).

-include("folsom.hrl").
@@ -201,3 +205,24 @@ histogram_timed_notify({Name, Begin}) ->
Now = os:timestamp(),
Time = timer:now_diff(Now, Begin),
ok = notify({Name, Time}).

safely_histogram_timed_update(Name, Fun) ->
{Time, Value} = timer:tc(Fun),
_ = safely_notify({Name, Time}),
Value.

safely_histogram_timed_update(Name, Fun, Args) ->
{Time, Value} = timer:tc(Fun, Args),
_ = safely_notify({Name, Time}),
Value.

safely_histogram_timed_update(Name, Mod, Fun, Args) ->
{Time, Value} = timer:tc(Mod, Fun, Args),
_ = safely_notify({Name, Time}),
Value.

safely_histogram_timed_notify({Name, Begin}) ->
Now = os:timestamp(),
Time = timer:now_diff(Now, Begin),
_ = safely_notify({Name, Time}),
ok.
@@ -109,6 +109,11 @@ populate_metrics() ->
meck:new(folsom_ets),
meck:expect(folsom_ets, notify, fun(_Event) -> meck:exception(error, something_wrong_with_ets) end),
{'EXIT', {something_wrong_with_ets, _}} = folsom_metrics:safely_notify({unknown_counter, {inc, 1}}),
ok = folsom_metrics:safely_histogram_timed_update(unknown_histogram, fun() -> ok end),
ok = folsom_metrics:safely_histogram_timed_update(unknown_histogram, fun(ok) -> ok end, [ok]),
3.141592653589793 = folsom_metrics:safely_histogram_timed_update(unknown_histogram, math, pi, []),
UnknownHistogramBegin = folsom_metrics:histogram_timed_begin(unknown_histogram),
ok = folsom_metrics:safely_histogram_timed_notify(UnknownHistogramBegin),
meck:unload(folsom_ets),

ok = folsom_metrics:notify({<<"gauge">>, 2}),

0 comments on commit e9be9f7

Please sign in to comment.