首页 » 脚本 » 正文

获取系统负载的脚本

#!/usr/bin/python
import os
def load_stat():
 loadavg = {}
 f = open(“/proc/loadavg”)
 con = f.read().split()
 f.close()
 loadavg[‘lavg_1’]=con[0]
 loadavg[‘lavg_5’]=con[1]
 loadavg[‘lavg_15’]=con[2]
 loadavg[‘nr’]=con[3]
 loadavg[‘last_pid’]=con[4]
 return loadavg
print “loadavg”,load_stat()[‘lavg_1’]

发表评论