
[已解決]bat批處理實(shí)現(xiàn)檢測所有進(jìn)程cpu占有率的總和超過40%就執(zhí)行某個代碼最后由 ygqiang 于 -8-29 17:50bat批處理實(shí)現(xiàn):檢測所有進(jìn)程cpu占有率的總和超過40%,就執(zhí)行某個代碼。
上面這個代碼,測試是沒有問題。如果再加上下面這個判斷時間范圍的代碼,測試也能通過。(在規(guī)定時間范圍內(nèi),cpu總的占用超過40%,就執(zhí)行停止、開啟sql數(shù)據(jù)庫操作)。nclick="copycode($('code0'));">復(fù)制代碼
- set Services1=mssqlserver
- for /f tokens=2 delims== %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value
- ^| findstr PercentProcessorTime') do (
- set CPUUsage=%%a
- )
- if %CPUUsage% geq 40 (
- net stop %Services1%
- ping 127.0.0.1 -n 1 >nul 2>nul
- net start %Services1%
- )
- exit
nclick="copycode($('code1'));">復(fù)制代碼
- :begin1
- ping 127.0.0.1 -n 600 >nul 2>nul
- :begin2
- if %time:~0,2% geq 11 (if %time:~3,2% leq 15 goto :stat)
- if %time:~0,2% geq 17 (if %time:~3,2% leq 20 goto :stat)
- goto :begin1
- :stat
- set Services1=mssqlserver
- for /f tokens=2 delims== %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value
- ^| findstr PercentProcessorTime') do (
- set CPUUsage=%%a
- )
- if %CPUUsage% geq 40 (
- net stop %Services1%
- ping 127.0.0.1 -n 1 >nul 2>nul
- net start %Services1%
- )
- ping 127.0.0.1 -n 10 >nul 2>nul
- goto :begin2

