-2

i want monitor windows cpu processes in % by zabbix but zabbix item proc.cpu.util[Sqlsvr.exe] is not supported in windows.

so i try to do a script in powershell and executed by zabbix, i don't know if its a good idea, do you have idea ?

my powershell script to take cpu process in %:

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

do you have idea to take cpu process in % or take only cpu process in % ?

jack94
  • 43
  • 1
  • 8

1 Answers1

1

Zabbix expects a numeric value from a plugin. It is not designed to give you statistics you are looking for, that would be performance tools like Newrelic. Your code returns a collection of processes. try this for chrome process:

# 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));
Iggy Zofrin
  • 515
  • 3
  • 10
  • i want use with zabbix only @Iggy Zofrin – jack94 Apr 02 '19 at 12:04
  • Then you need to have a powershell script that returns a numeric value for sql server [math]::Round((Get-Counter "\Process(sqlservr)\% Processor Time").CounterSamples.CookedValue) In zabbix windows agent zabbix_agentd.conf add UserParameter=sql.cpupercent,C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell C:\path_to_yourscript.ps1 In zabbix console add new item: type: Zabbix agent Key: sql.cpupercent – Iggy Zofrin Apr 02 '19 at 22:34
  • ok, i do the sript but i'me not good in powershell, i want take zabbix_agentd processor in % each second and do after a average : currently i have this scipt : For ($i=0; $i -le 5; $i++) { #$t = New-Object System.Collections.ArrayList #sleep 1 #$t = #echo $t #$t.Add([math]::Round((Get-Counter "\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 – jack94 Apr 05 '19 at 09:04
  • Thanks @Iggy Zofrin, are you sure zabbix item key sql.cpupercent work ? – jack94 Apr 08 '19 at 09:59
  • i have the message "Not supported" when i creat new item with this key : #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 – jack94 Apr 09 '19 at 07:20
  • "Not supported" means you have not followed suggestion in second comment detailing the User parameter. What is not clear about the answer? I practically spoon-fed you solution. I suspect you are not understanding how Zabbix works. Read https://www.zabbix.com/documentation/1.8/manual/tutorials/extending_agent – Iggy Zofrin Apr 12 '19 at 23:43