Skip to content

Commit e8fe12a

Browse files
committed
MSSQL Buffer Cache Hit Ratio returns wrong metric
Fixes #21
1 parent 447be72 commit e8fe12a

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

plugins/Invoke-IcingaCheckMSSQLResource.psm1

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@
7474
function Invoke-IcingaCheckMSSQLResource()
7575
{
7676
param (
77-
$PageLifeExpectancyCritical = $null,
78-
$PageLifeExpectancyWarning = $null,
79-
$AverageLatchWaitTimeCritical = $null,
80-
$AverageLatchWaitTimeWarning = $null,
81-
$BufferCacheHitRatioCritical = $null,
82-
$BufferCacheHitRatioWarning = $null,
77+
$PageLifeExpectancyCritical = $null,
78+
$PageLifeExpectancyWarning = $null,
79+
$AverageLatchWaitTimeCritical = $null,
80+
$AverageLatchWaitTimeWarning = $null,
81+
$BufferCacheHitRatioCritical = $null,
82+
$BufferCacheHitRatioWarning = $null,
8383
[string]$SqlUsername,
8484
[securestring]$SqlPassword,
85-
[string]$SqlHost = "localhost",
86-
[int]$SqlPort = 1433,
85+
[string]$SqlHost = "localhost",
86+
[int]$SqlPort = 1433,
8787
[string]$SqlDatabase,
88-
[switch]$IntegratedSecurity = $FALSE,
88+
[switch]$IntegratedSecurity = $FALSE,
8989
[switch]$NoPerfData,
9090
[ValidateSet(0, 1, 2)]
91-
[int]$Verbosity = 0
91+
[int]$Verbosity = 0
9292
);
9393

9494
[hashtable]$CheckPackages = @{};
@@ -100,9 +100,27 @@ function Invoke-IcingaCheckMSSQLResource()
100100
-PerformanceCounters @(
101101
'\SQLServer:Buffer Manager\page life expectancy',
102102
'\SQLServer:Buffer Manager\Buffer cache hit ratio',
103-
'\SQLServer:Latches\Average Latch Wait Time (ms)'
103+
'\SQLServer:Latches\Average Latch Wait Time (ms)',
104+
'\SQLServer:Buffer Manager\Buffer cache hit ratio base',
105+
'\SQLServer:Latches\Average Latch Wait Time Base'
104106
);
105107

108+
[decimal]$BufferRatioBase = 1;
109+
[decimal]$LatchWaitTimeBase = 1;
110+
111+
foreach ($entry in $PerfCounters) {
112+
switch ($entry.counter_name) {
113+
'Buffer cache hit ratio base' {
114+
$BufferRatioBase = $entry.cntr_value;
115+
break;
116+
};
117+
'Average Latch Wait Time Base' {
118+
$LatchWaitTimeBase = $entry.cntr_value;
119+
break;
120+
};
121+
}
122+
}
123+
106124
$InstanceName = Get-IcingaMSSQLInstanceName -SqlConnection $SqlConnection;
107125

108126
# Close the connection as we no longer require it
@@ -116,27 +134,32 @@ function Invoke-IcingaCheckMSSQLResource()
116134
foreach ($Entry in $PerfCounters) {
117135
$FullName = Get-IcingaMSSQLPerfCounterPathFromDBObject -DBObject $Entry;
118136

119-
Add-IcingaHashtableItem `
120-
-Hashtable $CheckPackages `
121-
-Key ($Entry.object_name) `
122-
-Value (New-IcingaCheckPackage -Name $Entry.object_name -OperatorAnd -Verbose $Verbosity) | Out-Null;
123-
124137
<# https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-buffer-manager-object?view=sql-server-ver15 #>
125138
switch ($FullName) {
126139
'\SQLServer:Buffer Manager\page life expectancy' {
127140
$Check = (New-IcingaCheck -Name $Entry.counter_name -Value $Entry.cntr_value).WarnOutOfRange($PageLifeExpectancyWarning).CritOutOfRange($PageLifeExpectancyCritical);
128141
break;
129142
};
130143
'\SQLServer:Buffer Manager\Buffer cache hit ratio' {
131-
$Check = (New-IcingaCheck -Name $Entry.counter_name -Value $Entry.cntr_value).WarnOutOfRange($BufferCacheHitRatioWarning).CritOutOfRange($BufferCacheHitRatioCritical);
144+
$Check = (New-IcingaCheck -Name $Entry.counter_name -Value (($Entry.cntr_value * 1.0 / $BufferRatioBase) * 100) -Unit '%').WarnOutOfRange($BufferCacheHitRatioWarning).CritOutOfRange($BufferCacheHitRatioCritical);
132145
break;
133146
};
134147
'\SQLServer:Latches\Average Latch Wait Time (ms)' {
135-
$Check = (New-IcingaCheck -Name $Entry.counter_name -Value $Entry.cntr_value).WarnOutOfRange($AverageLatchWaitTimeWarning).CritOutOfRange($AverageLatchWaitTimeCritical);
148+
$Check = (New-IcingaCheck -Name $Entry.counter_name -Value ($Entry.cntr_value / $LatchWaitTimeBase) -Unit 'ms').WarnOutOfRange($AverageLatchWaitTimeWarning).CritOutOfRange($AverageLatchWaitTimeCritical);
136149
break;
137-
}
150+
};
151+
}
152+
153+
# Do not add these metrics to our check package of create checks for them
154+
if ($FullName -eq '\SQLServer:Buffer Manager\Buffer cache hit ratio base' -Or $FullName -eq '\SQLServer:Latches\Average Latch Wait Time Base') {
155+
continue;
138156
}
139157

158+
Add-IcingaHashtableItem `
159+
-Hashtable $CheckPackages `
160+
-Key ($Entry.object_name) `
161+
-Value (New-IcingaCheckPackage -Name $Entry.object_name -OperatorAnd -Verbose $Verbosity) | Out-Null;
162+
140163
if ($null -ne $Check) {
141164
# The check package for our counter category
142165
(Get-IcingaHashtableItem -Hashtable $CheckPackages -Key ($Entry.object_name)).AddCheck($Check) | Out-Null;

0 commit comments

Comments
 (0)