Hi,
I have wrapped a C# script into powershell that monitors ASP.NET information (Current Connections, Requests Executing, Request Wait Time, Requests In Queue, and Request Execution Time). Currently the only modifier to alarm color is how long it takes for the script to respond. I want to make it so, for example, if current connections reaches a certain point, it turns yellow/red. Lines 108-115 highlight what I am referring to. Is there any way to accomplish this? Thanks
$MAX_RUN_TIME = 300 $TIME_Exceeded = $false $TEST_FILE = "C:\Program Files (x86)\BBWin\tmp\aspfoster" $STATUS = "green" $STATUSCODE = "Good to go"
$Source = @" using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics;
namespace ASPNETPerformance {
public static class Query
{
public static IntPtr userHandle = new IntPtr(0);
public static string hostName = ".";
public static string categoryName = "ASP.NET Applications";
public static string instanceName = "__Total__";
public static float CurrentConnections()
{
string counterName = "Current Connections";
PerformanceCounter counter = new PerformanceCounter("Web Service", counterName, "_Total", hostName);
return counter.NextValue();
}
public static float RequestsExecuting()
{
string counterName = "Requests Executing";
PerformanceCounter counter = new PerformanceCounter(categoryName, counterName, instanceName, hostName);
return counter.NextValue();
}
public static float RequestWaitTime()
{
string counterName = "Request Wait Time";
PerformanceCounter counter = new PerformanceCounter(categoryName, counterName, instanceName, hostName);
return counter.NextValue();
}
public static float RequestsInApplicationQueue()
{
string counterName = "Requests In Application Queue";
PerformanceCounter counter = new PerformanceCounter(categoryName, counterName, instanceName, hostName);
return counter.NextValue();
}
public static float RequestExecutionTime()
{
string counterName = "Request Execution Time";
PerformanceCounter counter = new PerformanceCounter(categoryName, counterName, instanceName, hostName);
return counter.NextValue();
}
}
}
"@
try{ Add-Type -TypeDefinition $Source -Language CSharp } catch { }
$CurrentConnections = [ASPNETPerformance.Query]::CurrentConnections() $RequestsExecuting = [ASPNETPerformance.Query]::RequestsExecuting() $RequestWaitTime = [ASPNETPerformance.Query]::RequestWaitTime() $RequestsInApplicationQueue = [ASPNETPerformance.Query]::RequestsInApplicationQueue() $RequestExecutionTime = [ASPNETPerformance.Query]::RequestExecutionTime()
$yep = "$CurrentConnections $RequestsExecuting $RequestWaitTime $RequestsInApplicationQueue $RequestExecutionTime" $yep | out-file -filePath "C:\users\patchf\desktop\herrp.txt"
if ($TIME_Exceeded) { $STATUS = "yellow" $STATUSCODE = "This is taking longer than usual" }
if ($CurrentConnections > 15000) { #turn current connections yellow } if($CurrentConnections > 16000) { #turn current connections red }
$end = Get-Date $STATUS = "$STATUS $end $STATUSCODE" $STATUS | out-file -Encoding ASCII $TEST_FILE $Herp = "ASP.NET Application Information `n" | out-file -Encoding ASCII $TEST_FILE -Append $Derp = "Current Connections: " + $CurrentConnections | out-file -Encoding ASCII $TEST_FILE -Append $Merp = "Requests Executing: " + $RequestsExecuting | out-file -Encoding ASCII $TEST_FILE -Append $Cherp = "Request Wait Time: " + $RequestWaitTime | out-file -Encoding ASCII $TEST_FILE -Append $Berp = "Requests In Queue: " + $RequestsInApplicationQueue | out-file -Encoding ASCII $TEST_FILE -Append $Flerp = "Requests Execution Time: " + $RequestExecutionTime | out-file -Encoding ASCII $TEST_FILE -Append
Foster Patch Web Server Technician
You can only send one colour per column back to xymon so you need to have logic to determine the "overall" colour if you are testing multiple things or split it into separate columns. The way I have done this in the past is just have the message that is displayed on the column show something like the below so I can identify exactly what has failed:
TEST 1 = OK TEST 2 = OK TEST 3 = NOT OK
And in the script when anything triggers yellow/red threshold I just add to a count and then at the end I use that to determine the colour with red always "winning" if anything triggers red. Something like:
If($RedCount -gt 0) { $colour = 'red' } Elseif($YellowCount -gt 0) { $colour = 'yellow' } Else { $colour = 'green' }
The other option is you can just put your whole thing into the same if statement but that may not be what you want.
if($TIME_Exceeded) { $STATUS = "yellow" $STATUSCODE = "&yellow This is taking longer than usual" } elseif($CurrentConnections -gt 16000) { $STATUS = "red" $STATUSCODE = "&red Current Connections exceed 1600" } elseif($CurrentConnections -gt 15000) { $STATUS = "yellow" $STATUSCODE = "&yellow Current Connections exceed 1500" }
Regards,
Brandon
participants (2)
-
BDale@kitchengroup.com.au
-
Foster.Patch@accuweather.com