Projet

Général

Profil

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

root / plugins / mysql / mysql_size_ondisk @ b9ffe603

Historique | Voir | Annoter | Télécharger (1,9 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
		exit 0
46
	else
47
		echo "no"
48
		exit 1
49
	fi
50
elif [ "${1:-}" = "config" ]
51
then
52
	echo "graph_title MySQL on-disk database size"
53
	echo "graph_category mysql"
54
	# graph_info cannot have newlines - replace by <br> which will be rendered to newlines in
55
	# the web interface.
56
	echo "graph_info ${INFO//$'\n'/<br>}"
57
	echo "graph_args --base 1024 --lower-limit 0"
58
	echo "graph_vlabel Bytes"
59
	cd $DIR
60
	du -sb * | sort -nr | while read s i
61
	do
62
		i=`clean $i`
63
		echo "$i.label $i"
64
		echo "$i.type GAUGE"
65
		echo "$i.draw AREASTACK"
66
	done
67
	exit 0
68
elif [ "${1:-}" = "" ]
69
then
70
	cd $DIR
71
	du -sb * | sort -nr | while read s i
72
	do
73
		i=`clean $i`
74
		echo "$i.value $s"
75
	done
76
	exit 0
77
else
78
	echo "Unknown argument"
79
	exit 1
80
fi