python利用wmi模块统计windows下cpu信息
2012-09-03 13:59
330 查看
# -*- coding: utf-8 -*-
#import
########################################################################
import os, sys
import time
import wmi
########################################################################
#function
########################################################################
def get_cpu_info() :
tmpdict = {}
tmpdict["CpuCores"] = 0
c = wmi.WMI ()
for cpu in c.Win32_Processor():
tmpdict["CpuType"] = cpu.Name
try:
tmpdict["CpuCores"] = cpu.NumberOfCores
except:
tmpdict["CpuCores"] += 1
tmpdict["CpuClock"] = cpu.MaxClockSpeed
return tmpdict
def _read_cpu_usage():
c = wmi.WMI ()
for cpu in c.Win32_Processor():
return cpu.LoadPercentage
def get_cpu_usage():
"""
get cpu avg used by percent
"""
cpustr1 =_read_cpu_usage()
if not cpustr1:
return 0
time.sleep(2)
cpustr2 = _read_cpu_usage()
if not cpustr2:
return 0
cpuper = int(cpustr1)+int(cpustr2)/2
return cpuper
if __name__ == "__main__":
a = get_cpu_info()
print a
print '--------------------------'
b = get_cpu_usage()
print b其他python网站访问地址:http://bbs.pythonfan.org/thread-2348-1-1.html本文出自 “学海无涯苦作伴” 博客,请务必保留此出处http://linuxshow.blog.51cto.com/1572053/980639
#import
########################################################################
import os, sys
import time
import wmi
########################################################################
#function
########################################################################
def get_cpu_info() :
tmpdict = {}
tmpdict["CpuCores"] = 0
c = wmi.WMI ()
for cpu in c.Win32_Processor():
tmpdict["CpuType"] = cpu.Name
try:
tmpdict["CpuCores"] = cpu.NumberOfCores
except:
tmpdict["CpuCores"] += 1
tmpdict["CpuClock"] = cpu.MaxClockSpeed
return tmpdict
def _read_cpu_usage():
c = wmi.WMI ()
for cpu in c.Win32_Processor():
return cpu.LoadPercentage
def get_cpu_usage():
"""
get cpu avg used by percent
"""
cpustr1 =_read_cpu_usage()
if not cpustr1:
return 0
time.sleep(2)
cpustr2 = _read_cpu_usage()
if not cpustr2:
return 0
cpuper = int(cpustr1)+int(cpustr2)/2
return cpuper
if __name__ == "__main__":
a = get_cpu_info()
print a
print '--------------------------'
b = get_cpu_usage()
print b其他python网站访问地址:http://bbs.pythonfan.org/thread-2348-1-1.html本文出自 “学海无涯苦作伴” 博客,请务必保留此出处http://linuxshow.blog.51cto.com/1572053/980639
相关文章推荐
- python利用wmi模块统计windows下硬盘信息
- python利用wmi模块统计windows下网卡信息和连接数
- python利用wmi统计windows下内存信息
- Python 利用WMI监控windows状态如CPU、内存、硬盘
- 利用python自带的os模块删除windows机器的模块
- Python利用groupby模块进行Mysql分表数据的汇总统计
- python利用platform模块获取windows系统信息
- python利用WMI等监控获取windows状态如CPU、内存、硬盘等信息
- python使用wmi模块获取windows下的系统信息 监控系统
- python使用wmi模块获取windows下的系统信息 监控系统
- python利用WMI监控windows状态如CPU、内存、硬盘
- python使用wmi模块获取windows下硬盘信息的方法
- 利用python 与 wmi 获取WINDOWS基本信息
- Python用WMI模块获取Windows系统的硬件信息
- python使用wmi模块获取windows下硬盘信息的方法
- 利用Python进行数据导入、变化、统计和假设检验等基本数据分析
- python利用twilio模块发短信
- 利用python 下paramiko模块无密码登录
- windows下python安装Numpy和Scipy模块
- windows下使用pip安装python模块lxml