# ModbusGateway 监控脚本# 每5分钟记录一次运行状态$logFile = "modbusgateway_monitor.log"$header = "Time,PID,Memory(MB),CPU,Handles"# 写入表头if (!(Test-Path $logFile)) { $header | Out-File -FilePath $logFile -Encoding UTF8}# 监控循环while ($true) { $time = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $processes = Get-Process | Where-Object {$_.ProcessName -eq "modbusgateway"} foreach ($proc in $processes) { $memory = [math]::Round($proc.WS/1MB, 2) $cpu = $proc.CPU $handles = $proc.Handles "$time,$($proc.Id),$memory,$cpu,$handles" | Out-File -FilePath $logFile -Encoding UTF8 -Append } # 每5分钟执行一次 Start-Sleep -Seconds 300}