-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lockstep - Citrix Generic Performance.ps1
186 lines (151 loc) · 6.86 KB
/
Lockstep - Citrix Generic Performance.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
###############################################################################
#
# prtg citrix xenapp monitor (generic performance)
# mar 4, 2013
#
###############################################################################
#
# Citrix documentation on this subject
# http://support.citrix.com/article/CTX133540
#
###############################################################################
#
# PRTG configuration:
# ensure the executing security context has the needed permissions
# this likely means "Use Windows credentials of parent device"
# also set "Parameters to "%host" (without the quotes).
#
###############################################################################
# script parameters
Param (
[Parameter(Position=0)]
[string]$ComputerName
)
# parameter options to require this don't send enough info back to prtg. do it manual!
# is there a better way to handle this?
if (!($ComputerName)) {
return @"
<prtg>
<error>1</error>
<text>Required parameter not specified: please provide target hostname (or %host)</text>
</prtg>
"@
}
$TimerStart = Get-Date
###############################################################################
# load the prtgshell module
function Import-MyModule {
Param(
[string]$Name
)
if ( -not (Get-Module -Name $Name) ) {
if ( Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } ) {
Import-Module -Name $Name
$true # module installed + loaded
} else {
$false # module not installed
}
}
else {
$true # module already loaded
}
}
$ModuleImportSuccess = Import-MyModule PrtgShell
if (!($ModuleImportSuccess)) {
return @"
<prtg>
<error>1</error>
<text>PrtgShell module not loaded: ensure the module is visible for 32-bit PowerShell</text>
</prtg>
"@
}
###############################################################################
# initial wmi connection tests (fail-fast)
function Get-TargetStatus {
Param (
[Parameter(mandatory=$True,Position=0)]
[string]$ComputerName,
[Parameter(Position=1)]
[string]$ServiceName = "SamSs"
)
$wmi = [WMISearcher]""
$wmi.options.timeout = '0:0:5' # 5-second timeout
$wmi.scope.path = "\\$ComputerName\Root\CIMV2"
$wmi.query = 'Select Status from Win32_Service where Name= "' + $ServiceName + '"'
try {
$ServiceStatus = ($wmi.Get() | select Status).Status
} catch {
if ($_.Exception.InnerException) {
return "Error: $($ComputerName): " + $_.Exception.InnerException.Message
} else {
return "Error: $($ComputerName): " + $_.Exception.Message
}
}
if ($ServiceStatus -eq "OK") {
return $true
} else {
return "Error: $($ComputerName): $ServiceName not running."
}
}
$CheckServer = Get-TargetStatus $ComputerName
if ($CheckServer -ne $true) {
return @"
<prtg>
<error>1</error>
<text>$CheckServer</text>
</prtg>
"@
}
###############################################################################
$ReturnText = "OK" # this is the default
###############################################################################
#### queries from citrix documentation: "Operations Guide - Monitoring.pdf"
# system counters
$wql = "Select PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor where name='_total'"
$QueryObject = Get-WmiObject -Query $wql -computername $computername
$SystemPercentProcessorTime = $QueryObject.PercentProcessorTime # warn at 80% for 15 minutes
# this is for the script metrics, not xenapp
$TimerInitialExecution = Get-Date
$wql = "Select ProcessorQueueLength from Win32_PerfFormattedData_PerfOS_System"
$QueryObject = Get-WmiObject -Query $wql -computername $computername
$SystemProcessorQueueLength = $QueryObject.ProcessorQueueLength # warn at 5 (per Core) for 5 minutes
$wql = "Select AvailableBytes,PagesPerSec from Win32_PerfFormattedData_PerfOS_Memory"
$QueryObject = Get-WmiObject -Query $wql -computername $computername
$SystemAvailableBytes = $QueryObject.AvailableBytes # warn at <30% of total RAM
$SystemPagesPerSec = $QueryObject.PagesPerSec # warn at >10
$wql = "Select CurrentUsage from Win32_PageFileUsage"
$QueryObject = @(Get-WmiObject -Query $wql -computername $computername)
$SystemPagefileCurrentUsage = $QueryObject[0].CurrentUsage # warn at >40%
if ($QueryObject.Count -gt 1) {
$ReturnText = "Multiple Page Files!"
}
$wql = "Select PercentDiskTime,CurrentDiskQueueLength,AvgDisksecPerRead,AvgDisksecPerTransfer,AvgDisksecPerWrite from Win32_PerfFormattedData_PerfDisk_PhysicalDisk where name='_Total'"
$QueryObject = Get-WmiObject -Query $wql -computername $computername
$SystemPercentDiskTime = $QueryObject.PercentDiskTime # warn at >70% consistently
$SystemCurrentDiskQueueLength = $QueryObject.CurrentDiskQueueLength # warn at >=1 (per spindle) consistently
$SystemAvgDisksecPerRead = $QueryObject.AvgDisksecPerRead # warn at >=15ms consistently
$SystemAvgDisksecPerTransfer = $QueryObject.AvgDisksecPerTransfer # warn at >=15ms consistently
$SystemAvgDisksecPerWrite = $QueryObject.AvgDisksecPerWrite # warn at >=15ms consistently
###############################################################################
$TimerStop = Get-Date
$InitialExecutionTime = $TimerInitialExecution - $TimerStart
$ExecutionTime = $TimerStop - $TimerStart
###############################################################################
# output
$XMLOutput = "<prtg>`n"
$XMLOutput += Set-PrtgResult "Sensor Initial WMI Connection Time" $InitialExecutionTime.TotalMilliseconds "ms" -ShowChart
$XMLOutput += Set-PrtgResult "Sensor Total Execution Time" $ExecutionTime.TotalMilliseconds "ms" -ShowChart
$XMLOutput += Set-PrtgResult "Processor Time (Percent)" $SystemPercentProcessorTime "Percent" -ShowChart -MaxWarn 80 -WarnMsg "CPU Usage high"
$XMLOutput += Set-PrtgResult "Processor Queue Length" $SystemProcessorQueueLength "#" -ShowChart
$XMLOutput += Set-PrtgResult "Memory - Available Bytes" $SystemAvailableBytes "BytesMemory" -ShowChart
$XMLOutput += Set-PrtgResult "Memory - Pages/sec" $SystemPagesPerSec "#" -ShowChart -MaxWarn 10 -WarnMsg "Potential memory bottleneck"
$XMLOutput += Set-PrtgResult "Page File Percent Usage" $SystemPagefileCurrentUsage "Percent" -ShowChart
$XMLOutput += Set-PrtgResult "Disk Time (Percent)" $SystemPercentDiskTime "Percent" -ShowChart -MaxWarn 40 -WarnMsg "High Page File usage"
$XMLOutput += Set-PrtgResult "Disk Queue Length (Current)" $SystemCurrentDiskQueueLength "#" -ShowChart -MaxWarn 70 -WarnMsg "High disk queue length"
$XMLOutput += Set-PrtgResult "Disk Average Seconds Per Read" $SystemAvgDisksecPerRead "ms" -ShowChart -MaxWarn 15 -WarnMsg "High Average Disk Seconds Per Read"
$XMLOutput += Set-PrtgResult "Disk Average Seconds Per Transfer" $SystemAvgDisksecPerTransfer "ms" -ShowChart -MaxWarn 15 -WarnMsg "High Average Disk Seconds Per Transfer"
$XMLOutput += Set-PrtgResult "Disk Average Seconds Per Write" $SystemAvgDisksecPerWrite "ms" -ShowChart -MaxWarn 15 -WarnMsg "High Average Disk Seconds Per Write"
$XMLOutput += " <text>$ReturnText</text>"
$XMLOutput += "</prtg>"
$XMLOutput