Skip to content

Commit

Permalink
add entites.on_step metric
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Nov 22, 2020
1 parent 7d7402b commit c3a86d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions builtin/on_step.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local metric = monitoring.counter("entity_on_step_count", "Entity on_step call count")

local metric_time = monitoring.counter("entity_on_step_time", "time usage in microseconds for on_step calls")
local metric_time_max = monitoring.gauge(
"entity_on_step_time_max",
"max time usage in microseconds for on_step calls",
{ autoflush=true }
)


minetest.register_on_mods_loaded(function()
for _, entity in pairs(minetest.registered_entities) do
if type(entity.on_step) == "function" then
local old_on_step = entity.on_step
entity.on_step = function(...)
local t0 = minetest.get_us_time()
local result = old_on_step(...)
local t1 = minetest.get_us_time()

local diff = t1 - t0
metric_time.inc(diff)
metric_time_max.setmax(diff)
metric.inc()

return result
end
end
end
end)
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if not monitoring.settings.builtin_disable then
dofile(MP.."/builtin/nodetimer_calls.lua")
dofile(MP.."/builtin/on_joinplayer.lua")
dofile(MP.."/builtin/on_prejoinplayer.lua")
dofile(MP.."/builtin/on_step.lua")
dofile(MP.."/builtin/playercount.lua")
dofile(MP.."/builtin/protection_violation_count.lua")
dofile(MP.."/builtin/punchplayer.lua")
Expand Down
1 change: 1 addition & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
monitoring.prometheus_push_url (monitoring push url) string

0 comments on commit c3a86d5

Please sign in to comment.