Home > System Tutorial > Linux > body text

How to create custom monitoring items with zabbix

王林
Release: 2024-04-14 21:01:16
forward
550 people have browsed it
背景:

zabbix本身提供了很多可选的监控项,可以满足绝大部分的监控需求。有时候由于业务需求,需要自定义监控项。 下面以创建mysql自定义监控项为例,分享如何创建zabbix自定义监控项。

环境说明:

zabbix版本:3.0.3 操作系统:CentOS 7 mysql版本:5.7.1

实现步骤:

1、修改 zabbix_agentd.conf,添加zabbix_agent 配置目录,以下是我本机的zabbix的配置: 将以下行的注释去掉

   #Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf 
Copy after login

变成:

   Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf 
Copy after login

将此行注释去掉后,zabbix_agentd启动后会自动扫描/usr/local/etc/zabbix_agentd.conf.d/目录下所有的.conf文件,并加载。

2、编写监控脚本/usr/local/zabbix/zabbix-script/get_mysql_status.sh,脚本如下(脚本存放目录可以自定义):

#!/bin/sh

case $3 in
uptime)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $2}'
;;
threads)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $4}'
;;
question)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $6}'
;;
sq)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $9}'
;;
open)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $11}'
;;
ftable)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $14}'
;;
opent)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $17}'
;;
qps)
mysqladmin -u$1 -p$2 status 2>/dev/nul | awk -F '[:| ]'+ '{print $22}'
;;
*)
Copy after login

脚本说明,脚本需要输入三个参数分别是:mysql用户、mysql用户密码、mysql状态各项指标如下: uptime:运行时长单位s、 threads:开启的会话数、 question(questions):服务器启动以来客户的问题(查询)数目 sq(Slow queries): 慢查询数量 open(opens):服务器已经打开的数据库表的数量 ftable(Flush tables):服务器已经执行的flush ...、refresh和reload命令的数量 opent(open tables):通过命令是用的数据库的表的数量,以服务器启动开始 qps(Queries per second avg):select语句平均查询时间

3、在/usr/local/etc/zabbix_agentd.conf.d/目录下添加监控项配置文件get_mysql_status.conf,内容如下:

UserParameter=get_mysql_status[*],/usr/local/zabbix/zabbix-script/get_mysql_status.sh $1 $2 $3
Copy after login

4、重启zabbix_agent和zabbix_server,使用zabbix_get测试,如下:

   #zabbix_get -s 127.0.0.1 -k get_mysql_status[root,weiming,open]
   679
Copy after login

5、web端添加监控项: 在主机上添加监控项:
How to create custom monitoring items with zabbix

添加完成后可以看到新增监控项如下:

How to create custom monitoring items with zabbix

添加图形:

How to create custom monitoring items with zabbix

图形预览:

How to create custom monitoring items with zabbix

The above is the detailed content of How to create custom monitoring items with zabbix. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!