2013-03-30 01:11:08 +01:00
|
|
|
#!/bin/bash
|
2018-07-11 19:14:18 +02:00
|
|
|
|
|
|
|
: <<=cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
minecraft-users-ram_ - monitor ressource usage of a local minecraft server
|
|
|
|
|
|
|
|
=head1 APPLICABLE SYSTEMS
|
|
|
|
|
|
|
|
Every system with a running minecraft server.
|
|
|
|
|
|
|
|
|
|
|
|
=head1 USAGE
|
|
|
|
|
|
|
|
Symlink this plugin to /etc/munin/plugins/ by adding the TCP port number used
|
|
|
|
by the local mincecraft server. Afterwards restart the munin-node.
|
|
|
|
|
|
|
|
Some more instructions: http://wiki.natenom.name/minecraft/munin-plugin
|
|
|
|
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
2011 Natenom
|
|
|
|
2017 Leandro Späth
|
|
|
|
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=manual
|
|
|
|
#%# capabilities=
|
|
|
|
|
|
|
|
=cut
|
2013-03-30 01:11:08 +01:00
|
|
|
|
|
|
|
LC_LANG=C
|
|
|
|
MC_PORT=${0##*_}
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]
|
|
|
|
then
|
|
|
|
printf 'graph_title Minecraft-Server (Port %s)\n' ${MC_PORT}
|
2017-02-21 17:11:23 +01:00
|
|
|
printf 'graph_category games'
|
2016-06-27 02:41:34 +02:00
|
|
|
printf 'graph_scale no\n'
|
|
|
|
printf 'graph_vlabel Players / RAM / CPU\n'
|
|
|
|
printf 'users.label Players\n'
|
|
|
|
printf 'ramusage.label RAM usage in GiB\n'
|
|
|
|
printf 'cpuusage.label CPU usage\n'
|
2013-03-30 01:11:08 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
PLAYERCOUNT=$(netstat -tn | grep -i ${MC_PORT} | grep ESTABLISHED | wc -l)
|
|
|
|
MC_PID=$(netstat -tlpn | grep ${MC_PORT} | sed -n -e '1p' | awk '{ print $7 }' | cut -d'/' -f1)
|
|
|
|
if [ ! -z "${MC_PID}" ]
|
|
|
|
then #is running
|
|
|
|
MEMORYRSS=$(ps -p ${MC_PID} -o rss | cut -d'
|
|
|
|
' -f2)
|
|
|
|
MEMGiB=$(echo "scale=2;${MEMORYRSS}/1024/1024" | bc -l)
|
2016-06-29 17:38:42 +02:00
|
|
|
CPUPERCENT=$(top -bp ${MC_PID} -n 1 | sed -n '$p' | tr -s ' ' | cut -d ' ' -f10)
|
2016-06-27 02:41:34 +02:00
|
|
|
CPU=$(echo "scale=2;${CPUPERCENT}/100" | bc -l)
|
2013-03-30 01:11:08 +01:00
|
|
|
else
|
|
|
|
MEMGiB=0
|
2016-06-27 02:41:34 +02:00
|
|
|
CPU=0
|
2013-03-30 01:11:08 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
printf "users.value %i\n" "${PLAYERCOUNT}"
|
|
|
|
printf "ramusage.value %3.2f\n" "${MEMGiB}"
|
2016-06-27 02:41:34 +02:00
|
|
|
printf "cpuusage.value %3.2f\n" "${CPU}"
|