使用python3.x实现统计Nginx进程所占用的物理内存

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用python3.x实现统计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进程所占用的物理内存的主要内容,如果未能解决你的问题,请参考以下文章