python计算apache总内存
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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总内存的主要内容,如果未能解决你的问题,请参考以下文章
什么是在 C++ 中获取总内核数量的跨平台代码片段? [复制]