root / plugins / games / cstat @ c3660c2a
Historique | Voir | Annoter | Télécharger (3,09 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
################################################################# |
| 3 |
# Title : Cstat plugin for Munin # |
| 4 |
# Author : Benjamin DUPUIS - Poil # |
| 5 |
# Email : poil@quake.fr # |
| 6 |
# First release : 22/03/2011 # |
| 7 |
#---------------------------------------------------------------# |
| 8 |
|
| 9 |
################################################################# |
| 10 |
# Variable : # |
| 11 |
#---------------------------------------------------------------# |
| 12 |
cstat_exe='/usr/local/bin/cstat' |
| 13 |
|
| 14 |
#---------------------------------------------------------------# |
| 15 |
# End of config |
| 16 |
script_name=$(basename $0) |
| 17 |
################################################################# |
| 18 |
|
| 19 |
################################################################# |
| 20 |
# Help # |
| 21 |
#---------------------------------------------------------------# |
| 22 |
usage() {
|
| 23 |
echo 'For testing the script, run cstat_ GameType IP Port' |
| 24 |
echo ' - GameType : c2s, sbs, bfs ... run cstat for seeing available gametype' |
| 25 |
echo 'For munin you must ln -s /usr/share/munin/plugins/cstat_ /etc/munin/plugins/cstat_GameType_IP2test_Port' |
| 26 |
echo 'Perhaps you must have to set cstat_exe path, actually on'${cstat_exe};
|
| 27 |
echo 'Have Fun' |
| 28 |
} |
| 29 |
|
| 30 |
config() {
|
| 31 |
if [ "${script_name}" != "cstat_" ]; then
|
| 32 |
gametype=$(echo ${script_name} | cut -d_ -f2)
|
| 33 |
ip=$(echo ${script_name} | cut -d_ -f3)
|
| 34 |
port=$(echo ${script_name} | cut -d_ -f4)
|
| 35 |
else |
| 36 |
gametype=$1 |
| 37 |
ip=$2 |
| 38 |
port=$3 |
| 39 |
fi |
| 40 |
|
| 41 |
echo "graph_title Number of players on ${gametype} - ${ip}:${port}
|
| 42 |
graph_vlabel players |
| 43 |
graph_args --base 1000 -r --lower-limit 0 --upper-limit 16 |
| 44 |
graph_category games |
| 45 |
maxplayer.label max players |
| 46 |
player.label players |
| 47 |
maxplayer.critical 1:" |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
################################################################# |
| 52 |
# Cube Stat, call cstat # |
| 53 |
#---------------------------------------------------------------# |
| 54 |
cube_stat() {
|
| 55 |
if [ "${script_name}" != "cstat_" ]; then
|
| 56 |
gametype=$(echo ${script_name} | cut -d_ -f2)
|
| 57 |
ip=$(echo ${script_name} | cut -d_ -f3)
|
| 58 |
port=$(echo ${script_name} | cut -d_ -f4)
|
| 59 |
else |
| 60 |
gametype=$1 |
| 61 |
ip=$2 |
| 62 |
port=$3 |
| 63 |
fi |
| 64 |
|
| 65 |
if [ ! -z ${gametype} ] && [ ! -z ${gametype} ] && [ ! -z ${gametype} ]; then
|
| 66 |
dummy=$(${cstat_exe} --xml --${gametype} ${ip}:${port})
|
| 67 |
playervalue=$(echo "${dummy}" | sed -n -e 's/.*<numplayers>\(.*\)<\/numplayers>.*/\1/p')
|
| 68 |
maxplayervalue=$(echo "${dummy}" | sed -n -e 's/.*<maxplayers>\(.*\)<\/maxplayers>.*/\1/p')
|
| 69 |
|
| 70 |
if [ -z "${playervalue}" ]; then
|
| 71 |
playervalue=0 |
| 72 |
fi |
| 73 |
|
| 74 |
if [ -z "${maxplayervalue}" ]; then
|
| 75 |
maxplayervalue=0 |
| 76 |
fi |
| 77 |
|
| 78 |
|
| 79 |
echo "maxplayer.value "${maxplayervalue};
|
| 80 |
echo "player.value "${playervalue};
|
| 81 |
else |
| 82 |
echo "maxplayer.value U" |
| 83 |
echo "player.value U" |
| 84 |
fi |
| 85 |
} |
| 86 |
|
| 87 |
################################################################# |
| 88 |
# Main # |
| 89 |
#---------------------------------------------------------------# |
| 90 |
case $1 in |
| 91 |
config) |
| 92 |
config |
| 93 |
exit 0 |
| 94 |
;; |
| 95 |
help | ?) |
| 96 |
usage |
| 97 |
exit 0 |
| 98 |
;; |
| 99 |
autoconf) |
| 100 |
echo "no (edit the script for set cstat path)" |
| 101 |
;; |
| 102 |
*) |
| 103 |
cube_stat $1 $2 $3 |
| 104 |
exit 0 |
| 105 |
;; |
| 106 |
esac |
| 107 |
|
