繁体   English   中英

powershell - zabbix 获取 cpu 进程并发送 %

[英]powershell - zabbix take cpu processes and send in %

我想通过 zabbix 以 % 监视 windows cpu 进程,但 windows 不支持 zabbix item proc.cpu.util[Sqlsvr.exe]。

所以我尝试在powershell中做一个脚本并由zabbix执行,我不知道它是否是一个好主意,你有想法吗?

我的powershell脚本以%为单位进行cpu进程:

$test = Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process
-filter "Name='chrome'" | 
    Select-Object @{ Expression = {$_.PercentProcessorTime}} |Format-Table -AutoSize
     echo $test

你有想法在 % 中采用 cpu 进程还是只在 % 中采用 cpu 进程?

Zabbix 期望来自插件的数值。 它的目的不是为您提供您正在寻找的统计信息,而是像 Newrelic 这样的性能工具。 您的代码返回进程的集合。 试试这个镀铬工艺:

# Declare collection
$t = New-Object System.Collections.ArrayList;
# For loop 5 times
For ($i=0; $i -lt 5; $i++) {
    # Add slot cpu time 
    [void]$t.Add( (Get-Counter "\Process(chrome)\% Processor Time").CounterSamples.CookedValue );
    sleep -Seconds 1;
}
# Return average with two decimal places
write-host ([math]::Round(($t | Measure-Object -Average).Average, 2));

暂无
暂无

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

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