There’s an Easter egg hidden in the vWorkspace connection broker service. If you navigate to the service via a web browser, you’ll get a few stats that show what the broker has done since it was last started.
The numbers are pretty meaningless without some sort of context. One way of handling this is to sample the statistics over a period of time and then signal when a threshold is reached. Using the Invoke-WebRequest cmdlet, we can easily query the broker for these stats. With a little simple parsing we can put together a PSCustomObject that contains the sample data.
ToggleUnsafeHeaderParsing -Enabled $true $Request = Invoke-WebRequest -Uri "http://$_" ToggleUnsafeHeaderParsing -Enabled $false $content = $Request.ParsedHtml.all.tags("p") | Select -ExpandProperty innerHtml $values = @() 0..3 | % { $startIndex = $content.IndexOf("</BR>;") + 4 $endIndex = $content.IndexOf("<B>") $values += $content.subString($startIndex, $endIndex - $startIndex) $content = $content.subString($endIndex + 4, $content.Length - $endIndex - 4) } [PSCustomObject]@{ServerName=$_;StartTime=$values[0];HTTPRequests=[long]$values[1];VMHeartbeats=[long]$values[2];DBQueries=[long]$values[3];} |
Notice the use of the ToggleUnsafeHeaderParsing function. This is required due to some legacy code within the broker that doesn’t play nice with .NET based web request classes. To address this we need to turn on “unsafe header parsing” for the process. This is typically done via the app.config file. Rather than having to stick something in System32, it’s much easier to use a little reflection. I mimic this Stackoverflow example in PowerShell.
Once we have our samples, we can begin to calculate a rolling average for each of the three stats returned by the web page.
$AvgStats = @() $Servers | % { $AvgStats += [PSCustomObject]@{ServerName=$_;AvgHTTPRequests=[double]-1.0;AvgVMHeartbeats=[double]-1.0;AvgDBQueries=[double]-1.0;LastSample=$null;SampleCount=0} } while($true) { Get-BrokerStats -Servers $Servers | % { $AvgStat = $AvgStats | Where ServerName -eq $_.ServerName $AvgStat.SampleCount++ #Rolling average of HTTP requests if ($AvgStat.AvgHTTPRequests -eq -1) { $AvgStat.AvgHTTPRequests = $_.HTTPRequests } else { $sample = $AvgStat.LastSample.HTTPRequests - $_.HTTPRequests $AvgStat.AvgHTTPRequests = (($AvgStat.AvgHTTPRequests * ($AvgStat.SampleCount -1)) + $sample) / $AvgStat.SampleCount } #... |
Finally, we can put in place some thresholds to determine when we should be notified that the service is under heavy load.
if ($AvgStat.AvgHTTPRequests -gt $HTTPRequestWarningThreshold -or $AvgStat.AvgVMHeartbeats -gt $VMHeartbeatWarningThreshold -or $AvgStat.AvgDBQueries -gt $DBQueryWarningThreshold) { #This is where you can put your notification mechanism # Send-MailMessage -SmtpServer "xyz" -Subject "vWorkspace Broker Threshold Exceeded!" -Body " Write-Host " vWorkspace Broker Threshold Exceeded! -------------------------------------- Poll interval: $PollInterval seconds Average HTTP Requests: $($AvgStat.AvgHTTPRequests) - Threshold: $HTTPRequestWarningThreshold Average VM Heartbeats: $($AvgStat.AvgVMHeartbeats) - Threshold: $VMHeartbeatWarningThreshold Average DB Queries: $($AvgStat.AvgDBQueries) - Threshold: $DBQueryWarningThreshold " } |
In this neat little example, this is what we would get for output.
vWorkspace Broker Threshhold Exceeded!
--------------------------------------
Poll interval: 10 seconds
Average HTTP Requests: 28.5 - Threshhold: 1000
Average VM Heartbeats: 0 - Threshhold: 1000
Average DB Queries: 1376.5 - Threshhold: 1000
ServerName : 10.0.0.9:8080
AvgHTTPRequests : 3.83333333333333
AvgVMHeartbeats : 0
AvgDBQueries : 226
LastSample : @{ServerName=10.0.0.9:8080; StartTime=Tue 2013-01-01 18:32:34 Central Standard
Time ; HTTPRequests=69; VMHeartbeats=0; DBQueries=2798}
SampleCount : 12









[...] [...]
[...] Simple vWorkspace Connection Broker Monitoring with PowerShell by Adam Driscoll [...]
[...] Simple vWorkspace Connection Broker Monitoring with PowerShell by Adam Driscoll [...]
[...] Simple vWorkspace Connection Broker Monitoring with PowerShell by Adam Driscoll [...]