window bat cmd 获取cpu 利用率(使用率)跟 性能计数器一致,方式收集

1. typeperf (1秒一输出)

typeperf "processor(_total)\% processor time"

若是只要执行一次,末尾添加  -sc 1,如下:

typeperf "processor(_total)\% processor time" -sc 1

 

windows 监控指标采集_任务管理器

 

2. powershell

Powershell "Get-Counter '\Processor(*)\% Processor Time' | Select -Expand Countersamples |Select InstanceName, CookedValue"
Get-Counter -Counter "\Processor(_Total)\% Processor Time" -Continuous

windows 监控指标采集_性能监视_02

 

3.wmic

wmic cpu get loadpercentage

windows 监控指标采集_性能监视_03

 

5. bat 

@echo off
for /f "tokens=2 delims==" %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value^|findstr "PercentProcessorTime"') do (
set UseCPU=%%a
)
echo CPU使用率:%UseCPU%%%
pause

获取到跟任务管理器不大一样,性能监视器(perfmon)又是一致的。

cmd 输入 perfmon 监视项选择 Processor Time