首页 > 代码库 > python计算apache总内存
python计算apache总内存
#!/usr/bin/env python import os from subprocess import Popen, PIPE def getPid(): p=Popen([‘pidof‘,‘httpd‘],stdout=PIPE,stderr=PIPE) pids = p.stdout.read().split() return pids def paresPidFile(pids): sum =0 for i in pids: fn = os.path.join(‘/proc/‘,i,‘status‘) with open(fn) as fd: for line in fd: if line.startswith(‘VmRSS‘): http_mem =int(line.split()[1]) sum += http_mem break return sum def total_mem(f): with open(f) as fd: for line in fd: if line.startswith(‘MemTotal‘): total_mem =int(line.split()[1]) return total_mem if __name__ ==‘__main__‘: pids = getPid() http_mem = paresPidFile(pids) total = total_mem(‘/proc/meminfo‘) print"Apache memory is: %s KB"% http_mem print "Percent: %.2f%%"%(http_mem/float(total)*100)
python计算apache总内存
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。