python下wmi模块介绍之四:得到cpu的占用率
python下wmi模块介绍之四:得到cpu的占用率
今天继续介绍下利用python的wmi模块来得到当前机器的CPU的占用率是多少,下面看下代码:
#-*- encoding: utf-8 -*-
Created on 2011-3-1
@author: hack7th
import wmi
import time
c = wmi.WMI()
while True:
for cpu in c.Win32_Processor():
timestamp = time.strftime(%a, %d %b %Y %H:%M:%S, time.localtime())
print %s | Utilization: %s: %d %% % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
time.sleep(5)
#-*- encoding: utf-8 -*-
Created on 2011-3-1
@author: hack7th
import wmi
import time
c = wmi.WMI()
while True:
for cpu in c.Win32_Processor():
timestamp = time.strftime(%a, %d %b %Y %H:%M:%S, time.localtime())
print %s | Utilization: %s: %d %% % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
time.sleep(5)
本文来自: Rootexp
相关内容
- 暂无相关文章
评论关闭