capturetheflag/mods/ctf/ctf_metrics/init.lua

45 lines
1.1 KiB
Lua
Raw Normal View History

2017-11-07 01:20:34 +00:00
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
2019-01-11 19:01:49 +00:00
local bins = { r050=0, r200=0, r5000=0, rest=0 }
2017-11-07 01:20:34 +00:00
if #minetest.get_connected_players() > 0 then
for _, player in pairs(minetest.get_connected_players()) do
local total, _ = ctf_stats.player(player:get_player_name())
2017-11-07 01:20:34 +00:00
sum = sum + total.score
2019-01-11 16:29:36 +00:00
if total.score > 174000 then
2019-01-11 19:01:49 +00:00
bins.r050 = bins.r050 + 1
2019-01-11 16:29:36 +00:00
elseif total.score > 10000 then
2019-01-11 19:01:49 +00:00
bins.r200 = bins.r200 + 1
2019-01-11 16:29:36 +00:00
elseif total.score > 1000 then
2019-01-11 19:01:49 +00:00
bins.r5000 = bins.r5000 + 1
2019-01-11 16:29:36 +00:00
else
bins.rest = bins.rest + 1
end
2017-11-07 01:20:34 +00:00
end
avg = sum / #minetest.get_connected_players()
end
2019-01-11 16:29:36 +00:00
for key, value in pairs(bins) do
prometheus.post("minetest_ctf_score_bins{rank=\"" .. key .. "\"}", value)
end
2017-11-07 01:20:34 +00:00
prometheus.post("minetest_ctf_score_total", sum)
prometheus.post("minetest_ctf_score_avg", avg)
minetest.after(15, step)
end
minetest.after(15, step)