74
74
function Invoke-IcingaCheckMSSQLResource ()
75
75
{
76
76
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 ,
83
83
[string ]$SqlUsername ,
84
84
[securestring ]$SqlPassword ,
85
- [string ]$SqlHost = " localhost" ,
86
- [int ]$SqlPort = 1433 ,
85
+ [string ]$SqlHost = " localhost" ,
86
+ [int ]$SqlPort = 1433 ,
87
87
[string ]$SqlDatabase ,
88
- [switch ]$IntegratedSecurity = $FALSE ,
88
+ [switch ]$IntegratedSecurity = $FALSE ,
89
89
[switch ]$NoPerfData ,
90
90
[ValidateSet (0 , 1 , 2 )]
91
- [int ]$Verbosity = 0
91
+ [int ]$Verbosity = 0
92
92
);
93
93
94
94
[hashtable ]$CheckPackages = @ {};
@@ -100,9 +100,27 @@ function Invoke-IcingaCheckMSSQLResource()
100
100
- PerformanceCounters @ (
101
101
' \SQLServer:Buffer Manager\page life expectancy' ,
102
102
' \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'
104
106
);
105
107
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
+
106
124
$InstanceName = Get-IcingaMSSQLInstanceName - SqlConnection $SqlConnection ;
107
125
108
126
# Close the connection as we no longer require it
@@ -116,27 +134,32 @@ function Invoke-IcingaCheckMSSQLResource()
116
134
foreach ($Entry in $PerfCounters ) {
117
135
$FullName = Get-IcingaMSSQLPerfCounterPathFromDBObject - DBObject $Entry ;
118
136
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
-
124
137
<# https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-buffer-manager-object?view=sql-server-ver15 #>
125
138
switch ($FullName ) {
126
139
' \SQLServer:Buffer Manager\page life expectancy' {
127
140
$Check = (New-IcingaCheck - Name $Entry.counter_name - Value $Entry.cntr_value ).WarnOutOfRange($PageLifeExpectancyWarning ).CritOutOfRange($PageLifeExpectancyCritical );
128
141
break ;
129
142
};
130
143
' \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 );
132
145
break ;
133
146
};
134
147
' \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 );
136
149
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 ;
138
156
}
139
157
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
+
140
163
if ($null -ne $Check ) {
141
164
# The check package for our counter category
142
165
(Get-IcingaHashtableItem - Hashtable $CheckPackages - Key ($Entry.object_name )).AddCheck($Check ) | Out-Null ;
0 commit comments