From bc1ba727ebfca9dfe42d7dff53c459340a8f5044 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 7 Nov 2017 01:20:34 +0000 Subject: [PATCH] Add metrics mod --- mods/ctf_metrics/depends.txt | 3 +++ mods/ctf_metrics/init.lua | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 mods/ctf_metrics/depends.txt create mode 100644 mods/ctf_metrics/init.lua diff --git a/mods/ctf_metrics/depends.txt b/mods/ctf_metrics/depends.txt new file mode 100644 index 0000000..665282e --- /dev/null +++ b/mods/ctf_metrics/depends.txt @@ -0,0 +1,3 @@ +ctf +ctf_stats +prometheus? diff --git a/mods/ctf_metrics/init.lua b/mods/ctf_metrics/init.lua new file mode 100644 index 0000000..4ba4c9d --- /dev/null +++ b/mods/ctf_metrics/init.lua @@ -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)