如何用Python实现cpu和内存的监控
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用Python实现cpu和内存的监控相关的知识,希望对你有一定的参考价值。
参考技术A #!/usr/bin/env python# -*- coding: utf-8 -*-
import wmi
import time
def cpu_mem():
c = wmi.WMI()
for processor in c.Win32_Processor():
print ("Processor ID: %s" % processor.DeviceID )
print( "Process Name: %s" % processor.Name.strip() )
for Memory in c.Win32_PhysicalMemory():
print( "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576) )
def cpu_use():
c = wmi.WMI()
for i in range(1,3): # 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(3)
def main():
cpu_mem()
cpu_use()本回答被提问者采纳
以上是关于如何用Python实现cpu和内存的监控的主要内容,如果未能解决你的问题,请参考以下文章