码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-06-13 14:19:41      阅读:160      评论:0      收藏:0      [点我收藏+]

标签: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进程所占用的物理内存

标签:linux   进程   统计   python   nginx   

原文地址:http://270142877.blog.51cto.com/12869137/1934859

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!