===== Munin plugin pro sledování využití procesoru minetest serverem ===== #!/bin/bash #munin plugin for cpu usage monitoring of minetestserver for given port #author: Ritchie #thanks Pitriss for advices #inspired by plugin minecraft-users-ram_ #https://github.com/munin-monitoring/contrib/blob/master/plugins/minecraft/minecraft-users-ram_ #Author & instructions: http://wiki.natenom.name/minecraft/munin-plugin LC_LANG=C MT_PORT=${0##*_} if [ "$1" = "config" ] then #NCPU=$(egrep '^cpu[0-9]+ ' /proc/stat | wc -l) # if [ "$scaleto100" = "yes" ]; then # graphlimit=100 # else # graphlimit=$(($NCPU * 100)) # fi # printf 'graph_title Minetestserver CPU usage (Port %s)\n' ${MT_PORT} # echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit $graphlimit" # printf 'graph_vlabel %\n' # echo 'graph_scale no' # printf 'cpuusage.label cpu usage\n' # printf 'graph_category minetest' # printf 'graph_info Shows RAM usage by minetestserver process' #echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit $graphlimit" echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100" echo "graph_title Minetestserver CPU usage (Port ${MT_PORT})" echo "graph_category minetest" echo "graph_info This graph shows CPU usage for minetestserver." echo "graph_vlabel %" echo "graph_scale no" echo "graph_period second" echo "cpuusage.label cpu usage" exit 0 fi MT_PID=$(netstat -ulpn 2>/dev/null | grep ${MT_PORT} | sed -n -e '1p' | awk '{ print $6 }' | cut -d'/' -f1) if [ ! -z "${MT_PID}" ] then #is running CPUusage=$(ps aux | grep ${MT_PID} | grep -v grep | awk '{print $3}') else CPUusage=0 fi printf "cpuusage.value %3.2f\n" "${CPUusage}"