root / plugins / mysql / mysql_size_ondisk @ 852aa41a
Historique | Voir | Annoter | Télécharger (1,89 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# |
| 3 |
INFO=\ |
| 4 |
"mysql_size_ondisk - Munin plugin that reports the size of the files and |
| 5 |
directories in /var/lib/mysql, biggest to smallest. |
| 6 |
To correctly count InnoDB tables you should have innodb_file_per_table enabled |
| 7 |
in MySQL (good practise anyway), otherwise all InnoDB tables will be counted into |
| 8 |
ibdataX. |
| 9 |
This plugin must be run as the user mysql, to do that append the following |
| 10 |
to your /etc/munin/plugins/plugin-conf.d/munin-node: |
| 11 |
|
| 12 |
[mysql_size_ondisk] |
| 13 |
user mysql |
| 14 |
|
| 15 |
This plugin gives you similar information as mysql_size_all. A difference |
| 16 |
is that mysql_size_ondisk is much faster (0.4 seconds vs 14 seconds, on a server |
| 17 |
with 170 databases, 26 GB total). Also note that mysql_size_all gives you the net |
| 18 |
data size, mysql_size_ondisk gives you the gross storage space used, which may be |
| 19 |
much more than your actual data." |
| 20 |
# |
| 21 |
# License: GPLv2 or later |
| 22 |
# |
| 23 |
# v1.0, 27.01.2012 Jakob Unterwurzacher <j.unterwurzacher@web-tech.at> |
| 24 |
|
| 25 |
#%# family=auto |
| 26 |
#%# capabilities=autoconf |
| 27 |
|
| 28 |
set -eu |
| 29 |
|
| 30 |
DIR=/var/lib/mysql |
| 31 |
|
| 32 |
function clean {
|
| 33 |
# First character must not be a number |
| 34 |
a=${1/#[0-9]/_}
|
| 35 |
# Other characters must be alphanumeric |
| 36 |
b=${a//[^a-zA-Z0-9]/_}
|
| 37 |
echo $b |
| 38 |
} |
| 39 |
|
| 40 |
if [ "${1:-}" = "autoconf" ]
|
| 41 |
then |
| 42 |
if du -sb $DIR &> /dev/null |
| 43 |
then |
| 44 |
echo "yes" |
| 45 |
else |
| 46 |
echo "no" |
| 47 |
fi |
| 48 |
exit 0 |
| 49 |
elif [ "${1:-}" = "config" ]
|
| 50 |
then |
| 51 |
echo "graph_title MySQL on-disk database size" |
| 52 |
echo "graph_category db" |
| 53 |
# graph_info cannot have newlines - replace by <br> which will be rendered to newlines in |
| 54 |
# the web interface. |
| 55 |
echo "graph_info ${INFO//$'\n'/<br>}"
|
| 56 |
echo "graph_args --base 1024 --lower-limit 0" |
| 57 |
echo "graph_vlabel Bytes" |
| 58 |
cd $DIR |
| 59 |
du -sb * | sort -nr | while read s i |
| 60 |
do |
| 61 |
i=`clean $i` |
| 62 |
echo "$i.label $i" |
| 63 |
echo "$i.type GAUGE" |
| 64 |
echo "$i.draw AREASTACK" |
| 65 |
done |
| 66 |
exit 0 |
| 67 |
elif [ "${1:-}" = "" ]
|
| 68 |
then |
| 69 |
cd $DIR |
| 70 |
du -sb * | sort -nr | while read s i |
| 71 |
do |
| 72 |
i=`clean $i` |
| 73 |
echo "$i.value $s" |
| 74 |
done |
| 75 |
exit 0 |
| 76 |
else |
| 77 |
echo "Unknown argument" |
| 78 |
exit 1 |
| 79 |
fi |
