Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-IcingaCheckMSSQLResource uses wrong/insufficient query #50

Open
Donien opened this issue Mar 14, 2023 · 4 comments
Open

Invoke-IcingaCheckMSSQLResource uses wrong/insufficient query #50

Donien opened this issue Mar 14, 2023 · 4 comments

Comments

@Donien
Copy link

Donien commented Mar 14, 2023

When using Invoke-IcingaCheckMSSQLResource the effective query used is

SELECT
    RTRIM(object_name) as object_name,
    RTRIM(counter_name) as counter_name,
    RTRIM(instance_name) as instance_name,
    RTRIM(cntr_value) as cntr_value,
    RTRIM(cntr_type) as cntr_type
        FROM sys.dm_os_performance_counters
            WHERE (object_name = 'SQLServer:Buffer Manager' AND counter_name = 'page life expectancy')
               OR (object_name = 'SQLServer:Buffer Manager' AND counter_name = 'Buffer cache hit ratio')
               OR (object_name = 'SQLServer:Latches' AND counter_name = 'Average Latch Wait Time (ms)')
               OR (object_name = 'SQLServer:Buffer Manager' AND counter_name = 'Buffer cache hit ratio base')
               OR (object_name = 'SQLServer:Latches' AND counter_name = 'Average Latch Wait Time Base');

In my case, using MSSQL-Server Express Edition, this query returns no results since the

object_name column does not look like

object_name = 'SQLServer:Buffer Manager'

but instead looks like

object_name = 'MSSQL$SQLEXPRESS01:Buffer Manager'

for example.

At least in the case of MSSQL-Server Express Edition the direct string comparison does not seem to be sufficient.

@winter1967
Copy link

winter1967 commented Mar 15, 2023

Additionaly:
At our servers, we use 'named instances', so the following queries may be helpful:

WHERE (object_name LIKE '%:Buffer Manager%'  AND counter_name = 'page life expectancy')
               OR (object_name LIKE '%:Buffer Manager%' AND counter_name = 'Buffer cache hit ratio')
               OR (object_name LIKE '%:Latches%' AND counter_name = 'Average Latch Wait Time (ms)')
               OR (object_name LIKE '%:Buffer Manager%' AND counter_name = 'Buffer cache hit ratio base')
               OR (object_name LIKE '%:Latches%' AND counter_name = 'Average Latch Wait Time Base');

@audiocoach
Copy link

audiocoach commented Jan 29, 2024

Same for me. I am also using named instances.

Same problem with Invoke-IcingaCheckMSSQLPerfCounter.
If you set "\SQLServer:Buffer Manager\Buffer cache hit ratio" as performance counter value the result is "No checks added to this package"
If you use the named instance instead of \SQLServer it is working as expected. For example my named instance is MYDATABASE01. So I need to use "\MSSQL$MYDATABASE01::Buffer Manager\Buffer cache hit ratio" as performance counter value.

@audiocoach
Copy link

audiocoach commented Jan 29, 2024

And if you are using the direcor you have to set '\MSSQL$$MYDATABASE01::Buffer Manager\Buffer cache hit ratio'

@audiocoach
Copy link

audiocoach commented Jan 30, 2024

Ok, I think I have found a solution. I don't know if it is the best way to solve the problem but for me it works. You have to change the follwing files:

C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-mssql\provider\mssql\Get-IcingaMSSQLPerformanceCounter.psm1
Change Line 108
"{0}(object_name = '{1}' AND counter_name = '{2}') OR ", to "{0}(object_name LIKE '{1}' AND counter_name = '{2}') OR ",

Change Line 117
"{0}(object_name = '{1}' AND counter_name = '{2}' AND instance_name = '{3}') OR ", to "{0}(object_name LIKE '{1}' AND counter_name = '{2}' AND instance_name = '{3}') OR ",

C:\Program Files\WindowsPowerShell\Modules\icinga-powershell-mssql\plugins\Invoke-IcingaCheckMSSQLResource.psm1
Change Line 102-107 to:

            '\%:Buffer Manager%\page life expectancy',
            '\%:Buffer Manager%\Buffer cache hit ratio',
            '\%:Latches%\Average Latch Wait Time (ms)',
            '\%:Buffer Manager%\Buffer cache hit ratio base',
            '\%:Latches%\Average Latch Wait Time Base'

Change Line 140-158 to:

        switch -Wildcard ($FullName) {
            '\*:Buffer Manager\page life expectancy' {
                $Check = (New-IcingaCheck -Name $Entry.counter_name -Value $Entry.cntr_value -Unit 's' -MetricIndex $SerializedCounter.Category -MetricName $SerializedCounter.Counter).WarnOutOfRange($PageLifeExpectancyWarning).CritOutOfRange($PageLifeExpectancyCritical);  
                break;
            };
            '\*:Buffer Manager\Buffer cache hit ratio' {
                $Check = (New-IcingaCheck -Name $Entry.counter_name -Value (($Entry.cntr_value * 1.0 / $BufferRatioBase) * 100) -Unit '%' -MetricIndex $SerializedCounter.Category -MetricName $SerializedCounter.Counter).WarnOutOfRange($BufferCacheHitRatioWarning).CritOutOfRange($BufferCacheHitRatioCritical);
                break;
            };
            '\*:Latches\Average Latch Wait Time (ms)' {
                $Check = (New-IcingaCheck -Name $Entry.counter_name -Value ($Entry.cntr_value / $LatchWaitTimeBase) -Unit 'ms' -MetricIndex $SerializedCounter.Category -MetricName $SerializedCounter.Counter).WarnOutOfRange($AverageLatchWaitTimeWarning).CritOutOfRange($AverageLatchWaitTimeCritical);
                break;
            };
        }

        # Do not add these metrics to our check package of create checks for them
        if ($FullName -like '\*:Buffer Manager\Buffer cache hit ratio base' -Or $FullName -like '\*:Latches\Average Latch Wait Time Base') {
            continue;
        }

After the manual changes you have to rebuild the cache and restart the icinga services:

icinga -rebuildcache
Restart-IcingaService icinga2
Restart-IcingaService icingapowershell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants