zabbix有内置的模板,不过需要修改下配置,配置文件路径在:

[root@localhost ~]# cd /etc/zabbix/
[root@localhost zabbix]# ls
web zabbix_agentd.conf zabbix_agentd.d zabbix_server.conf zabbix_server.conf_bak
[root@localhost zabbix]# ll zabbix_agentd.d/userparameter_mysql.conf
-rw-r--r--. root root Dec zabbix_agentd.d/userparameter_mysql.conf
[root@localhost zabbix]#

配置文件里需要:

1、修改HOME路径,创建.my.cnf文件。

2、mysql和mysqladmin需要改成绝对路径

# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.

# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -N | awk '{print $$2}' # Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
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 inform
ation_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/var/lib/zabbix mysql -N' UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

.my.cnf

[root@localhost zabbix]# pwd
/etc/zabbix
[root@localhost zabbix]# cat .my.cnf
[mysql]
host=localhost
user=zabbix
password= [mysqladmin]
host=localhost
user=zabbix
password=

正常情况需要创建一个zabbix用户,限定权限,供zabbix-server调用,不过我这里监控的是zabbix-server在的数据库,用户是现成的。

UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix  /usr/bin/mysql -N | awk '{print $$2}'
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 inform
ation_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/etc/zabbix /usr/bin/mysql
-N' UserParameter=mysql.ping,HOME=/etc/zabbix /usr/bin/mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

mysql和mysqladmin路径可以通过whereis查看

[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/lib64/mysql /usr/include/mysql /usr/local/mysql /usr/share/mysql /usr/share/man/man1/mysql..gz
[root@localhost ~]# whereis mysqladmin
mysqladmin: /usr/bin/mysqladmin /usr/share/man/man1/mysqladmin..gz

修改完毕,记得重启zabbix-agent

添加模板:

在lastest data看下:

最新文章

  1. JavaScript常用技巧总结(持续添加中...)
  2. putty如何使用
  3. position-relative 的问题
  4. Maven_根据不同个环境打包, 获取不同的配置文件等等
  5. 在virtualbox下使用vm映像文件
  6. U3d中实现A*寻路,附源文件
  7. A - 棋盘问题
  8. Canvas之动态波浪效果_陈在真Sunny_chen_新浪博客
  9. Python 文本解析器
  10. 怎样使Android应用程序获得root权限
  11. window.open模拟表单POST提交
  12. Keras bug in model.predict
  13. 【aardio】是否取消三个按键的对话框
  14. Linux性能优化 第二章 性能工具:系统CPU
  15. 【4-1】js函数、事件、补充知识
  16. Silverlight样式定义
  17. 【转】多线程:C#线程同步lock,Monitor,Mutex,同步事件和等待句柄(上)
  18. 【JMeter】如何用JMeter进行压力测试
  19. 更喜欢从一而终?bing测试在新窗口打开链接遭美国网友痛批
  20. linux 远程复制文件或文件夹

热门文章

  1. css控制文本对齐
  2. 路由参数 query和params
  3. undefined,null,var 0 = {},var s = &#39;&#39;,的区别
  4. luoguP1540 机器翻译 题解(NOIP2010)
  5. Java-技术专区-异步编程指南
  6. 第5篇K8S创建资源的两种方式
  7. hdu4857 拓扑排序
  8. MyISAM和InnoDB引擎的区别
  9. 怀旧浪潮来袭,小霸王游戏、windows95......曾经的经典哪些能戳中你的心怀?
  10. java html生成PDF,并打印