Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
add switching station metrics (#1)
Browse files Browse the repository at this point in the history
* add switching station metrics

* remove unneeded if

* fix wrong import

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
  • Loading branch information
BuckarooBanzay and BuckarooBanzay committed May 4, 2022
1 parent e9ae72b commit ff6af94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions init.lua
Expand Up @@ -17,6 +17,9 @@ dofile(MP.."/abm.lua")
-- quarry
dofile(MP.."/quarry.lua")

-- switching station
dofile(MP.."/switch.lua")

if minetest.settings:get_bool("monitoring.technic.verbose") then
-- intercept *all* machines (may be slow!)
dofile(MP.."/technic_run.lua")
Expand Down
12 changes: 5 additions & 7 deletions quarry.lua
@@ -1,9 +1,7 @@

local quarry_node = minetest.registered_nodes["technic:quarry"]
if quarry_node ~= nil then
print("[monitoring] wrapping quarry.technic_run")
local quarry_def = minetest.registered_nodes["technic:quarry"]
assert(quarry_def)

quarry_node.technic_run = monitoring
.counter("technic_quarry_dig_count", "number of technic quarry digs")
.wrap(quarry_node.technic_run)
end
quarry_def.technic_run =
monitoring.counter("technic_quarry_dig_count", "number of technic quarry digs")
.wrap(quarry_def.technic_run)
21 changes: 21 additions & 0 deletions switch.lua
@@ -0,0 +1,21 @@
assert(type(technic.network_run) == "function")
assert(type(technic.active_networks) == "table")

technic.network_run =
monitoring.counter("technic_switching_stations_usage", "usage in microseconds cpu time")
.wraptime(technic.network_run)

local active_switching_stations_metric = monitoring.gauge(
"technic_active_switching_stations",
"Number of active switching stations"
)

local function count_stations()
local count = 0
for _ in pairs(technic.active_networks) do
count = count + 1
end
active_switching_stations_metric.set(count)
minetest.after(5, count_stations)
end
count_stations()

0 comments on commit ff6af94

Please sign in to comment.