Plugin Munin: open table by database

Plugin Munin: open table by database

Suite au précédent plugin munin pour Mysql qui indique les ouvertures de table, il manquait une information pour aider à l’optimisation de mysql: Savoir quelle table provoque les ouvertures: voila le code qui donne ces informations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
#
# Plugin to monitor the number of opened tables on a mysql-server.
#
# Parameters:
#
#   config
#   autoconf
#
# Configuration variables
#
#   mysqlopts    - Options to pass to mysql
#
# $Log$
# Revision 1.0  2009/05/1 1:04 ffwill
#
#%# family=auto
#%# capabilities=autoconf
 
MYSQLOPTS="$mysqlopts"
MYSQL=${mysql:-mysql}
BDD="database list you want monitoring"
TMPFILE="/tmp/munin.mysql_open_tables_by_database"
 
if [ "$1" = "autoconf" ]; then
        $MYSQL --version 2>/dev/null >/dev/null
        if [ $? -eq 0 ]
        then
                $MYSQL $MYSQLOPTS -e 'show open tables' 2>/dev/null >/dev/null
                if [ $? -eq 0 ]
                then
                        echo yes
                        exit 0
                else
                        echo "no (could not connect to mysql)"
                fi
        else
                echo "no (mysqladmin not found)"
        fi
        exit 1
fi
if [ "$1" = "config" ]; then
    echo 'graph_title MySQL Open table by database'
    echo 'graph_vlabel Open Tables'
    echo 'graph_category mysql'
    echo 'graph_args --base 1000'
    num=0;
    for i in $BDD; do
        echo 'opentables_'$i'.label '$i
        echo 'opentables_'$i'.min 0'
#           echo 'opentables'$i'.type DERIVE'
                if [ $num = "0" ]
        then
            echo 'opentables_'$i'.draw AREA'
                else
            echo 'opentables_'$i'.draw STACK'
        fi
        num=1;
    done
    exit 0
fi
 
$MYSQL $MYSQLOPTS -e 'show open tables' 2>/dev/null 1>$TMPFILE
 
echo $result
 
for i in $BDD; do
    res=`grep $i $TMPFILE  | wc -l`
    echo 'opentables_'$i'.value '$res
 
done

Et pour télécharger le plugin c’est ici ou ici