注:
当nginx 应用了nginx_upstream_check_module 模块,虽然可以看到upstream 的service状态,但是如何做到实时监控报警
[root@sit-cdpapp-162l zabbix]# cat nginx_check_upstream.py
#!/usr/bin/python
# -*- coding:utf-8 -*-
# from django.test import TestCase
import requests,re
import os,sys
domainname = sys.argv[1]
try:
environment = sys.argv[2]
except IndexError:
environment = ''
def NginxSstatus(url):
r = requests.get(url)
resStr = r.text
resStr = resStr.split('\n')
thList = [re.search('<th>.*</th>',i).group().replace('<th>','').replace('</th>','') for i in resStr if re.search('<th>.*</th>',i) is not None]
tdList = [re.search('<td>.*</td>',i).group().replace('<td>','').replace('</td>','') for i in resStr if re.search('<td>.*</td>',i) is not None]
resList = [tdList[i:i+len(thList)] for i in range(0,len(tdList),len(thList))]
# resList.insert(0,thList)
resList = [dict(map(lambda x,y:[x,y],thList,li)) for li in resList]
return resList
if __name__ == "__main__":
if environment == '':
li = NginxSstatus('http://{tdomain}.xxxx.com/nstatus'.format(tenv=environment,tdomain=domainname))
else:
li = NginxSstatus('http://{tenv}-{tdomain}.xxxx.com/nstatus'.format(tenv=environment,tdomain=domainname))
#print(li)
#print(type(li[0]['Index']))
code = []
for i in range(len(li)):
if li[i]['Status'] == 'down':
code.append(li[i])
else:
code.append('success')
print(code)
vim /etc/zabbix/nginx_check_upstream.py
cat /etc/zabbix/zabbix_agentd.conf
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。