-
<PYTHON>[psutil]Flower in my dev/Python 2015. 8. 21. 14:37
[psutil]
-cpu_times : CPU 사용 정보
-cpu_percent : CPU 사용률(%)
-cpu_count : CPU 개수(논리)
-cpu_times_percent : CPU 사용 정보(%)
- virtual_memory : 메모리 사용 정보
- swap_memory : 스왑 사용 정보
- disk_partitions : 디스크 사용 정보
- disk_usage : 디스크 사용량
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849def getLoad(self, now):cpu_result, mem_result, swap_result, disk_result, network_result = {}, {}, {}, {}, {}# CPUtry:cpu = psutil.cpu_times_percent()total = cpu.user + cpu.system + cpu.idleif total > 100:cpu_result['user'] = 100 - (cpu.system + cpu.idle)else:cpu_result['user'] = cpu.userif total < 100:cpu_result['idle'] = 100 - (cpu.system + cpu_result['user'])else:cpu_result['idle'] = cpu.idlecpu_result['kernel'] = cpu.systemcpu_result['idle'] = cpu.idleexcept Exception as e:log.err(e)# memtry:mem = psutil.virtual_memory()mem_result['total'] = mem.total/1024. # kbytesmem_result['used'] = mem.used/1024.mem_result['free'] = mem.available/1024.except Exception as e:log.err(e)# swaptry:swap = psutil.swap_memory()swap_result['total'] = swap.total/1024. # kbytesswap_result['used'] = swap.used/1024.swap_result['free'] = swap.free/1024.except Exception as e:log.err(e)# diskfor partition in psutil.disk_partitions():if ('removable' in partition.opts) or ('cdrom' in partition.opts):continuemountPoint = partition.mountpointdiskInfo = psutil.disk_usage(mountPoint)disk_result[mountPoint.replace(":", "_").replace('\\', '')] = (diskInfo.percent, diskInfo.total)cs 'Flower in my dev > Python' 카테고리의 다른 글
<PYTHON>[json] (0) 2015.08.21 <PYTHON>[platform] (0) 2015.08.21 <PYTHON>[numpy, scipy, matplotlib] 설치 (0) 2015.08.17 <PYTHON>[한글 사용] (0) 2015.07.28 <PYTHON>[socket:UDP] (0) 2015.07.28