黑帽联盟

标题: 用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参数,来获取相应的数据
  1. #coding=utf-8
  2. import urllib,urllib2
  3. import json,sys
  4. def data_result():
  5.     try:
  6.         data = urllib2.urlopen("http://www.xxxxxx.com/13/status?json").read()
  7.     except urllib2.HTTPError as err:
  8.         print str(err)
  9.     data_ret = json.loads(data)
  10.     return data_ret
  11. def accepted_conn():
  12.     data = data_result()
  13.     return data["accepted conn"]
  14. def listen_queue():
  15.     data = data_result()
  16.     return data["listen queue"]
  17. def max_listen_queue():
  18.     data = data_result()
  19.     return data["max listen queue"]
  20. def listen_queue_len():
  21.     data = data_result()
  22.     return data["listen queue len"]
  23. def idle_processes():
  24.     data = data_result()
  25.     return data["idle processes"]
  26. def active_processes():
  27.     data = data_result()
  28.     return data["active processes"]
  29. def total_processes():
  30.     data = data_result()
  31.     return data["total processes"]
  32. def max_active_processes():
  33.     data = data_result()
  34.     return data["max active processes"]
  35. def max_children_reached():
  36.     data = data_result()
  37.     return data["max children reached"]
  38. def slow_requests():
  39.     data = data_result()
  40.     return data["slow requests"]
  41. if __name__== "__main__":
  42.     if sys.argv[1]=="accepted_conn":
  43.         print accepted_conn()
  44.     if sys.argv[1]=="listen_queue":
  45.         print listen_queue()
  46.     if sys.argv[1]=="max_listen_queue":
  47.         print max_listen_queue()
  48.     if sys.argv[1]=="listen_queue_len":
  49.         print listen_queue_len()
  50.     if sys.argv[1]=="idle_processes":
  51.         print idle_processes()
  52.     if sys.argv[1]=="active_processes":
  53.         print active_processes()
  54.     if sys.argv[1]=="total_processes":
  55.         print total_processes()
  56.     if sys.argv[1]=="max_active_processes":
  57.         print max_active_processes()
  58.     if sys.argv[1]=="max_children_reached":
  59.         print max_children_reached()
  60.     if sys.argv[1]=="slow_requests":
  61.         print slow_requests()
复制代码





欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5