Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / quake / qstat @ 63f8552a

Historique | Voir | Annoter | Télécharger (3,29 ko)

1
#!/bin/sh
2
#################################################################
3
# Title : Qstat plugin for Munin                                #
4
# Author : Benjamin DUPUIS - Poil				#
5
# Email : poil@quake.fr						#
6
# First release :  18/10/2007					#
7
#---------------------------------------------------------------#
8

    
9
#################################################################
10
# Variable :							#
11
#---------------------------------------------------------------#
12
qstat_exe="${qstat_exe:-/usr/local/bin/qstat}"
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 qstat_ GameType IP Port'
24
	echo ' - GameType : q3s, q4s ... run qstat for seeing available gametype'
25
	echo 'For munin you must ln -s /usr/share/munin/plugins/qstat_ /etc/munin/plugins/qstat_GameType_IP2test_Port'
26
	echo 'Perhaps you must have to set qstat_exe path, actually on' "${qstat_exe}";
27
	echo 'Have Fun'
28
}
29

    
30
config() {
31
	if [ "${script_name}" != "qstat_" ]; 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
44
graph_category games
45
maxplayer.label max players
46
bot.label bots
47
player.label players"
48
}
49

    
50
#################################################################
51
#       Quake Stat, call qstat	                                #
52
#---------------------------------------------------------------#
53
qstat_run() {
54
	if [ "${script_name}" != "qstat_" ]; then
55
                gametype=$(echo "$script_name" | cut -d_ -f2)
56
                ip=$(echo "$script_name" | cut -d_ -f3)
57
                port=$(echo "$script_name" | cut -d_ -f4)
58
	else
59
		gametype=$1
60
		ip=$2
61
		port=$3
62
	fi
63

    
64
	if [ -n "$gametype" ] && [ -n "$gametype" ] && [ -n "$gametype" ]; then
65
		rawstats=$("$qstat_exe" -raw ";" -nh "-$gametype" "${ip}:${port}")
66

    
67
		playervalue=$(echo "$rawstats" | cut -d\; -f6)
68
		maxplayervalue=$(echo "$rawstats" | cut -d\; -f5)
69
		
70
		# Assume that bots have a ping time of 0 miliseconds
71
		botvalue=$("$qstat_exe" -P -pa -sort P "-$gametype" "${ip}:${port}" | grep -c 0ms)
72

    
73
		if [ -z "${playervalue}" ]; then
74
			playervalue=0
75
		fi
76

    
77
		if [ -z "${botvalue}" ]; then
78
			botvalue=0
79
		fi
80

    
81
		if [ -z "${maxplayervalue}" ]; then
82
		        maxplayervalue=0
83
		fi
84

    
85

    
86
		echo "maxplayer.value "${maxplayervalue};
87
		echo "bot.value "${botvalue};
88
		echo "player.value "${playervalue};
89
	else
90
		echo "maxplayer.value U"
91
		echo "bot.value U"
92
		echo "player.value U"
93
	fi
94
}
95

    
96
#################################################################
97
#	Main 							#
98
#---------------------------------------------------------------#
99
case $1 in
100
	config)
101
		config "$@"
102
		exit 0
103
   	;;
104
	help | ?)
105
		usage
106
		exit 0
107
	;;
108
	autoconf)
109
		echo "no (edit the script for set qstat path)"
110
	;;
111
	*)
112
		qstat_run "$@"
113
		exit 0
114
	;;
115
esac
116