黑帽联盟
标题:
用python脚本获取php-fpm服务的状态和性能
[打印本页]
作者:
定位
时间:
2017-3-27 09:38
标题:
用python脚本获取php-fpm服务的状态和性能
直接上脚本,有需要的拿去自行测试:
提示:该页比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()
复制代码
欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/)
Powered by Discuz! X2.5