PluginPortrait/mysql_size: mysql_size.2

File mysql_size.2, 1.4 KB (added by = vmware_gsx_ = Multi function plugin for monitoring memory, disk IO and ethernet IO pr virtual machine. ||Language||Perl|| ||Requirements||Perl VMware::Config::Server VMware::Config::VM|| ||Supported platforms||VMware GSX|| ||Written by||Rune Nordbøe Skillingstad rune@…, at 2006-07-06T13:27:49+02:00)
Line 
1#!/bin/sh
2#
3# Plugin to monitor the size of databases in a mysql-server.
4#
5# Copyright: Rune Nordbøe Skillingstad <rune.skillingstad@ntnu.no>
6#
7# Parameters supported:
8#
9#       config
10#       autoconf
11#
12# Configuration variables
13#
14#       mysqlopts    - Options to pass to mysql
15#
16#%# family=auto
17#%# capabilities=autoconf
18
19MYSQLOPTS="$mysqlopts"
20MYSQL=${mysql:-mysql}
21
22if [ "$1" = "autoconf" ]; then
23        $MYSQL --version 2>/dev/null >/dev/null
24        if [ $? -eq 0 ]
25        then
26                $MYSQL $MYSQLOPTS -s -e "SHOW TABLE STATUS" 2>/dev/null >/dev/null
27                if [ $? -eq 0 ]
28                then
29                        echo yes
30                        exit 0
31                else
32                        echo "no (could not connect to mysql)"
33                fi
34        else
35                echo "no (mysql not found)"
36        fi
37        exit 1
38fi
39
40if [ "$1" = "config" ]; then
41        echo 'graph_title MySQL database sizes'
42        echo 'graph_vlabel bytes'
43        echo 'graph_category mysql'
44        echo 'graph_args --base 1000'
45        for DB in $($MYSQL $MYSQLOPTS -s -e 'show databases');
46        do
47           echo "$DB.label $DB size (bytes)"
48           echo "$DB.info $DB size"
49           echo "$DB.type GAUGE"
50           echo "$DB.draw LINE2"
51        done
52        exit 0
53fi
54
55for DB in $($MYSQL $MYSQLOPTS -s -e 'show databases');
56do
57        echo -n "$DB.value "
58        $MYSQL $MYSQLOPTS -s -e "SHOW TABLE STATUS FROM $DB" \
59          | awk 'BEGIN{s=0}{s+=$6;s+=$8}END{printf "%d\n", s}';
60done