有服务器2的CPU负载 [英] Load of server having 2 CPUs
问题描述
我有2 * CPU的服务器。当我在服务器上低于code运行它给出了两个CPU的LoadPercentage值:
I have a server with 2*CPU. when i run below code on server it gives two CPU LoadPercentage value as:
code:
@echo off
setlocal enabledelayedexpansion
(For /F "tokens=1,* delims==" %%A in ('"wmic cpu get LoadPercentage /value |find "P" "') do (
set "line=%%A %%B"
set "line=!line:~0,-1!"
echo !line!
))>output.txt
output.txt的:
LoadPercentage 2
LoadPercentage 4
虽然在任务管理器 - 服务器>性能其仅示出一个值(显然,如服务器为1)。
这怎么一个值显示,而CPU的两个......?它是平均二的的..?我如何使用批处理获得CPU负载百分比的单一价值?
While on server in task manager->performance its showing only one value (obviously, as server is 1). How this one value is showing while CPU's are two...? Is it average of two's..? How i can get that single value of CPU Load percentage using batch ?
推荐答案
是的,这是由负载处理器数量除以总和。
Yes, it's sum of loads divided by the number of processors.
在为
循环,当你的负荷,总结他们并计算CPU的数量。在为
退出,设置/一平均= ...
将给出答案。
In for
loop, as you get the loads, sum them and count the number of cpus. On for
exit, set /a average=...
will give the answer.
编辑(在OP自己的答案)
EDIT (over the OP own answer)
@echo off
setlocal enableextensions enabledelayedexpansion
rem Initialize variables
set sum=0
set num=0
rem Iterate over wmic output
for /f "tokens=2 delims==" %%1 in ('wmic cpu get LoadPercentage /value ^|find "P" ') do (
set /a sum=!sum!+%%1
set /a num=!num!+1
)
rem test if we get any data
if %num% gtr 0 (
set /a avg=%sum%/%num%
) else (
set avg=0
)
echo CPULoadPercentage %avg% > output.txt
exit /b
这篇关于有服务器2的CPU负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!