root / plugins / minecraft / minecraft-users-ram_ @ 99a5c384
Historique | Voir | Annoter | Télécharger (1,2 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# I'm not the author, just wanted to add this plugin to github |
| 3 |
# Author & instructions: http://wiki.natenom.name/minecraft/munin-plugin |
| 4 |
# CPU usage update and translation by Leandro Späth (https://github.com/LeoDJ) |
| 5 |
|
| 6 |
LC_LANG=C |
| 7 |
MC_PORT=${0##*_}
|
| 8 |
|
| 9 |
if [ "$1" = "config" ] |
| 10 |
then |
| 11 |
printf 'graph_title Minecraft-Server (Port %s)\n' ${MC_PORT}
|
| 12 |
printf 'graph_category games' |
| 13 |
printf 'graph_scale no\n' |
| 14 |
printf 'graph_vlabel Players / RAM / CPU\n' |
| 15 |
printf 'users.label Players\n' |
| 16 |
printf 'ramusage.label RAM usage in GiB\n' |
| 17 |
printf 'cpuusage.label CPU usage\n' |
| 18 |
exit 0 |
| 19 |
fi |
| 20 |
|
| 21 |
PLAYERCOUNT=$(netstat -tn | grep -i ${MC_PORT} | grep ESTABLISHED | wc -l)
|
| 22 |
MC_PID=$(netstat -tlpn | grep ${MC_PORT} | sed -n -e '1p' | awk '{ print $7 }' | cut -d'/' -f1)
|
| 23 |
if [ ! -z "${MC_PID}" ]
|
| 24 |
then #is running |
| 25 |
MEMORYRSS=$(ps -p ${MC_PID} -o rss | cut -d'
|
| 26 |
' -f2) |
| 27 |
MEMGiB=$(echo "scale=2;${MEMORYRSS}/1024/1024" | bc -l)
|
| 28 |
CPUPERCENT=$(top -bp ${MC_PID} -n 1 | sed -n '$p' | tr -s ' ' | cut -d ' ' -f10)
|
| 29 |
CPU=$(echo "scale=2;${CPUPERCENT}/100" | bc -l)
|
| 30 |
else |
| 31 |
MEMGiB=0 |
| 32 |
CPU=0 |
| 33 |
fi |
| 34 |
|
| 35 |
printf "users.value %i\n" "${PLAYERCOUNT}"
|
| 36 |
printf "ramusage.value %3.2f\n" "${MEMGiB}"
|
| 37 |
printf "cpuusage.value %3.2f\n" "${CPU}"
|
