使用information_schema数据库
MariaDB [(none)]> use information_schema ; 查询数据库总大小
MariaDB [information_schema]> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
查询指定数据库zabbix的大小
MariaDB [information_schema]> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix';
查询指定数据库的指定表的大小(zabbix数据库的items表的大小)
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix' and table_name='items';
2.如何通过shell 脚本去获取?
vim /etc/zabbix/shell/monitor_mysql.sh
#!/bin/bash
DB_size() {
mysql -Dinformation_schema -e "select concat(round(sum(data_length/1024/1024),2)) as data from tables" |awk 'NR==2{print $1}'
}
DB_zabbix_size() {
mysql -Dinformation_schema -e "select concat(round(sum(data_length/1024/1024),2)) as data from tables where table_schema='zabbix'" | \
awk 'NR==2{print $1}'
}
$1 3.agent定义模板
vim userparameter_my.confUserParameter=monitor_mysql