From f60dbc7caaecb95a84bb1543bb6adc8e2a3e399b Mon Sep 17 00:00:00 2001 From: Natenom Date: Wed, 5 Sep 2012 14:14:36 +0200 Subject: [PATCH] Added minecraft_ script --- README | 20 ++++++++++++++++++++ minecraft_ | 28 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 minecraft_ diff --git a/README b/README index 9ff166c..0854e69 100644 --- a/README +++ b/README @@ -1 +1,21 @@ +======Munin-Plugins====== Several plugins for munin; mostly bash scripts. + +=====Minecraft===== +Name: minecraft_ +Description: Shows user count and RAM usage. +Website: http://wiki.natenom.name/minecraft/munin-plugin + +====Install==== +As the script needs root rights to work correctly, you must add following +two lines to /etc/munin/plugin-conf.d/munin-node on Debian: + [minecraft_*] + user root + +If your server is running on the default port, do: + # cd /etc/munin/plugins + # ln -s /path/to/minecraft_ minecraft_25565 + + + + diff --git a/minecraft_ b/minecraft_ new file mode 100644 index 0000000..6861dc8 --- /dev/null +++ b/minecraft_ @@ -0,0 +1,28 @@ +#!/bin/bash + +LC_LANG=C +MC_PORT=${0##*_} + +if [ "$1" = "config" ] +then + printf 'graph_title Minecraft-Server (Port %s)\n' ${MC_PORT} + printf 'graph_vlabel Anzahl\n' + printf 'users.label Benutzer\n' + printf 'ramusage.label Verwendeter RAM in GiB\n' + 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) +else + MEMGiB=0 +fi + +printf "users.value %i\n" "${PLAYERCOUNT}" +printf "ramusage.value %3.2f\n" "${MEMGiB}"