Добавлена оперативная и историческая статистика нод и узлов mnesia #22

This commit is contained in:
2026-05-28 18:59:21 +03:00
parent 29fe0386be
commit f507d08e2c
16 changed files with 753 additions and 201 deletions
+30
View File
@@ -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.