first commit

master
Rafi59 2018-06-27 20:11:28 +02:00
commit 0bf9f15056
4 changed files with 228 additions and 0 deletions

28
README.txt Normal file
View File

@ -0,0 +1,28 @@
Munin mod
=========
This mod provide player cap, number of connected players, current max_lag and uptime into munin.txt file once per 30 seconds.
To enable this add:
munin.enabled = true
into your minetest.conf file
Directory munin-plugin contains bash and ruby version of plugin for munin monitoring.
Ruby one is more advanced as it can detect crashed minetest and put zero values into graph. Munin multigraph feature added. This feature is default off. When enabled second graph with MT uptime appears.
Licence: WTFPL
Structure of munin.txt
player cap
connected players
max_lag
uptime
generation unixtimestamp
Authors: Pitriss (munin mod) & Ritchie (munin.rb)

36
init.lua Normal file
View File

@ -0,0 +1,36 @@
local max_players = minetest.setting_get("max_users")
munin_enabled = false
if minetest.setting_getbool("munin.enabled") ~= nil then
munin_enabled = minetest.setting_getbool("munin.enabled")
end
local last_time = os.time() + 5
function munin_write(status, path)
local file_desc = io.open(path, "w")
file_desc:write(status.."\n")
file_desc:close()
end
if munin_enabled then
minetest.register_globalstep(function(dtime)
if os.time() >= last_time then
last_time = os.time() + 30
if max_players == nil then
local max_players = 100
end
local players = minetest.get_connected_players()
local player_count = table.getn(players)
local status = minetest.get_server_status()
local status_splitted = {}
for k, v in string.gmatch(status, "([_%w]+)=([%+%w%.]+)") do
status_splitted[k] = v
end
local uptime = status_splitted.uptime
local max_lag = status_splitted.max_lag
local status_to_write = max_players.."\n"..player_count.."\n"..max_lag.."\n"..uptime.."\n"..tostring(os.time())
local fpath = minetest.get_worldpath().."/munin.txt"
munin_write(status_to_write, fpath)
end
end)
end

102
munin-plugin/minetest.rb Normal file
View File

@ -0,0 +1,102 @@
#!/usr/bin/ruby
##################################
# MT monitoring plugin for munin #
# Author: Pitriss & Ritchie #
# Licence: WTFPL #
##################################
# Some config
datafile = ""
worldname = ""
# graph uptime of minetestserver? Multigraph feature will be used. http://munin-monitoring.org/wiki/MultigraphSampleOutput
uptime = "no"
# maximum value of maxlag. It prevents to make your graph unreadable when some huge peak appears.
maxlag_maximum = 100
# Maximal possible delay between value in munin.txt and server time in seconds
# Formula is: servertime - (MTserverstartuptime + MTserveruptime)
# MTserver should log every 30s
max_delay = 60
# colors
color1 = "6DFF90"
color2 = "FF0000"
color3 = "0066B3"
color4 = "00CC00"
# Not needed to change anything below this comment
if ARGV[0] == "config"
if uptime == "yes"
puts "multigraph minetest_players"
end
puts "graph_title Minetest server - #{worldname}"
puts "graph_category minetest"
puts "graph_info this graph shows information provided by munin mod"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel Players | Lag"
puts "PlayerCap.label Player cap"
puts "PlayerCap.draw AREA"
puts "PlayerCap.colour #{color1}"
puts "PlayersConnected.label Connected players"
puts "PlayersConnected.draw AREA"
puts "PlayersConnected.colour #{color2}"
puts "MaxLag.label Maximal lag"
puts "MaxLag.draw LINE"
puts "MaxLag.colour #{color3}"
if uptime == "yes"
puts "multigraph minetest_uptime"
puts "graph_title Minetest server - #{worldname}"
puts "graph_category minetest"
puts "graph_info this graph shows information provided by munin mod"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel Uptime in days"
puts "Uptime.label Uptime"
puts "Uptime.draw AREA"
puts "Uptime.colour #{color4}"
end
elsif ARGV[0] == "debug"
begin
content = IO.readlines(datafile)
offset = Time.now.to_i-content[4].to_i
puts "Max delay is now: #{offset} second(s)"
rescue Errno::ENOENT
puts "ERROR: Misconfigured path to munin.txt or munin.txt doesn't exist."
rescue
puts "ERROR: Unknown error"
end
else
content = IO.readlines(datafile)
offset = Time.now.to_i-content[4].to_i
if offset > max_delay
if uptime == "yes"
puts "multigraph minetest_players"
end
puts "PlayerCap.value 0"
puts "PlayersConnected.value 0"
puts "MaxLag.value 0"
if uptime == "yes"
puts "multigraph minetest_uptime"
puts "Uptime.value 0"
end
else
if uptime == "yes"
puts "multigraph minetest_players"
end
puts "PlayerCap.value #{content[0]}"
puts "PlayersConnected.value #{content[1]}"
if content[2].to_f > maxlag_maximum then
maxlag_value = maxlag_maximum.to_s
else
maxlag_value = content[2].to_s
end
puts "MaxLag.value #{maxlag_value}"
if uptime == "yes"
uptime_mt = content[3].to_f
uptime_mt_day = uptime_mt / 86400
puts "multigraph minetest_uptime"
puts "Uptime.value #{uptime_mt_day}"
end
end
end

62
munin-plugin/minetest.sh Normal file
View File

@ -0,0 +1,62 @@
#!/bin/bash
##################################
# MT monitoring plugin for munin #
# Author: Pitriss & Ritchie #
# Licence: WTFPL #
##################################
# Path to munin.txt
WORLDFILE="/home/axinite/.minetest/worlds/axinite/munin.txt"
# Name of world displayed in graph title
WORLDNAME="Axinite"
if [ "$1" = "config" ] ; then
echo "graph_title Minetest server - $WORLDNAME"
echo "graph_category minetest"
echo "graph_info this graph shows information provided by munin mod"
echo 'graph_args --base 1000 -l 0 '
echo "PlayerCap.label Player cap"
echo "PlayerCap.draw AREA"
echo "PlayerCap.colour 6DFF90"
echo "PlayersConnected.label Connected players"
echo "PlayersConnected.draw AREA"
echo "PlayersConnected.colour FF0000"
echo "MaxLag.label Maximal lag"
echo "MaxLag.draw LINE"
echo "MaxLag.colour 0066B3"
## Uptime is commented out, because high
## numbers will break whole graph
# echo "Uptime.label Uptime"
# echo "Uptime.draw LINE"
else
COUNT=0
while read LINE; do
case $COUNT in
0)
echo "PlayerCap.value $LINE"
COUNT=$((COUNT+1))
;;
1)
echo "PlayersConnected.value $LINE"
COUNT=$((COUNT+1))
;;
2)
echo "MaxLag.value $LINE"
COUNT=$((COUNT+1))
;;
## Uptime is commented out, because high
## numbers will break whole graph
# 3)
# echo "Uptime.value $LINE"
# COUNT=$((COUNT+1))
# ;;
esac
done <$WORLDFILE
fi