import os
import win32api
import win32con
import wmi
import time
import requests
def getSysInfo(wmiService = None):
result = {}
if wmiService == None:
wmiService = wmi.WMI()
# cpu
for cpu in wmiService.Win32_Processor():
timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
result['cpuPercent'] = cpu.loadPercentage
# memory
cs = wmiService.Win32_ComputerSystem()
os = wmiService.Win32_OperatingSystem()
result['memTotal'] = int(int(cs[0].TotalPhysicalMemory)/1024/1024)
result['memFree'] = int(int(os[0].FreePhysicalMemory)/1024)
#disk
result['diskTotal'] = 0
result['diskFree'] = 0
for disk in wmiService.Win32_LogicalDisk(DriveType=3):
result['diskTotal'] += int(disk.Size)
result['diskFree'] += int(disk.FreeSpace)
result['diskTotal'] = int(result['diskTotal']/1024/1024)
result['diskFree'] = int(result['diskFree']/1024/1024)
return result
def make_message(msg):
return f'https://sc.ftqq.com/SCU23486T20f48c74769f0c6b72a918fe892307655ab14c6616304.send?text=庞銮先生你好!~&desp={msg}'
if __name__ == '__main__':
wmiService = wmi.WMI()
while True:
disk1 = getSysInfo(wmiService)
print(disk1)
time.sleep(3)
baifen = (disk1['diskTotal']-disk1['diskFree']) / disk1['diskTotal']
if baifen > 0.3 :
requests.post(make_message( '硬盘占用情况:{:.2%}'.format(baifen)))
监视硬盘占用情况
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...