Skip to content

Commit

Permalink
add monitoring metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Jun 14, 2022
1 parent ba3ae44 commit e9ac279
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ read_globals = {
-- Minetest
"vector", "ItemStack",
"dump", "dump2",
"VoxelArea"
"VoxelArea",

-- deps
"monitoring"
}
8 changes: 8 additions & 0 deletions bridge_rx.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
local http = ...

local metric
if minetest.get_modpath("monitoring") then
metric = monitoring.counter("mtui_rx", "number of received commands")
end

local command_handlers = {}

function mtui.register_on_command(type, handler)
Expand All @@ -20,6 +25,9 @@ local function fetch_commands()
local command_list = minetest.parse_json(res.data)

for _, cmd in ipairs(command_list) do
if metric then
metric.inc()
end
local handler = command_handlers[cmd.type]
if type(handler) == "function" then
local send = function(data)
Expand Down
6 changes: 6 additions & 0 deletions bridge_tx.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
local http = ...

local metric
if minetest.get_modpath("monitoring") then
metric = monitoring.counter("mtui_tx", "number of sent commands")
end

-- list of commands to send
local commands = {}

Expand Down Expand Up @@ -30,6 +35,7 @@ end

-- queues a command to send to the ui
function mtui.send_command(cmd)
metric.inc()
table.insert(commands, cmd)

if not send_triggered then
Expand Down
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = mtui
optional_depends = mail
optional_depends = mail, monitoring

0 comments on commit e9ac279

Please sign in to comment.