windows获取硬盘使用率等信息
windows获取硬盘使⽤率等信息
1#coding=utf8
2import psutil
3 cpu = {'user' : 0, 'system' : 0, 'idle' : 0, 'percent' : 0}
4 mem = {'total' : 0, 'avaiable' : 0, 'percent' : 0, 'used' : 0, 'free' : 0}
5
6#磁盘名称
7 disk_id = []
8#将每个磁盘的total used free percent 分别存⼊到相应的list
9 disk_total = []马景涛老婆唐韵
中古战锤10 disk_used = []
11 disk_free = []
12 disk_percent = []
13
14#获取磁盘
15def get_disk_info():
16for id in psutil.disk_partitions():
17if'cdrom'in id.opts or id.fstype == '':
18continue
19        disk_name = id.device.split(':')
20        s = disk_name[0]
21        disk_id.append(s)
22
国庆不放假属于违法吗23        disk_info = psutil.disk_usage(id.device)
24
25        disk_total.append(al)
26        disk_used.append(disk_info.used)
27        disk_free.append(disk_info.free)
28        disk_percent.append(disk_info.percent)
29
30#获取CPU信息
31def get_cpu_info():
32    cpu_times = psutil.cpu_times()
33    cpu['user'] = cpu_times.user
34    cpu['system'] = cpu_times.system
35    cpu['idle'] = cpu_times.idle
36    cpu['percent'] = psutil.cpu_percent(interval=2)
37#获取内存信息
38def get_mem_info():
39    mem_info = psutil.virtual_memory()
40    mem['total'] = al
41    mem['available'] = mem_info.available
42    mem['percent'] = mem_info.percent
43    mem['used'] = mem_info.used
44    mem['free'] = mem_info.free
45
全自动条幅机46if__name__ == '__main__':
47    get_cpu_info()
中国杀人排行榜
48    cpu_status = cpu['percent']
哈尔滨特小吃
49print u"CPU使⽤率: %s %%" % cpu_status
50    get_mem_info()
51    mem_status = mem['percent']
52print u"内存使⽤率: %s %%" % mem_status
53    get_disk_info()
54for i in range(len(disk_id)):
55print u'%s盘空闲率: %s %%' % (disk_id[i],100 - disk_percent[i])
56    raw_input("Enter enter key ")
执⾏结果如下:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。