Search code examples
wildcardzabbix

Zabbix - wildcard usage in perf_counter


colleges!

I really need to use wildcard in perf_counter.

We have .NET Data Provider for SqlServer counters. Unfortunately, the ID on counter changes after each reboot.

Right now I have counter like this:

perf_counter["\.NET Data Provider for SqlServer(_lm_w3svc_3_root-3-131958133162924330[18196])\NumberOfActiveConnectionPools"]

How can I use it permanently. Maybe I need to use a wildcard like this:

perf_counter["\.NET Data Provider for SqlServer(_lm_w3svc_3_root-3-131958133162924330[*])\NumberOfActiveConnectionPools"]

The counter became unsupported with "Cannot obtain performance information from collector".

I really need your help! Thank you and have a nice day!


Solution

  • The documentation doesn't mention wildcards with performance counters.

    If your counter changes at every reboot you need to use a discovery rule even if you're dealing with a single item.

    The discovery rule could be a powershell script like:

    $result = @{}
    $result.data = @()
    
    (get-counter -Listset *).paths | ForEach-Object { 
        if ($_ -Like "*_lm_w3svc_3_root-3-131958133162924330*\NumberOfActiveConnectionPools") { 
            $result.data += @{
                "{#PATH}" = $_
            }
        }
    } 
    
    $result | ConvertTo-Json
    

    Set it to run every hour or less and create an item prototype like perf_counter["{#PATH}"], this should do the trick.