Zabbix low-level discovery - CPU usage per process - two items with identical keys

I'm trying to use Zabbix for monitoring CPU usage by different processes on Windows Server. Processes to monitor are not determined upfront. I want to use LLD to monitor top 3 CPU demanding processes.

Currently I've created a discovery rule that returns top 3 CPU demanding processes at given moment, for example:

{
   {
      "name":"DistributedCacheService",
      "value":"9238.09375"
   },
   {
      "name":"System",
      "value":"6649.234375"
   },
   {
      "name":"svchost",
      "value":"5224.40625"
   }
}

Then I've created macros using json paths and item prototype and that's where i started to experience problems. I'm using earlier created LLD macro for item name and I'm using system.run command for obtaning a value in key field. Item name is supposed to process name and item key, value is supposed the CPU usage by that process. [enter image description here][1] [1]: https://i.stack.imgur.com/HuNbd.png

When testing discovery rule and item prototype everything runs fine, but when i try to run that discovery rule I get an error

"Cannot create item: item with the same key "system.run[powershell.exe -nolog -command "(Get-Process | Sort-Object CPU -desc | Select-Object -index 0 | Format-Table -Aut...]" already exists."

Firstly, there is no other item with the same key.

Secondly, when my discovery rule will detect other processes, there will have to be created other items with the same key. Other names, but the same key

Is it even possible to create processes CPU usage monitoring using LLD? I don't want to be stuck with predefined processes, I would like to have them dynamicly added with LLD.


Solution 1:

Zabbix requires keys be unique for a single host, so you'll run into problems when there is more than one of the same named process if you store processes by name (https://www.zabbix.com/documentation/current/manual/config/items/item)

Get-Process | sort "CPU" -Descending | select -First 3

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
    117   247.48     170.53   3,682.67    2232   1 Minesweeper
     47   564.25     528.42   3,491.36   15768   1 calc
     33   126.67      93.09   1,179.27   12960   1 Minesweeper

Process names don't need to be unique, so Get-Process returns objects with duplicate ProcessName values.

You can add -Unique to the select cmdlet to drop duplicates. This might hide data you want to log.

Get-Process | sort "CPU" -Descending | select -First 3 -Unique

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
    117   248.00     171.31   3,683.27    2232   1 Minesweeper
     47   563.74     527.91   3,491.36   15768   1 calc

The Zabbix team looks like they provided a workaround to this problem here: https://support.zabbix.com/browse/ZBXNEXT-164

UserParameter=top,top -n 1 -b|head -20