root / plugins / minecraft / minecraft-users-ram_ @ 1977235f
Historique | Voir | Annoter | Télécharger (1,37 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
|
| 3 |
: <<=cut |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
minecraft-users-ram_ - monitor resource usage of a local minecraft server |
| 8 |
|
| 9 |
=head1 APPLICABLE SYSTEMS |
| 10 |
|
| 11 |
Every system with a running minecraft server. |
| 12 |
|
| 13 |
|
| 14 |
=head1 USAGE |
| 15 |
|
| 16 |
Symlink this plugin to /etc/munin/plugins/ by adding the TCP port number used |
| 17 |
by the local mincecraft server. Afterwards restart the munin-node. |
| 18 |
|
| 19 |
Some more instructions: http://wiki.natenom.name/minecraft/munin-plugin |
| 20 |
|
| 21 |
|
| 22 |
=head1 AUTHOR |
| 23 |
|
| 24 |
2011 Natenom |
| 25 |
2017 Leandro Späth |
| 26 |
|
| 27 |
|
| 28 |
=head1 MAGIC MARKERS |
| 29 |
|
| 30 |
#%# family=manual |
| 31 |
#%# capabilities= |
| 32 |
|
| 33 |
=cut |
| 34 |
|
| 35 |
|
| 36 |
MC_PORT=${0##*_}
|
| 37 |
|
| 38 |
if [ "$1" = "config" ] |
| 39 |
then |
| 40 |
echo "graph_title Minecraft-Server (Port $MC_PORT)" |
| 41 |
echo 'graph_category games' |
| 42 |
echo 'graph_scale no' |
| 43 |
echo 'graph_vlabel Players / RAM / CPU' |
| 44 |
echo 'users.label Players' |
| 45 |
echo 'ramusage.label RAM usage in GiB' |
| 46 |
echo 'cpuusage.label CPU usage in %' |
| 47 |
exit 0 |
| 48 |
fi |
| 49 |
|
| 50 |
PLAYERCOUNT=$(LANG=en LC_LANG=C netstat -tn | grep "\:$MC_PORT " | grep -c "ESTABLISHED") |
| 51 |
MC_PID=$(netstat -tlpn | grep ":$MC_PORT " | sed -n -e '1p' | awk '{ print $7 }' | cut -d '/' -f1 | grep -v '-')
|
| 52 |
if [ -n "${MC_PID}" ]
|
| 53 |
then #is running |
| 54 |
MEMGiB=$(ps -p "$MC_PID" -o rss | sed -n '2p' | awk '{ print $1 / 1024 / 1024 }')
|
| 55 |
CPU=$(ps -p "$MC_PID" -o pcpu | sed -n '2p' | awk '{ print $1 }')
|
| 56 |
else |
| 57 |
MEMGiB="U" |
| 58 |
CPU="U" |
| 59 |
fi |
| 60 |
|
| 61 |
echo "users.value $PLAYERCOUNT" |
| 62 |
echo "ramusage.value $MEMGiB" |
| 63 |
echo "cpuusage.value $CPU" |
