zoukankan      html  css  js  c++  java
  • python 统计nmon 监控结果 简易版

    当前版本为简易版,仅能够统计在监控时设定的时间。

    如 nmon -fs 1 -c 10

    即统计10秒钟内,系统cpu和内存的平均使用率,后续将进一步完善。

    #获取文件名
    import string
    
    fileName = raw_input("输入文件名:\n")
    
    fileText = open(fileName,'r')
    
    text = fileText.readlines()
    
    ##获取监控频率 和 次数
    second = 0.0
    count = 0.0
    
    #监控时要严格按照该格式 nmon -fs second -c count
    
    for line in text:
        if 'AAA,command' in line:
            second = string.atof(line.split(' ')[2])
            count = string.atof(line.split(' ')[4])
            
    #处理text
            
    #获取CPU
    CPU_TXT = []
    
    for line in text:
        if 'CPU_ALL,T' in line:
            CPU_TXT.append(line)
    #计算CPU
    
    #将列表的每一项split后 按照idle列 计算CPU
    CPUVALUE=''
    CPU_VALUE = 0.0
    CPU_AVG_VALUE = 0.0
    
    for CPU in CPU_TXT:
        CPU_VALUE = CPU_VALUE + 100.0 - string.atof(CPU.split(',')[5])
    #平均使用率
    CPU_AVG_VALUE = CPU_VALUE/count
    time = second * count /60
    print "共监控",time, "minutes\n"
    print "CPU的平均使用率为:" ,CPU_AVG_VALUE,'%\n'
        
    #获取内存
    MEM_TXT = []
    
    for line in text:
        if 'MEMUSE,T' in line:
            MEM_TXT.append(line)
    #计算内存
    
    #将列表的每一项split后 ,根据第三项Memory Use sop21 来统计MEMUSE
    MEMVALUE=''
    MEM_VALUE = 0.0
    MEM_AVG_VALUE = 0.0
    
    for MEM in MEM_TXT:
        MEM_VALUE = MEM_VALUE + string.atof(MEM.split(',')[2])
    
    
    
        
    #平均使用率
        
    MEM_AVG_VALUE = MEM_VALUE/count
    
    print "内存的平均使用率为:",MEM_AVG_VALUE,'%'
    #print text
    
    #print text[3]
    
    #关闭文件
    fileText.close()
  • 相关阅读:
    ubuntu开启SSH服务
    Ubuntu修改虚拟内存(即swap空间)
    【转】Ubuntu 13.10中MyEclipse 10.6+下载+安装+破解
    【转】 ubuntu下安装mysql
    【转】 Ubuntu 11.04 下安装配置 JDK 7
    Linux非root用户安装jdk和tomcat
    algorithm之改变序列算法--待解决
    时间日期设置--ctime头文件
    C中的一些函数
    algorithm之不变序列操作
  • 原文地址:https://www.cnblogs.com/katero/p/2918755.html
Copyright © 2011-2022 走看看