MySQL

Collect MySQL Size in Zabbix on Ubuntu 12.04 LTS

Posted on

If you have a lot of such entries

sh: 1: [[: not found
sh: 1: : Permission denied

in your zabbix_agentd.log and you are on Ubuntu 12.04 LTS then you have the dash shell as /bin/sh DashAsBinSh

I have used the following setup to solve this issue.

vi /etc/zabbix/mysql_size.sh

#!/bin/bash

echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema='$1'")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name='$2'");" | HOME=/var/lib/zabbix mysql -N

chmod 755 /etc/zabbix/mysql_size.sh

and changed the original line in

userparameter_mysql.conf

to
UserParameter=mysql.size[*],/etc/zabbix/mysql_size.sh $1 $2 $3

Advertisements