Add metrics mod
This commit is contained in:
parent
0fd9bf7a61
commit
bc1ba727eb
2 changed files with 32 additions and 0 deletions
3
mods/ctf_metrics/depends.txt
Normal file
3
mods/ctf_metrics/depends.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
ctf
|
||||
ctf_stats
|
||||
prometheus?
|
29
mods/ctf_metrics/init.lua
Normal file
29
mods/ctf_metrics/init.lua
Normal file
|
@ -0,0 +1,29 @@
|
|||
if not minetest.global_exists("prometheus") then
|
||||
return
|
||||
end
|
||||
|
||||
local kill_counter = 0
|
||||
ctf.register_on_killedplayer(function(victim, killer, type)
|
||||
kill_counter = kill_counter + 1
|
||||
end)
|
||||
|
||||
local function step()
|
||||
prometheus.post("minetest_kills", kill_counter)
|
||||
kill_counter = 0
|
||||
|
||||
local sum = 0
|
||||
local avg = 0
|
||||
if #minetest.get_connected_players() > 0 then
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local total, match = ctf_stats.player(player:get_player_name())
|
||||
sum = sum + total.score
|
||||
end
|
||||
avg = sum / #minetest.get_connected_players()
|
||||
end
|
||||
|
||||
prometheus.post("minetest_ctf_score_total", sum)
|
||||
prometheus.post("minetest_ctf_score_avg", avg)
|
||||
|
||||
minetest.after(15, step)
|
||||
end
|
||||
minetest.after(15, step)
|
Loading…
Reference in a new issue