How to create custom monitoring items with zabbix
zabbix本身提供了很多可选的监控项,可以满足绝大部分的监控需求。有时候由于业务需求,需要自定义监控项。 下面以创建mysql自定义监控项为例,分享如何创建zabbix自定义监控项。
zabbix版本:3.0.3 操作系统:CentOS 7 mysql版本:5.7.1
1、修改 zabbix_agentd.conf,添加zabbix_agent 配置目录,以下是我本机的zabbix的配置: 将以下行的注释去掉
#<span class="hljs-keyword">Include</span>=<span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/etc/</span>zabbix_agentd.conf.d<span class="hljs-comment">/*.conf </span>
变成:
<span class="hljs-keyword">Include</span>=<span class="hljs-regexp">/usr/</span>local<span class="hljs-regexp">/etc/</span>zabbix_agentd.conf.d<span class="hljs-comment">/*.conf </span>
将此行注释去掉后,zabbix_agentd启动后会自动扫描/usr/local/etc/zabbix_agentd.conf.d/目录下所有的.conf文件,并加载。
2、编写监控脚本/usr/local/zabbix/zabbix-script/get_mysql_status.sh,脚本如下(脚本存放目录可以自定义):
<span class="hljs-meta">#!/bin/sh </span> <span class="hljs-keyword">case</span> <span class="hljs-variable">$3</span> <span class="hljs-keyword">in</span> uptime) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $2}'</span> ;; threads) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $4}'</span> ;; question) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $6}'</span> ;; sq) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $9}'</span> ;; open) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $11}'</span> ;; ftable) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $14}'</span> ;; opent) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $17}'</span> ;; qps) mysqladmin -u<span class="hljs-variable">$1</span> -p<span class="hljs-variable">$2</span> status 2>/dev/nul | awk -F <span class="hljs-string">'[:| ]'</span>+ <span class="hljs-string">'{print $22}'</span> ;; *)
脚本说明,脚本需要输入三个参数分别是: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[*],<span class="hljs-regexp">/usr/local</span><span class="hljs-regexp">/zabbix/zabbix</span>-script/get_mysql_status.sh <span class="hljs-variable">$1</span> <span class="hljs-variable">$2</span> <span class="hljs-variable">$3</span>
4、重启zabbix_agent和zabbix_server,使用zabbix_get测试,如下:
<span class="hljs-selector-id">#zabbix_get</span> <span class="hljs-selector-tag">-s</span> 127<span class="hljs-selector-class">.0</span><span class="hljs-selector-class">.0</span><span class="hljs-selector-class">.1</span> <span class="hljs-selector-tag">-k</span> <span class="hljs-selector-tag">get_mysql_status</span><span class="hljs-selector-attr">[root,weiming,open]</span> 679
5、web端添加监控项: 在主机上添加监控项:
添加完成后可以看到新增监控项如下:
添加图形:
图形预览:
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!

Linux and Windows differ in hardware compatibility: Windows has extensive driver support, and Linux depends on the community and vendors. To solve Linux compatibility problems, you can manually compile drivers, such as cloning RTL8188EU driver repository, compiling and installing; Windows users need to manage drivers to optimize performance.

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software