File size: 4,035 Bytes
82ea528 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
from server import PromptServer
from aiohttp import web
from ..core import logger
from ..general import cmonitor
@PromptServer.instance.routes.patch("/crystools/monitor")
async def newSettings(request):
try:
settings = await request.json()
# print(settings)
if 'rate' in settings is not None:
rate = settings['rate']
if type(rate) is not int and type(rate) is not float:
raise Exception('Rate must be an number.')
if cmonitor.rate == 0 and rate > 0:
cmonitor.rate = rate
cmonitor.startMonitor()
else:
cmonitor.rate = rate
if 'switchCPU' in settings is not None:
switchCPU = settings['switchCPU']
if type(switchCPU) is not bool:
raise Exception('switchCPU must be an boolean.')
cmonitor.hardwareInfo.switchCPU = switchCPU
if 'switchHDD' in settings is not None:
switchHDD = settings['switchHDD']
if type(switchHDD) is not bool:
raise Exception('switchHDD must be an boolean.')
cmonitor.hardwareInfo.switchHDD = switchHDD
if 'switchRAM' in settings is not None:
switchRAM = settings['switchRAM']
if type(switchRAM) is not bool:
raise Exception('switchRAM must be an boolean.')
cmonitor.hardwareInfo.switchRAM = switchRAM
if 'whichHDD' in settings is not None:
whichHDD = settings['whichHDD']
if type(whichHDD) is not str:
raise Exception('whichHDD must be an string.')
cmonitor.hardwareInfo.whichHDD = whichHDD
return web.Response(status=200)
except Exception as e:
logger.error(e)
return web.Response(status=400, text=str(e))
@PromptServer.instance.routes.post("/crystools/monitor/switch")
async def monitorSwitch(request):
try:
switch = await request.json()
if 'monitor' in switch is not None:
monitor = switch['monitor']
if type(monitor) is not bool:
raise Exception('monitor must be an boolean.')
if monitor:
cmonitor.startMonitor()
else:
cmonitor.stopMonitor()
return web.Response(status=200)
except Exception as e:
logger.error(e)
return web.Response(status=400, text=str(e))
@PromptServer.instance.routes.get("/crystools/monitor/HDD")
def getHDDs(request):
try:
return web.json_response(cmonitor.hardwareInfo.getHDDsInfo())
except Exception as e:
logger.error(e)
return web.Response(status=400, text=str(e))
@PromptServer.instance.routes.get("/crystools/monitor/GPU")
def getGPUs(request):
try:
gpuInfo = cmonitor.hardwareInfo.getGPUInfo()
return web.json_response(gpuInfo)
except Exception as e:
logger.error(e)
return web.Response(status=400, text=str(e))
@PromptServer.instance.routes.patch("/crystools/monitor/GPU/{index}")
async def getGPUs(request):
try:
index = request.match_info["index"]
settings = await request.json()
if 'utilization' in settings is not None:
if type(settings['utilization']) is not bool:
raise Exception('utilization must be an boolean.')
cmonitor.hardwareInfo.GPUInfo.gpusUtilization[int(index)] = settings['utilization']
if 'vram' in settings is not None:
if type(settings['vram']) is not bool:
raise Exception('vram must be an boolean.')
cmonitor.hardwareInfo.GPUInfo.gpusVRAM[int(index)] = settings['vram']
if 'temperature' in settings is not None:
if type(settings['temperature']) is not bool:
raise Exception('temperature must be an boolean.')
cmonitor.hardwareInfo.GPUInfo.gpusTemperature[int(index)] = settings['temperature']
return web.Response(status=200)
except Exception as e:
logger.error(e)
return web.Response(status=400, text=str(e))
|