监控项(Item):采集数据的最小单位,定义了要监控什么、如何采集数据。
进入配置页面
配置 → 主机 → 选择主机 → 监控项 → 创建监控项
填写关键参数
key[参数])在Zabbix Agent配置文件(zabbix_agentd.conf)中添加:
# 格式:UserParameter=<key>,<command>
UserParameter=custom.process.count,ps aux | wc -l
UserParameter=custom.file.size[*],du -b $1 | awk '{print $1}'
重启Agent后,在Web界面使用键值:
custom.process.countcustom.file.size[/var/log/syslog]UserParameter=system.process.count,ps -e | wc -l
监控目录大小
UserParameter=directory.size[*],du -s $1 | awk '{print $1}'
监控服务状态
UserParameter=service.status[*],systemctl is-active $1
监控MySQL查询
UserParameter=mysql.connections,mysql -u<user> -p<password> -e "SHOW STATUS LIKE 'Threads_connected'" | grep Threads | awk '{print $2}'
{<host>:<key>.<function>(<parameter>)}<operator><constant>
进入触发器配置
配置 → 主机 → 选择主机 → 触发器 → 创建触发器
关键配置项
{ITEM.VALUE})# CPU使用率超过90%持续5分钟
{host:system.cpu.util[,system].avg(5m)}>90
# 内存使用率超过80%
{host:vm.memory.size[pavailable].last()}<=20
# 磁盘空间不足(小于10%)
{host:vfs.fs.size[/,pfree].last()}<10
# 服务宕机
{host:net.tcp.service[http].last()}=0
复杂表达式
# 连续3次检查失败
{host:icmpping.count(,5m)}>3
# 平均值超过阈值
{host:system.cpu.load[percpu,avg1].avg(10m)}>5
# 多个条件组合
{host:system.cpu.util[,system].avg(5m)}>90 and {host:system.cpu.load[percpu,avg1].last()}>5
# 最近一次值
last()
# 平均值
avg(5m) # 5分钟平均值
avg(1h) # 1小时平均值
avg(#3) # 最近3次平均值
# 最大值/最小值
max(10m) # 10分钟内最大值
min(1h) # 1小时内最小值
# 变化率
delta(1h) # 1小时内的变化值
change() # 当前值与前一值的差异
# 计数
count(5m) # 5分钟内值的数量
count(10m,0) # 10分钟内值为0的次数
# 时间函数
timeleft(1h,100,0) # 按当前趋势达到阈值的时间预测
Agent配置:
UserParameter=nginx.active.connections,curl -s http://localhost/nginx_status | grep "Active" | awk '{print $3}'
UserParameter=nginx.requests.total,curl -s http://localhost/nginx_status | grep "server accepts" | awk '{print $3}'
监控项键值:
nginx.active.connectionsnginx.requests.total触发器:
# Nginx活跃连接数超过1000
{host:nginx.active.connections.last()}>1000
# 5分钟内请求数增长异常(超过平时2倍)
{host:nginx.requests.total.avg(5m)} > {host:nginx.requests.total.avg(1h)} * 2
Agent配置:
UserParameter=app.error.count,grep "ERROR" /var/log/app/app.log | wc -l
监控项配置:
app.error.count触发器配置:
# 10分钟内错误数超过10次
{host:app.error.count.avg(10m)}>10
# 错误数突然增加(超过前一小时的3倍)
{host:app.error.count.avg(10m)} > {host:app.error.count.avg(1h)} * 3
# 自动发现挂载点
UserParameter=vfs.fs.discovery,lsblk -o MOUNTPOINT -n | grep -v "^$" | awk '{printf "{\"{#MOUNTPOINT}\":\"%s\"},\n", $1}' | sed '$s/,$//' | awk 'BEGIN{print "{\"data\":["}{print $0}END{print "]}"}'
防止告警风暴:
# 主触发器
{host:agent.ping.nodata(3m)}=1
# 依赖触发器(只在网络连通时触发)
{host:system.cpu.util[,system].avg(5m)}>90 and {host:agent.ping.last()}=1
# 在触发器名称中使用宏
CPU使用率超过{$CPU.CRIT}%: {ITEM.VALUE}
# 使用标签分类
标签: application → nginx
标签: component → performance
监控项不采集数据
触发器不触发
测试监控项
# 在Agent端测试
zabbix_get -s 127.0.0.1 -k "custom.process.count"
<类别>.<子类>.<指标>
合理设置更新间隔,避免性能影响
使用趋势数据减少数据库压力
为重要监控项设置依赖关系
定期审核和优化触发器阈值
需要更具体的监控场景配置,请提供详细需求。