Skip to content

Loading…

Expose the clear/1 fun from counter in the folsom api #46

Merged
merged 1 commit into from

2 participants

@russelldb

No description provided.

@joewilliams joewilliams merged commit 4239920 into boundary:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2013
  1. @russelldb

    Expose the clear/1 fun from counter in the folsom api

    russelldb committed
    Conflicts:
    	test/folsom_erlang_checks.erl
Showing with 20 additions and 2 deletions.
  1. +7 −0 src/folsom_ets.erl
  2. +13 −2 test/folsom_erlang_checks.erl
View
7 src/folsom_ets.erl
@@ -313,6 +313,13 @@ notify(Name, {dec, Value}, counter, false) ->
add_handler(counter, Name),
folsom_metrics_counter:dec(Name, Value),
ok;
+notify(Name, clear, counter, true) ->
+ folsom_metrics_counter:clear(Name),
+ ok;
+notify(Name, clear, counter, false) ->
+ add_handler(counter, Name),
+ folsom_metrics_counter:clear(Name),
+ ok;
notify(Name, Value, gauge, true) ->
folsom_metrics_gauge:update(Name, Value),
ok;
View
15 test/folsom_erlang_checks.erl
@@ -45,6 +45,7 @@
create_metrics() ->
ok = folsom_metrics:new_counter(counter),
+ ok = folsom_metrics:new_counter(counter2),
ok = folsom_metrics:new_gauge(<<"gauge">>),
ok = folsom_metrics:new_histogram(<<"uniform">>, uniform, 5000),
@@ -80,7 +81,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()]).
@@ -88,6 +89,9 @@ populate_metrics() ->
ok = folsom_metrics:notify({counter, {inc, 1}}),
ok = folsom_metrics:notify({counter, {dec, 1}}),
+ ok = folsom_metrics:notify({counter2, {inc, 10}}),
+ ok = folsom_metrics:notify({counter2, {dec, 7}}),
+
ok = folsom_metrics:notify({<<"gauge">>, 2}),
[ok = folsom_metrics:notify({<<"uniform">>, Value}) || Value <- ?DATA],
@@ -141,6 +145,12 @@ populate_metrics() ->
check_metrics() ->
0 = folsom_metrics:get_metric_value(counter),
+ 3 = folsom_metrics:get_metric_value(counter2),
+
+ ok = folsom_metrics:notify_existing_metric(counter2, clear, counter),
+
+ 0 = folsom_metrics:get_metric_value(counter2),
+
2 = folsom_metrics:get_metric_value(<<"gauge">>),
Histogram1 = folsom_metrics:get_histogram_statistics(<<"uniform">>),
@@ -202,9 +212,10 @@ 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(counter2),
ok = folsom_metrics:delete_metric(<<"gauge">>),
ok = folsom_metrics:delete_metric(<<"hugedata">>),
Something went wrong with that request. Please try again.