Skip to content
Permalink
Browse files
Add new timed update begin/notify functions
  • Loading branch information
puzza007 committed Dec 5, 2012
1 parent 2556e38 commit d68bb193d3502f339588de996e019ea611075086
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
@@ -55,7 +55,9 @@
get_history_values/2,
histogram_timed_update/2,
histogram_timed_update/3,
histogram_timed_update/4
histogram_timed_update/4,
histogram_timed_begin/1,
histogram_timed_notify/1
]).

-include("folsom.hrl").
@@ -163,3 +165,11 @@ histogram_timed_update(Name, Mod, Fun, Args) ->
{Time, Value} = timer:tc(Mod, Fun, Args),
ok = notify({Name, Time}),
Value.

histogram_timed_begin(Name) ->
{Name, os:timestamp()}.

histogram_timed_notify({Name, Begin}) ->
Now = os:timestamp(),
Time = timer:now_diff(Now, Begin),
ok = notify({Name, Time}).
@@ -56,6 +56,7 @@ create_metrics() ->
ok = folsom_metrics:new_histogram(nonea, none, 5000),

ok = folsom_metrics:new_histogram(timed, none, 5000),
ok = folsom_metrics:new_histogram(timed2, none, 5000),

ok = folsom_metrics:new_history(<<"history">>),
ok = folsom_metrics:new_meter(meter),
@@ -81,7 +82,7 @@ create_metrics() ->
%% check a server got started for the spiral metric
1 = length(supervisor:which_children(folsom_sample_slide_sup)),

13 = length(folsom_metrics:get_metrics()),
14 = length(folsom_metrics:get_metrics()),

?debugFmt("~n~nmetrics: ~p~n", [folsom_metrics:get_metrics()]).

@@ -103,6 +104,9 @@ populate_metrics() ->

3.141592653589793 = folsom_metrics:histogram_timed_update(timed, math, pi, []),

Begin = folsom_metrics:histogram_timed_begin(timed2),
folsom_metrics:histogram_timed_notify(Begin),

PopulateDuration = fun() ->
ok = folsom_metrics:notify_existing_metric(duration, timer_start, duration),
timer:sleep(10),
@@ -171,6 +175,9 @@ check_metrics() ->
List = folsom_metrics:get_metric_value(timed),
?debugFmt("timed update value: ~p", [List]),

List2 = folsom_metrics:get_metric_value(timed2),
?debugFmt("timed update value begin/end: ~p", [List2]),

1 = length(folsom_metrics:get_metric_value(<<"history">>)),
1 = length(folsom_metrics:get_metric_value(historya)),

@@ -209,7 +216,7 @@ check_metrics() ->


delete_metrics() ->
15 = length(ets:tab2list(?FOLSOM_TABLE)),
16 = length(ets:tab2list(?FOLSOM_TABLE)),

ok = folsom_metrics:delete_metric(counter),
ok = folsom_metrics:delete_metric(<<"gauge">>),
@@ -224,6 +231,7 @@ delete_metrics() ->

ok = folsom_metrics:delete_metric(nonea),
ok = folsom_metrics:delete_metric(timed),
ok = folsom_metrics:delete_metric(timed2),
ok = folsom_metrics:delete_metric(testcounter),

ok = ensure_meter_tick_exists(2),

0 comments on commit d68bb19

Please sign in to comment.