Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ewma for day suport, add tests

  • Loading branch information...
commit 223acaf58b87c3a6bfe6f2fa0a91da0f71d7536b 1 parent a87ef8a
Petrovsky Alexander authored
View
13 src/folsom_ewma.erl
@@ -29,9 +29,10 @@
-module(folsom_ewma).
--define(M1_ALPHA, 1 - math:exp(-5 / 60.0)).
--define(M5_ALPHA, 1 - math:exp(-5 / 60.0 / 5)).
--define(M15_ALPHA, 1 - math:exp(-5 / 60.0 / 15)).
+-define(M1_ALPHA, 1 - math:exp(-5 / 60.0)).
+-define(M5_ALPHA, 1 - math:exp(-5 / 60.0 / 5)).
+-define(M15_ALPHA, 1 - math:exp(-5 / 60.0 / 15)).
+-define(D1_ALPHA, 1 - math:exp(-5 / 60.0 / 1440)).
-record(ewma, {
alpha,
@@ -47,7 +48,8 @@
tick/1,
one_minute_ewma/0,
five_minute_ewma/0,
- fifteen_minute_ewma/0]).
+ fifteen_minute_ewma/0,
+ one_day_ewma/0]).
% API
@@ -61,6 +63,9 @@ five_minute_ewma() ->
fifteen_minute_ewma() ->
new(?M15_ALPHA, 5).
+one_day_ewma() ->
+ new(?D1_ALPHA, 5).
+
new(Alpha, Interval) ->
#ewma{alpha = Alpha, interval = Interval}.
View
19 src/folsom_metrics_meter.erl
@@ -37,6 +37,7 @@
one,
five,
fifteen,
+ day,
count = 0,
start_time
}).
@@ -47,26 +48,31 @@ new(Name) ->
OneMin = folsom_ewma:one_minute_ewma(),
FiveMin = folsom_ewma:five_minute_ewma(),
FifteenMin = folsom_ewma:fifteen_minute_ewma(),
+ OneDay = folsom_ewma:one_day_ewma(),
ets:insert(?METER_TABLE,
{Name, #meter{one = OneMin,
five = FiveMin,
fifteen = FifteenMin,
+ day = OneDay,
start_time = folsom_utils:now_epoch_micro()}}).
tick(Name) ->
#meter{one = OneMin,
five = FiveMin,
- fifteen = FifteenMin} = Meter = get_value(Name),
+ fifteen = FifteenMin,
+ day = OneDay} = Meter = get_value(Name),
OneMin1 = folsom_ewma:tick(OneMin),
FiveMin1 = folsom_ewma:tick(FiveMin),
FifteenMin1 = folsom_ewma:tick(FifteenMin),
+ OneDay1 = folsom_ewma:tick(OneDay),
ets:insert(?METER_TABLE,
{Name, Meter#meter{one = OneMin1,
five = FiveMin1,
- fifteen = FifteenMin1}}).
+ fifteen = FifteenMin1,
+ day = OneDay1}}).
mark(Name) ->
mark(Name, 1).
@@ -75,21 +81,25 @@ mark(Name, Value) ->
#meter{count = Count,
one = OneMin,
five = FiveMin,
- fifteen = FifteenMin} = Meter = get_value(Name),
+ fifteen = FifteenMin,
+ day = OneDay} = Meter = get_value(Name),
OneMin1 = folsom_ewma:update(OneMin, Value),
FiveMin1 = folsom_ewma:update(FiveMin, Value),
FifteenMin1 = folsom_ewma:update(FifteenMin, Value),
+ OneDay1 = folsom_ewma:update(OneDay, Value),
ets:insert(?METER_TABLE, {Name, Meter#meter{count = Count + Value,
one = OneMin1,
five = FiveMin1,
- fifteen = FifteenMin1}}).
+ fifteen = FifteenMin1,
+ day = OneDay1}}).
get_values(Name) ->
#meter{one = OneMin,
five = FiveMin,
fifteen = FifteenMin,
+ day = OneDay,
count = Count} = Meter = get_value(Name),
L = [
@@ -97,6 +107,7 @@ get_values(Name) ->
{one, get_rate(OneMin)},
{five, get_rate(FiveMin)},
{fifteen, get_rate(FifteenMin)},
+ {day, get_rate(OneDay)},
{mean, get_mean_rate(Meter)},
{acceleration, get_acceleration(Name)}
],
View
8 test/folsom_erlang_checks.erl
@@ -183,12 +183,18 @@ check_metrics() ->
_ ->
error
end,
+ ok = case proplists:get_value(day, Meter) of
+ Value1 when Value1 > 0.005 ->
+ ok;
+ _ ->
+ error
+ end,
?debugFmt("checking meter reader~n", []),
MeterReader = folsom_metrics:get_metric_value(meter_reader),
?debugFmt("~p~n", [MeterReader]),
ok = case proplists:get_value(one, MeterReader) of
- Value1 when Value1 > 1 ->
+ Value2 when Value2 > 1 ->
ok;
_ ->
error
Please sign in to comment.
Something went wrong with that request. Please try again.