Projet

Général

Profil

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

root / plugins / mysql_by_user @ 8f2bcef9

Historique | Voir | Annoter | Télécharger (1,37 ko)

1
#!/bin/sh
2
#
3
# Plugin to monitor the number of active connections to the mysql server
4
#
5
# Parameters:
6
# 	
7
# 	config
8
# 	autoconf
9
#
10
# Configuration variables
11
#
12
#	mysqlopts    - Options to pass to mysql which should include the
13
#  			username, password, host and alternc database.
14
#
15
# Example of the entry in plugin-conf.d/munin-node
16
#	[alternc*]
17
#	user root
18
#	env.mysqlopts --defaults-file=/etc/mysql/alternc.cnf
19
#
20
#
21
#%# family=auto
22
#%# capabilities=autoconf
23

    
24
MYSQLOPTS="$mysqlopts"
25
MYSQL=${mysql:-mysql}
26

    
27
if [ "$1" = "autoconf" ]; then
28
        $MYSQL --version 2>/dev/null >/dev/null
29
        if [ $? -eq 0 ]
30
        then
31
                $MYSQL $MYSQLOPTS -N -B -e 'show tables' 2>/dev/null >/dev/null
32
                if [ $? -eq 0 ]
33
                then
34
                        echo yes
35
                        exit 0
36
                else
37
                        echo "no (could not connect to mysql)"
38
                fi
39
        else
40
                echo "no (mysql client not found)"
41
        fi
42
        exit 1
43
fi
44

    
45
if [ "$1" = "config" ]; then
46
	echo 'graph_title Apache - mysql connections by user'
47
	echo 'graph_vlabel quantity'
48
	echo 'graph_category alternc'
49
        $MYSQL $MYSQLOPTS -N -B -e "SHOW PROCESSLIST" | awk ' {foo[$2]++} END {for (f in foo) { print f".label" , f }}'
50
	exit 0
51
fi
52

    
53
$MYSQL $MYSQLOPTS -N -B -e "SHOW PROCESSLIST" | awk ' {foo[$2]++} END {for (f in foo) { print f".value" , foo[f] }}'