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:

#!/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