脚本如下:

#!/usr/bin/env python
#coding:utf-
import win32com.client
import time def disk_status():
try:
while :
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk")
print "time:" + time.strftime("%Y-%m-%d %H:%M:%S")
print "Device:" +'\t' + "tps" +'\t' + "kB_read/s" +'\t' + "kB_wrtn/s" +'\t' + "kB_read" +'\t' + "kB_wrtn" +'\t' +"Disk_free"
for objItem in colItems:
if objItem.Name != '_Total':
print objItem.Name +'\t' + str(objItem.DiskTransfersPersec) +'\t' + "%0.1f" % (float(objItem.DiskReadBytesPersec)/) +'\t' + '\t' + "%0.1f" % (float(objItem.DiskWriteBytesPersec)/) +'\t' + '\t' + "%0.1f" % (float(objItem.DiskReadsPersec)/) +'\t' + "%0.1f" % (float(objItem.DiskWritesPersec)/) +'\t' + "%0.0f%%" % objItem.PercentFreeSpace #Device: 显示磁盘名称
#tps: 表示每秒钟输出到物理磁盘的传输次数。一次传输就是一个对物理磁盘的 I/O 请求。多个逻辑请求可被并为对磁盘的一个单一 I/O 请求。传输具有中等的大小。
#kB_read/s: 每秒从磁盘读取的数据量,单位为KB。
#kB_wrtn/s: 每秒从写入磁盘的数据量,单位为KB。
#Kb_read: 读取的 KB 总数。
#Kb_wrtn: 写入的 KB 总数。
#DiskTransfersPerSec:每秒磁盘传输次数。
#DiskReadBytesPerSec:每秒从磁盘读取得数据量,单位为Byte。
#DiskWriteBytesPerSec:每秒从磁盘写取得数据量,单位为Byte。
#PercentFreeSpace:可用磁盘百分比
print ''
time.sleep()
except (EOFError,KeyboardInterrupt):
pass
if __name__ == '__main__':
disk_status()

执行结果:

time:-- ::
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn Disk_free
C: 437.6 700.2 0.1 0.1 %
D: 0.0 0.0 0.0 0.0 %
E: 0.0 0.0 0.0 0.0 %
F: 0.0 0.0 0.0 0.0 %
G: 0.0 0.0 0.0 0.0 %
H: 0.0 0.0 0.0 0.0 %
HarddiskVolume1 0.0 0.0 0.0 0.0 %
HarddiskVolume14 0.0 0.0 0.0 0.0 %
HarddiskVolume15 0.0 0.0 0.0 0.0 %
HarddiskVolume17 0.0 0.0 0.0 0.0 %
HarddiskVolume19 0.0 0.0 0.0 0.0 %
HarddiskVolume21 0.0 0.0 0.0 0.0 %
HarddiskVolume23 0.0 0.0 0.0 0.0 %
HarddiskVolume5 0.0 0.0 0.0 0.0 %
HarddiskVolume6 0.0 0.0 0.0 0.0 %

参考:http://blog.51cto.com/wangwei007/741083

安装win32com.client:

https://github.com/mhammond/pywin32/releases

最新文章

  1. Yii源码阅读笔记(三十)
  2. Python 之 装饰器的写法
  3. Java 对文件的读取操作
  4. 【wikioi】1022 覆盖(匈牙利)
  5. UIScrollView 期本使用方法
  6. windows command ftp 中文文件名乱码解决方法
  7. XML 格式转JSON 格式
  8. Android从入门到精通pdf+书源代码
  9. os8 location authorization 错误.
  10. jquery 浏览器放大缩小函数resize
  11. 安卓MP3播放器开发实例(1)之音乐列表界面
  12. window.open弹出窗口调用controller
  13. Nginx+IIS+Redis 处理Session共享问题 1
  14. Node入门教程(5)第四章:global 全局变量
  15. 第二章.python入门
  16. java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
  17. 性能测试六:jmeter进阶之Cookie与header管理器
  18. 解释变量(Explanatory Variable)
  19. ArcMap 导入Excel坐标数据
  20. 详解管理root用户权限的sudo服务程序

热门文章

  1. Spring超详细总结
  2. 01_console 你真的了解吗,不曾了解过得console~
  3. 08_jquery里面的$(this)和this都什么时候用,有什么区别
  4. C#操作注册表(简单方便,兼容X32和X64)
  5. Using TFRecords and tf.Example
  6. 天梯 L2 紧急救援 (dijkstra变形+记录路径)
  7. TypeScript 源码详细解读(1)总览
  8. 【转】Spring面试问题集锦
  9. GitHub项目绑定自己的域名
  10. POJ Muddy Fields 泥泞的牧场 二分图