使用python3.x實現統計Nginx進程所占用的物理內存
阿新 • • 發佈:2017-06-13
linux 進程 統計 python nginx
實現代碼如下:
#!/usr/bin/python #coding:utf8 from subprocess import Popen, PIPE import os nginxpid = Popen(["pidof", "nginx"], stdout=PIPE) nginxpid = nginxpid.stdout.read().split() memsum = 0 for i in nginxpid: pidfile = os.path.join("/proc/", str(i), "status") with open(pidfile) as f: for mem in f: if mem.startswith("VmRSS"): pidmem = int(mem.split()[1]) memsum += pidmem print("%d %s" %(memsum,"KB"))
本文出自 “藍色_風暴” 博客,請務必保留此出處http://270142877.blog.51cto.com/12869137/1934859
使用python3.x實現統計Nginx進程所占用的物理內存