本帖最后由 ygqiang 于 2012-8-26 16:51 编辑
测试代码:- @echo off
- rem 记录cpu利用率,如果cpu利用率超过40%重启mssqlserver
-
- @echo off
- if "%1" == "h" goto begin
- mshta vbscript:createobject("wscript.shell").run("%~fs0 h",0)(window.close)&&exit
- :begin
- rem 下边开始写批处代码了(适合全自动场合)
-
- ping 127.0.0.1 -n 240 >nul 2>nul
-
-
- :begin1
-
- @echo off
- if "%1" == "h" goto begin
- mshta vbscript:createobject("wscript.shell").run("%~fs0 h",0)(window.close)&&exit
- :begin
- rem 下边开始写批处代码了(适合全自动场合)
-
- 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 :begin1
-
- exit
-
-
-
-
-
- taskkill /f /im sqlservr.exe
- taskkill /f /im sqlmangr.exe
-
- "C:\SQL2KSP4\x86\binn\sqlservr.exe"
- "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqlmangr.exe" /n
复制代码 不过这个代码,只能检测所有进程cpu占有率的总和。
bat能否实现:检测sqlservr.exe 这个进程,占用cpu超过40% 呢? |