注:

当nginx 应用了nginx_upstream_check_module 模块,虽然可以看到upstream 的service状态,但是如何做到实时监控报警

image.png

[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)

image.png

vim /etc/zabbix/nginx_check_upstream.py

image.png

cat /etc/zabbix/zabbix_agentd.conf

image.png

image.png

image.png


锅包肉
89 声望17 粉丝

这个人很懒,没有什么说的。