[Xymon] Powershell ext script working with alarm colors

Foster Patch Foster.Patch at accuweather.com
Mon Apr 25 19:51:31 CEST 2016


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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20160425/7a859ebc/attachment.html>


More information about the Xymon mailing list