Projet

Général

Profil

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

root / plugins / other / mysql_innodb @ e908d2d2

Historique | Voir | Annoter | Télécharger (2,07 ko)

1
#!/bin/bash
2
#
3
# Munin plugin to monitor free space in MySQL's InnoDB tablespace.
4
# Mostly useful if you use InnoDB on a block device, or if you for
5
# some reason don't want to do autoextend on the last file.
6
# 
7
# 2007-03-18 Stig Sandbeck Mathisen <ssm@fnord.no>
8
#
9
# Configuration parameters for /etc/munin/plugin-conf.d/mysql_innodb,
10
# if you need to override the defaults below:
11
#
12
# [mysql_innodb]
13
#   env.mysqlopts - Options to pass to mysql (host, username, password)
14
#   env.warning   - Generate a warning if free space goes below this level
15
#   env.critical  - Generate a critical if free space goes below this level
16
# 
17
# For security reasons, this plugin uses its own schema with a simple,
18
# empty table using the InnoDB engine.
19
# 
20
# You need to run this to get this plugin to work:
21
#   mysql> CREATE DATABASE munin_innodb;
22
#   mysql> USE munin_innodb
23
#   mysql> CREATE TABLE something (anything int) ENGINE=InnoDB;
24

    
25
## Tunable parameters with defaults
26
MYSQL="${mysql:-/usr/bin/mysql}"
27
MYSQLOPTS="${mysqlopts:---user=munin --password=munin --host=localhost}"
28

    
29
WARNING=${warning:-2147483648}   # 2GB
30
CRITICAL=${critical:-1073741824} # 1GB
31

    
32
## No user serviceable parts below
33
if [ "$1" = "config" ]; then
34
    echo 'graph_title MySQL InnoDB free tablespace'
35
    echo 'graph_args --base 1024'
36
    echo 'graph_vlabel Bytes'
37
    echo 'graph_category mysql'
38
    echo 'graph_info Amount of free bytes in the InnoDB tablespace'
39
    echo 'free.label Bytes free'
40
    echo 'free.type GAUGE'
41
    echo 'free.min 0'
42
    echo 'free.warning' $WARNING:
43
    echo 'free.critical' $CRITICAL:
44
    exit 0
45
fi
46

    
47
# Get freespace from mysql
48
freespace=$($MYSQL $MYSQLOPTS --batch --skip-column-names --execute        \
49
    "SELECT table_comment FROM tables WHERE TABLE_SCHEMA = 'munin_innodb'" \
50
    information_schema);
51
retval=$?
52

    
53
# Sanity checks
54
if (( retval > 0 )); then
55
    echo "Error: mysql command returned status $retval" 1>&2
56
    exit -1
57
fi
58
if [ -z "$freespace" ]; then
59
    echo "Error: mysql command returned no output" 1>&2
60
    exit -1
61
fi
62

    
63
# Return freespace
64
echo $freespace | awk '/InnoDB free:/ {print "free.value", $3 * 1024}'