1.怎么去获取到数据库大小、表大小?mysql
information_schema数据库存储了关于数据库的信息web
使用information_schema数据库sql
MariaDB [(none)]> use information_schema ;
查询数据库总大小
shell
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表的大小)vim
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix' and table_name='items';
2.如何经过shell 脚本去获取?bash
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定义模板
app
vim userparameter_my.conf
UserParameter=monitor_mysql[*],/bin/bash /etc/zabbix/shell/monitor_mysql.sh "$1"
参数解释:
运维
monitor_mysql[*]:是自定义key,*是传参 是从server端自定义键值的时候传参传下来的
4.server端自定义键值,请参考第二篇,监控QPS和TPS的那篇
5.准备更新一个关于zabbix监控的专题,欢迎加入咱们的Linux技术交流群:642921645,zabbix监控交流群:832462735 ,咱们不按期去更新不少关于系统运维的资料在群里,期待你的加入!
6.在腾讯课堂有zabbix监控的免费技术分享,欢迎来听!地址以下:https://ke.qq.com/course/316681?tuin=6645db32
7.若是查看51cto不方便,文章也会推送到微信公众号