【问题标题】:powershell - zabbix take cpu processes and send in %powershell - zabbix 采用 cpu 进程并发送 %
【发布时间】:2019-04-02 08:41:30
【问题描述】:

我想通过 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 进程?

【问题讨论】:

    标签: powershell zabbix


    【解决方案1】:

    Zabbix 需要一个来自插件的数值。它并非旨在为您提供您正在寻找的统计数据,而是像 Newrelic 这样的性能工具。您的代码返回一个进程集合。试试这个 chrome 进程:

    # 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));
    

    【讨论】:

    • 我只想和 zabbix 一起使用 @Iggy Zofrin
    • 那么你需要有一个powershell脚本,它为sql server [math]::Round((Get-Counter "\Process(sqlservr)\% Processor Time").CounterSamples. CookedValue) 在 zabbix windows agent zabbix_agentd.conf 中添加 UserParameter=sql.cpupercent,C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell C:\path_to_yourscript.ps1 在 zabbix 控制台中添加新项目: type: Zabbix agent Key: sql .cppercent
    • 好的,我做了 sript,但我在 powershell 中表现不佳,我想以每秒 % 的速度使用 zabbix_agentd 处理器,然后平均处理:目前我有这个 scipt : For ($i=0 ; $i -le 5; $i++) { #$t = New-Object System.Collections.ArrayList #sleep 1 #$t = #echo $t #$t.Add([math]::Round((Get-计数器 "\Process(zabbix_agentd)\% Processor Time").CounterSamples.CookedValue)) $t = @([math]::Round((Get-Counter "\Process(zabbix_agentd)\% Processor Time").CounterSamples. CookedValue)) #echo $t[$i] } echo $t[0]`n $t.count @Iggy Zofrin
    • 谢谢@Iggy Zofrin,你确定zabbix item key sql.cpupercent 工作吗?
    • 当我使用此密钥创建新项目时,我收到消息“不支持”:#system.run["powershell.exe -NoProfile -ExecutionPolicy ByPass -File C:\zabbix\conf\CPU_% .ps1"] #system.run["C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\zabbix\conf\CPU_%.ps1",] @Iggy Zofrin
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多