Skip to content

Commit

Permalink
Add new timed update begin/notify functions
Browse files Browse the repository at this point in the history
  • Loading branch information
puzza007 committed Dec 5, 2012
1 parent 2556e38 commit d68bb19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/folsom_metrics.erl
Expand Up @@ -55,7 +55,9 @@
get_history_values/2, get_history_values/2,
histogram_timed_update/2, histogram_timed_update/2,
histogram_timed_update/3, histogram_timed_update/3,
histogram_timed_update/4 histogram_timed_update/4,
histogram_timed_begin/1,
histogram_timed_notify/1
]). ]).


-include("folsom.hrl"). -include("folsom.hrl").
Expand Down Expand Up @@ -163,3 +165,11 @@ histogram_timed_update(Name, Mod, Fun, Args) ->
{Time, Value} = timer:tc(Mod, Fun, Args), {Time, Value} = timer:tc(Mod, Fun, Args),
ok = notify({Name, Time}), ok = notify({Name, Time}),
Value. 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}).
12 changes: 10 additions & 2 deletions test/folsom_erlang_checks.erl
Expand Up @@ -56,6 +56,7 @@ create_metrics() ->
ok = folsom_metrics:new_histogram(nonea, none, 5000), ok = folsom_metrics:new_histogram(nonea, none, 5000),


ok = folsom_metrics:new_histogram(timed, 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_history(<<"history">>),
ok = folsom_metrics:new_meter(meter), ok = folsom_metrics:new_meter(meter),
Expand All @@ -81,7 +82,7 @@ create_metrics() ->
%% check a server got started for the spiral metric %% check a server got started for the spiral metric
1 = length(supervisor:which_children(folsom_sample_slide_sup)), 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()]). ?debugFmt("~n~nmetrics: ~p~n", [folsom_metrics:get_metrics()]).


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


3.141592653589793 = folsom_metrics:histogram_timed_update(timed, math, pi, []), 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() -> PopulateDuration = fun() ->
ok = folsom_metrics:notify_existing_metric(duration, timer_start, duration), ok = folsom_metrics:notify_existing_metric(duration, timer_start, duration),
timer:sleep(10), timer:sleep(10),
Expand Down Expand Up @@ -171,6 +175,9 @@ check_metrics() ->
List = folsom_metrics:get_metric_value(timed), List = folsom_metrics:get_metric_value(timed),
?debugFmt("timed update value: ~p", [List]), ?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(<<"history">>)),
1 = length(folsom_metrics:get_metric_value(historya)), 1 = length(folsom_metrics:get_metric_value(historya)),


Expand Down Expand Up @@ -209,7 +216,7 @@ check_metrics() ->




delete_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(counter),
ok = folsom_metrics:delete_metric(<<"gauge">>), ok = folsom_metrics:delete_metric(<<"gauge">>),
Expand All @@ -224,6 +231,7 @@ delete_metrics() ->


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


ok = ensure_meter_tick_exists(2), ok = ensure_meter_tick_exists(2),
Expand Down

0 comments on commit d68bb19

Please sign in to comment.