zabbix监控mysql以及其他常见
zabbix监控mysql以及其他常见,监控mysql,也可是使用percona提供的详细的模板,里面的监控项目非常的详细
<template>Template Percona MySQL Server</template>
1 监控mysql状态
[root@mysqlhq ~]# cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -v '^#' | grep -v '^$'
UserParameter=mysql.ping,/usr/bin/mysqladmin -uzabbix -p*-h127.0.0.1 -P3306 2>/dev/null ping|grep alive|wc -l
UserParameter=mysql.status[*],/usr/bin/mysql -h 127.0.0.1 -P3306 -uzabbix -p'*' -N -e "show global status where Variable_name='$1'" 2>/dev/null | cut -f2
UserParameter=mysql_variable_status[*],/usr/bin/mysql -h 127.0.0.1 -P3306 -uzabbix -p'*' -N -e "show variables where Variable_name='$1'" 2>/dev/null | cut -f2
UserParameter=mysql.version,/usr/bin/mysql -V
UserParameter=mysql.mysql_process_status,sh /usr/local/zabbix/lib/alertscripts/check_mysql_status_3306.sh
2 脚本
[root@mysqlhq ~]# cat /usr/local/zabbix/lib/alertscripts/check_mysql_status_3306.sh
#!/bin/bash host=127.0.0.1 username=* password=* port=3306 CHECK_TIME=3 #mysql is working MYSQL_IS_OK is 1 , mysql down MYSQL_IS_OK is 0 MYSQL_IS_OK=1 function check_mysql_status (){ /usr/bin/mysql -u$username -p"$password" -P$port -h$host -e "select user();" >/dev/null 2>&1 if [ $? = 0 ] ;then MYSQL_IS_OK=1 else MYSQL_IS_OK=0 fi return $MYSQL_IS_OK } while [ $CHECK_TIME -ne 0 ] do let "CHECK_TIME -= 1" check_mysql_status if [ $MYSQL_IS_OK = 1 ] ; then CHECK_TIME=0 echo 1 exit 0 fi if [ $MYSQL_IS_OK -eq 0 ] && [ $CHECK_TIME -eq 0 ] then echo 0 exit 1 fi sleep 3 done
check_slave_status_3306.sh
#监控slave,这里监控2个线程,正常返回值2,返回1或者0都是有错误,可以在trigger里面进行配置
#!/bin/bash host=127.0.0.1 username=* password=* port=3306 #mysql slave is working then return 2,others is error /usr/bin/mysql -u$username -p"$password" -P$port -h$host 2>/dev/null \ -e "show slave status\G" |grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'|grep -c Yes
3 监控其他端口,比如mongodb
--使用zabbix自带key监控进程与端口
1、监控端口
监控端口使用如下key:
key:net.tcp.listen[port]
Checks if this port is in LISTEN state. 0 - it is not, 1 - it is inLISTEN state.
翻译:监听端口状态,返回结果为1,则运行;返回结果为0,则没有运行。
例如监控443端口,net.tcp.listen[443]
--templates
--application
--items
----name= LISTEN_prot_test_8066
----key=net.tcp.listen[8066]
--triggers
----Expression={LISTEN_prot_test:net.tcp.listen[8066].max(#2)}=0
[mongodb@hongquan1 conf]$ /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k "net.tcp.listen[3306]"
1
[mongodb@hongquan1 conf]$ /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k "net.tcp.listen[28002]"
1
4 监控磁盘
# cat /proc/diskstats |grep sda |head -1
UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}' //磁盘读的次数
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}' //磁盘读的毫秒数
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}' //磁盘写的次数
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}' //磁盘写的毫秒数
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}' //花费在IO操作上的毫秒数
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}' //读扇区的次数(一个扇区的等于512B)
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}' //写扇区的次数(一个扇区的等于512B)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构