Добавлена оперативная и историческая статистика нод и узлов mnesia #22
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
-module(core_counters).
|
||||
-export([inc/1, dec/1, get/1, read_and_reset/1]).
|
||||
|
||||
-define(TABLE, eventhub_counters).
|
||||
|
||||
inc(Key) ->
|
||||
try ets:update_counter(?TABLE, Key, {2, 1}) % позиция 2 — значение
|
||||
catch error:badarg ->
|
||||
ets:insert(?TABLE, {Key, 1})
|
||||
end.
|
||||
|
||||
dec(Key) ->
|
||||
try ets:update_counter(?TABLE, Key, {2, -1})
|
||||
catch error:badarg ->
|
||||
ets:insert(?TABLE, {Key, 0})
|
||||
end.
|
||||
|
||||
get(Key) ->
|
||||
case ets:lookup(?TABLE, Key) of
|
||||
[{Key, Val}] -> Val;
|
||||
[] -> 0
|
||||
end.
|
||||
|
||||
read_and_reset(Key) ->
|
||||
case ets:lookup(?TABLE, Key) of
|
||||
[{Key, Val}] ->
|
||||
ets:insert(?TABLE, {Key, 0}),
|
||||
Val;
|
||||
[] -> 0
|
||||
end.
|
||||
Reference in New Issue
Block a user