简体   繁体   English

获取与Powershell计数器一起使用的CPU的百分比

[英]getting percentage of cpu used with powershell counter

I am trying to get with powershell script, the percentage of cpu used by my server. 我正在尝试使用Powershell脚本,即服务器使用的cpu百分比。 I developp a solution by searching on the net, but I am still a debutant and not sure about the real meaning of the value I get with this solution. 我通过在网上搜索来开发解决方案,但是我仍然是一个初学者,并且不确定通过该解决方案获得的价值的真正含义。 I did some research on the net, but answers are still giving me more doubt. 我在网上做了一些研究,但答案仍然使我更加怀疑。

This is my script : 这是我的脚本:

function GetPercentageOfCpuUsed()
{
 $value = Get-Counter "\Processor(_Total)\% Processor Time"
 $Value = $value.CounterSamples[0].CookedValue  
 return $Value
}

Is the "value" returned corresponds to the percentage of cpu used by my server at the time when I run my powershell script ? 返回的“值”是否对应于运行Powershell脚本时服务器使用的cpu百分比?

\\Processor(_Total)\\% Processor Time is a performance counter that tells you the percentage of time the processors were busy during the sampling interval (Source: http://technet.microsoft.com/en-us/library/cc938593.aspx ). \\Processor(_Total)\\% Processor Time是一个性能计数器,它告诉您在采样间隔内处理器繁忙的时间百分比(来源: http : //technet.microsoft.com/zh-cn/library/cc938593.aspx )。 For instance, in a 4-core system, one CPU with 100% usage and the rest of the CPUs running entirely idle should give you 25%. 例如,在4核系统中,一个CPU的使用率为100%,而其余CPU完全处于空闲状态则应该为您提供25%。 You can also monitor this counter live using the Performance Monitor MMC of Windows to get an impression how it behaves. 您还可以使用Windows的性能监视器MMC实时监视此计数器,以了解其行为。 According to the Technet article above, this figure is also the same as the CPU Usage figure in the Task Manager. 根据上面的Technet文章,此图也与任务管理器中的CPU使用率图相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM