Exast is an extremely fast erlang statistics library for simplest cases.
Data types:
- name()
- term()
- frame_length()
- pos_integer() (sec or count)
- value()
- integer() or term() for ‘gauge’
Name | Args | Desc |
---|---|---|
new_tsma/2 | name(), frame_length() | Register new time-limited simple moving average with FL sec length |
new_ssma/2 | name(), frame_length() | Register new size-limited simple moving average with FL maximum number of entries |
new_cma/1 | name() | Register new cumulative moving average |
new_gauge/1 | name() | Register new gauge |
new_counter/1 | name() | Register new counter |
new_meter/1 | name() | Register combined metric with 4 ‘rate’ - ‘one’, ‘five’, ‘fifteen’, ‘day’ |
notify/2 | name(), value() | Add value() to metric, or set in case of gauge |
get/0 | Retern all metrics with values | |
get/1 | name() | Retrun value |
delete/1 | name() | Remove metric |
new_rate/2 | name(), frame_length() | Register new periodic nullable counter to measure rate |
1> exast:new_ssma(test, 5).
ok
2> exast:get(test).
0.0
3> exast:notify(test, 10).
4> exast:get(test).
2.0 %% (10 + 0 + 0 + 0 + 0) / 5 == 2.0
5> exast:notify(test, 20).
6> exast:notify(test, 30).
7> exast:notify(test, 40).
8> exast:notify(test, 50).
9> exast:get(test).
30.0 %% (10 + 20 + 30 + 40 + 50) / 5 == 30.0
10> exast:notify(test, 0).
11> exast:get(test).
28.0 %% (20 + 30 + 40 + 50 + 0) / 5 == 28.0
12> FL = 10, ok = exast:new_rate(N, FL).
13> WorkerF = fun Loop()-> exast:notify(N, 10), timer:sleep(500), Loop() end.
14> ExpextedRate = 20.0.
15> MinRate = ExpextedRate - (ExpextedRate / FL). % rate, as any time-limited datatype have precision 1/FL
16> Worker1 = spawn(WorkerF), timer:sleep(FL * 1100). % because last seconds data can be dpoped just before call 'get/1'
17> Rate0 = exast:get(N).
18> Rate0 >= MinRate and Rate0 =< ExpextedRate.
true
19> Worker2 = spawn(WorkerF),timer:sleep(FL * 1100).
20> Rate1 = exast:get(N).
21> Rate1 >= 2*MinRate and Rate1 =< 2*ExpextedRate.
true
22> exit(Worker1, kill), exit(Worker2, kill), timer:sleep(FL * 1100).
23> exast:get(N)
0.0