TA的每日心情 | 开心 昨天 22:18 |
---|
签到天数: 1645 天 [LV.Master]伴坛终老
|
直接上脚本,有需要的拿去自行测试:
提示:该页比nginx status多一个实用功能---可以带参数,具体如下:
192.168.130.254/13/status?json
192.168.130.254/13/status?xml
192.168.130.254/13/status?html
192.168.130.254/13/status?full
这里我们通过json参数,来获取相应的数据- #coding=utf-8
- import urllib,urllib2
- import json,sys
- def data_result():
- try:
- data = urllib2.urlopen("http://www.xxxxxx.com/13/status?json").read()
- except urllib2.HTTPError as err:
- print str(err)
- data_ret = json.loads(data)
- return data_ret
- def accepted_conn():
- data = data_result()
- return data["accepted conn"]
- def listen_queue():
- data = data_result()
- return data["listen queue"]
- def max_listen_queue():
- data = data_result()
- return data["max listen queue"]
- def listen_queue_len():
- data = data_result()
- return data["listen queue len"]
- def idle_processes():
- data = data_result()
- return data["idle processes"]
- def active_processes():
- data = data_result()
- return data["active processes"]
- def total_processes():
- data = data_result()
- return data["total processes"]
- def max_active_processes():
- data = data_result()
- return data["max active processes"]
- def max_children_reached():
- data = data_result()
- return data["max children reached"]
- def slow_requests():
- data = data_result()
- return data["slow requests"]
- if __name__== "__main__":
- if sys.argv[1]=="accepted_conn":
- print accepted_conn()
- if sys.argv[1]=="listen_queue":
- print listen_queue()
- if sys.argv[1]=="max_listen_queue":
- print max_listen_queue()
- if sys.argv[1]=="listen_queue_len":
- print listen_queue_len()
- if sys.argv[1]=="idle_processes":
- print idle_processes()
- if sys.argv[1]=="active_processes":
- print active_processes()
- if sys.argv[1]=="total_processes":
- print total_processes()
- if sys.argv[1]=="max_active_processes":
- print max_active_processes()
- if sys.argv[1]=="max_children_reached":
- print max_children_reached()
- if sys.argv[1]=="slow_requests":
- print slow_requests()
复制代码 |
|