公司一臺app服務器需要監控狀態。開發人員要求使用post方式(json格式參數),查看服務器返回狀態。才能確定服務器是否正常。使用get方式是不行的。
我採用python寫個腳本監控。過程如下:
創建key:
[root@mob3 zabbix_agentd.conf.d]# cat httppost.conf
UserParameter=http.post,/usr/bin/python /etc/zabbix/scripts/httppost.py
測試key:
[root@mob3 zabbix_agentd.conf.d]# zabbix_get -s 127.0.0.1 -k http.post
200
腳本內容
[root@mob3 scripts]# cat httppost.py
#!/usr/bin/python
import requests,json
url="http://app.xxxxx.com/P2MLinkCenter/setting/upgrade"
header={'Content-Type': 'application/json'}
data=json.dumps({"type":"apk","versionCode":"1.0.0"})
req=requests.post(url=url,data=data,headers=header)
print req.status_code
選擇一臺服務器,創建item:
創建graph:
查看graph:
可以看到,服務器返回的狀態碼是200,表明ok的。