Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15175
  • 博文数量: 9
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2016-12-21 19:54
文章分类

全部博文(9)

文章存档

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 dd
if 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,memsize
memusedper = bufferused/memsize
print memusedper
sortproclist = []
sortmemlist = []
# print perfuserlist
#print commlist
#print cpuperlist
#cpu used per
psmemnum = 0
pscpunum = 0
testtuple = 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 += 1
memtuple = (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 xiaoshudian
sortmemlist.append(memtuple)
sortmemlist.sort(key=lambda x:float(x[2]),reverse=True)
print sortmemlist[0:10]
阅读(461) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~