cpu_mem_directories.py CPU、内存、硬盘分区的检测
#!/usr/bin/env python #coding:utf-8 import psutil import time import sys from optparse import OptionParser parser = OptionParser() parser.add_option("-t", "--time", dest="time", help="此参数可查看当前下载占的带宽,-t是测试时间", metavar="10") parser.add_option("-d", "--deamon",action="store_false", dest="deamon", default=True, help="后台运行此脚本") def Sysinfo(): Boot_Start = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(psutil.boot_time())) time.sleep(0.5) Cpu_usage = psutil.cpu_percent() RAM = int(psutil.virtual_memory().total/(1027*1024)) RAM_percent = psutil.virtual_memory().percent Swap = int(psutil.swap_memory().total/(1027*1024)) Swap_percent = psutil.swap_memory().percent Net_sent = psutil.net_io_counters().bytes_sent Net_recv = psutil.net_io_counters().bytes_recv Net_spkg = psutil.net_io_counters().packets_sent Net_rpkg = psutil.net_io_counters().packets_recv BFH = r'%' print " 33[1;32m开机时间:%s 33[1;m" % Boot_Start print " 33[1;32m当前CPU使用率:%s%s 33[1;m" % (Cpu_usage,BFH) print " 33[1;32m物理内存:%dM 使用率:%s%s 33[1;m" % (RAM,RAM_percent,BFH) print "