Zabbix监控nginx-rtmp status(html版)
nginx-rtmp开启stats
# nginx(--add-module=nginx-rtmp-module-master) nginx.conf: server { listen 81; location /stat { rtmp_stat all; } }
http://127.0.0.1:81/stat
stat状态值详解
codec: 编码
bits/s: 码流
size: 分辨率
fps: 每秒传输帧数
freq: 音频频率
chan: 声道数
定义zabbix监控item key
vim etc/zabbix_agentd.conf.d/userparameter_live.conf
UserParameter=live.stream[*],/usr/local/zabbix-agent/scripts/stream.py $1
stream.py # 判断In bits/s值(视音频合计码流)。0则rtmp断流,非0则正常
#!/usr/bin/python # -*- coding: utf-8 -*- # author pdd ''' curl的直播流状态值写入本地CACHE文件 后续具体的直播频道流值从该文件获取 CACHE文件根据ctime一分钟更新一次 ''' import os import re import sys import time import urllib2 class Live(object): def __init__(self,url,CACHETTL,CACHE,STREAM): self.url = url self.CACHETTL = CACHETTL self.CACHE = CACHE self.STREAM = STREAM def generate_cache(self): TIMENOW = int(time.time()) if os.path.isfile(self.CACHE) and os.path.getsize(self.CACHE) > 0: TIMECACHE = int(os.path.getctime(self.CACHE)) else: TIMECACHE = 0 if (TIMENOW - TIMECACHE) > self.CACHETTL: try: r = urllib2.urlopen(self.url,timeout=1) with open(self.CACHE,'w') as f: f.write(r.read()) except urllib2.URLError, e: print 0 # 给zabbix触发直播流down报警的值 exit(1) # 退出程序 不让从CACHE文件获取值 def get_status(self): self.generate_cache() with open(self.CACHE,'r') as f: r = f.read() name = re.findall(r'<name>(.*_sd)</name>',r) flow = re.findall(r'<bw_in>(.*)</bw_in>',r)[1:] stream = dict(zip(name,flow)) print(stream[self.STREAM]) if __name__ == "__main__": url = "http://127.0.0.1:81/stat" # 直播频道流状态值url CACHETTL = 60 # 本地CACHE文件更新时间间隔 CACHE = "/tmp/nginx-rtmp-status.cache" # 本地CACHE文件绝对路径 STREAM = sys.argv[1] # 某个具体直播频道 status = Live(url,CACHETTL,CACHE,STREAM) status.get_status()
重启zabbix_agentd客户端使监控key生效
客户端测试
服务器端 # 页面监控主机添加对应的application items
zabbix后台 Configuration->Hosts->被监控的数据库主机name->Applications Items
创建Graphs(视音频码流)
zabbix后台 Configuration->Hosts->被监控的主机name->Graphs
查看graph(视频码流)
zabbix后台 Monitoring->Graphs->对应的graph