tripleonard

a repo for my superuser adventures

A Simple Munin Plugin to Track the Size of a Mysql Database

Here is a simple munin plugin to graph the size of a MySQL database over time. A while back I created a Stored Procedure, which fed its results into another MySQL database. Our traffic has been low enough that the extra resources needed for the second db in production did not bother me. However, I have always had a nagging desire to move this to montitoring. This is my first, but not last, munin plugin:

[database_size]
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
#!/bin/sh

case $1 in
   config)
        cat <<'EOM'
graph_title Database size
graph_args --base 1000 -l 0
graph_vlabel megabytes
graph_category database
graph_info Size of total database, data, and indexes size in megabytes.
total.label total
total.info Total size of database. Combination of data and indexes.
data.label data
data.info Size of data only.
index.label index
index.info Size of indexes only.

EOM
        exit 0;;
esac

echo -n "total.value "
mysql -u user -ppassword --skip-column-names<<EOFMYSQL
select sum(data_length+index_length)/1024/1024 from information_schema.tables;
EOFMYSQL

echo -n "data.value "
mysql -u user -ppassword --skip-column-names<<EOFMYSQL
select sum(data_length)/1024/1024 from information_schema.tables;
EOFMYSQL

echo -n "index.value "
mysql -u user -ppassword --skip-column-names<<EOFMYSQL
select sum(index_length)/1024/1024 from information_schema.tables;
EOFMYSQL

Hello World

Installed the Octopress blogging software. Maybe I should do a post… nah.