zoukankan      html  css  js  c++  java
  • 统计nginx进程占用的物理内存

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    ''' 统计nginx进程占用的物理内存 '''
    
    import os
    import sys
    import subprocess
    
    def getPidList(proc):
        cmd = '''/usr/sbin/pidof %s''' % proc
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
        pidList = p.stdout.read().split()
        return pidList
    
    
    def getMemSize(pidList):
        sum = 0
        for pid in pidList:
            filename = os.path.join('/proc', pid, 'status')
            with open(filename) as fd:
                 for line in fd.readlines():
                     if line.startswith('VmRSS'):
                         memSize = int(line.split()[1])
                         sum += memSize
                         break
        return sum
    
    if __name__ == '__main__':
        proc = sys.argv[1]
        pidList = getPidList(proc)
        totalMem = getMemSize(pidList)
        print('%s占用物理内存:%sK' % (proc.capitalize(), totalMem))
    [root@localhost ~]$ python 1.py nginx
    Nginx占用物理内存:8056K

        

  • 相关阅读:
    17.10.13
    17.10.12
    17.10.11
    17.10.10
    17.10.05
    17.10.04
    17.10.03
    17.10.02
    17.10.01
    17.9.29
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10314196.html
Copyright © 2011-2022 走看看