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

2 thoughts on “Collect MySQL Size in Zabbix on Ubuntu 12.04 LTS

    Thiago Rodrigues said:
    March 24, 2015 at 20:45

    Follows a way working with Ubuntu 14.04.

    UserParameter=mysql.size[*],bash -c ‘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=/etc/zabbix mysql -N’

    regers,

    Thiago Rodrigues

      alword responded:
      March 25, 2015 at 11:57

      Thanks for the tip Thiago

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s