Home

Keebler/Blog

« Be a computer scientist without the years (of hell)
‘Scrubs’ Season 8 Premiere LIVEBLOG »

.NET: Monitoring Windows processes from ASPX webpage

I was recently working on some ScribbleLive features that require asynchronous processes to be running in the background on Windows. Since I want to make sure they keep running, I wanted Pingdom to be able to monitor (and alert) on them.

I was happy to find that in .NET, a web application can access the processes running on the host server. I whipped up this little bit of C# (which will be on an ASPX page) to check for the processes, and report if they are “UP” or “DOWN”. Pingdom will then check for the word “DOWN” on a request to the page and let me know if it finds one.

Here are the using statements that you have to have for this code to run:

using System.Diagnostics;
using System.Collections.ObjectModel;

Then here’s the bulk of it:

Collection<string> RunningProcesses = new Collection<string>();
RunningProcesses.Add( "Program1" );
RunningProcesses.Add( "Program2" );

Response.ContentType = "text/plain";

foreach ( Process proc in Process.GetProcesses() )
{
    if ( RunningProcesses.Contains( proc.ProcessName ) )
    {
        Response.Write( proc.ProcessName + ": UP" + System.Environment.NewLine );
        RunningProcesses.Remove( proc.ProcessName );
    }
}

foreach ( string s in RunningProcesses )
{
    Response.Write( s + ": DOWN" + System.Environment.NewLine );
}

When I have a bit more time, I’m going to add a call to Process.Start(…) to restart and processes that have gone down. You know, at some point this code will probably make me unnecessary :)

Tags: .net, ASPX, processes, Windows

Related Posts

  • Webpage WYSIWYG v0.0.1
  • Webpage WYSIWYG v0.0.2
  • ASPX: Don’t put UserControls inside of code blocks
  • Webpage WYSIWYG v0.0.3
  • Windows Server 2003 Running on Amazon Elastic Computing Cloud

This entry was posted on Saturday, January 3rd, 2009 at 11:40 am and is filed under My Releases, Software, Web Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Click here to cancel reply.

  • Blog Home

  • Tags

    90210 alessandra ambrosio animals asp.net audrina patridge battlestar galactica bikini bunny bush C# canada canada election ctv ctvglobemedia development Election Entertainment/Celebrity facebook Gordon Ramsay gorilla gossip girl hayden panettiere iphone last.fm liveblog liveblogging mesh08 muchmusic Music obama palin rachel bilson scribblelive shenae grimes subway telemarketers the hills the killers the office toronto ttc toronto tv us election video yeah yeah yeahs

    WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

  • Recent Posts

    • Trying to convince @idiotbante…
    • I wonder if the CTV “Save Loca…
    • Just finished dinner which I m…
    • I shouldn’t get as excited abo…
    • Stormtroopers’ 9/11 http://tin…
  • Categories

    • Election
    • Entertainment/Celebrity
    • Fake News
    • Featured
    • Funny
    • Keebler/Show
    • Music
    • My Releases
    • On-the-Road
    • RedDot
    • Reviews
    • Science/Technology
    • ScribbleLive
    • Security
    • Software
    • Torrent Live Stats
    • Tweets
    • Uncategorized
    • Web Development
  • Blogroll

    • Kitten-Monkey’s Cell
    • :: kattekylling ::
    • Adam Finley
    • blog-j
    • fuzzz.gaulin.ca
    • Idiot Banter
    • mad.greyarea.com
    • ob.blog
    • PollyPrissyPants
    • RedDot CMS Users Google Group
    • ScribbleLive Official Blog
  • My Sites

    • Flickr2Facebook
    • RedDot CMS
    • ScribbleLive
    • Where are my f(acebook)ing friends?
    • WhyYouShould