2016年(9)
分类: 系统运维
2016-12-23 15:07:01
感谢baidu,感谢网上其他人的分享。如果google不翻墙,会查找的更快。期间处理日常硬软件问题,自学自写python两个月。写了两三个版本,最后找到一个简化的。给自己点赞。 #取mem数值#elif checknum == 8 and len(re.findall('[0-9]',dd))>0:elif checknum == 8:# print ddif dd.find('Mem:')>=0:#memdetaillist.extend(ddlist[1:])memsize = int(ddlist[1])if dd.find("buffers/cache") >=0:#bufferlist= ddlist[2:4]bufferused = float(ddlist[2])# print memsize#process used analysys#抽取进程,给僵尸进程计数elif checknum ==9 and dd.find('processor begin')<0:perfuserlist.append(ddlist[0])pidlist.append(ddlist[1])cpuperlist.append(ddlist[2])memperlist.append(ddlist[3])commlist.append(ddlist[10][0:30])if dd.find('defunct')>0:zombnum =+ 1#根据生成的相应list,分析统计。print bufferused,memsizememusedper = bufferused/memsizeprint memusedpersortproclist = []sortmemlist = []# print perfuserlist#print commlist#print cpuperlist#cpu used perpsmemnum = 0pscpunum = 0testtuple = None# print cpuperlist[1:]# print 'cpu used'# for cpuper in cpuperlist[1:]:# pscpunum += 1# proctuple = (perfuserlist[pscpunum],int(pidlist[pscpunum]),cpuperlist[pscpunum],commlist[pscpunum])# testtuple = (perfuserlist[pscpunum],int(pidlist[pscpunum]),decimal.Decimal(cpuperlist[pscpunum]),commlist[pscpunum]) /bimianfloat xiaoshudian# sortproclist.append(proctuple)#if float(cpuper) > 0:# print perfuserlist[pscpunum],pidlist[pscpunum],float(cpuper)/100, commlist[pscpunum]# sortproclist.sort(key=lambda x:float(x[2]),reverse=True)#print sortproclist[0:10]print 'mem used'#print memperlist.sort()for cpuper in memperlist[1:]:psmemnum += 1memtuple = (perfuserlist[psmemnum],int(pidlist[psmemnum]),int(decimal.Decimal(memperlist[psmemnum])*memsize/100),cpuperlist[psmemnum],commlist[psmemnum])# testtuple = (perfuserlist[pscpunum],int(pidlist[pscpunum]),decimal.Decimal(cpuperlist[pscpunum]),commlist[pscpunum]) /bimianfloat xiaoshudiansortmemlist.append(memtuple)sortmemlist.sort(key=lambda x:float(x[2]),reverse=True)print sortmemlist[0:10]