Click here to Skip to main content
Click here to Skip to main content
Go to top

SystemWatchdog - An Experimental & Educational Project for System Monitoring

, 28 Aug 2010
Rate this:
Please Sign up or sign in to vote.
This is an experimental & educational project for system monitoring based on "Base Library for Multi-threaded Windows Services" architecture

Introduction

SystemWatchdog is a simple and flexible system monitoring tool for experimental and educational purpose, based on Base Library for Multi-threaded Windows Services[^] architecture.

Usage

Install software with installer, edit configuration file (SystemWatchdog.exe.config), and then, start service.

Configuration File

<systemWatchdog>

<watchdogList>

<watchdog name="MsSqlPortTester" enabled="true" sleepTime="60">
<plugin type="SystemWatchdog.Plugins.PortConnector, SystemWatchdog.Plugins">
<parameter name="Hosts" value="10.1.1.155:1433,10.1.1.156:1433,10.1.1.157:1433" />
</plugin>
</watchdog>

<watchdog name="HttpTester" enabled="true" sleepTime="60">
<plugin type="SystemWatchdog.Plugins.HttpRequester, SystemWatchdog.Plugins">
<parameter name="Host" value="http://www.google.com/" />
<parameter name="WaitingResponse" value="" />
</plugin>
</watchdog>

<watchdog name="SmtpTester" enabled="true" sleepTime="60">
<plugin type="SystemWatchdog.Plugins.SmtpConnecter, SystemWatchdog.Plugins">
<parameter name="Hosts" value="74.125.77.109:25" />
</plugin>
</watchdog>

<watchdog name="Pinger" enabled="true" sleepTime="60">
<plugin type="SystemWatchdog.Plugins.Pinger, SystemWatchdog.Plugins">
<parameter name="Hosts" value="www.microsoft.com" />
</plugin>
</watchdog>

</watchdogList>

<operators>
<operator name="Efe Erdogru" email="efe@xyz.com" />
</operators>

<smtpClient host="mail.xyz.com" port="587">
<parameter name="FromName" value="Efe Erdogru" />
<parameter name="FromAddress" value="efe@xyz.com" />
<parameter name="IsSmtpRequiresAuthentication" value="true" />
<parameter name="SmtpUserName" value="efe@xyz.com" />
<parameter name="SmtpPassword" value="password" />
</smtpClient>

</systemWatchdog> 

Configuration section is made of three parts:

  1. watchdogList: This section contains the watchdog services.
  2. operators: This section contains the operators which will be used when an watchdog gets an error.
  3. smtpClient: This section contains SMTP connection settings.

Every watchdog is a service which does a work managed by a plugin.

Background

Project contains an engine library which manages and configures the watchdogs and a plugin library. Also an executor service which is a Windows service and an installer.

  1. Engine Library
  2. Plugin Library
  3. Executor Service
  4. Installer

Engine Library

  • Interfaces
    • IConfigurable: Defines the interface for the classes which can be configured via XmlNode instance that contains the configuration settings.
    • IRunnable: Defines the interface for all classes that have a determined lifetime for execution.
    • IWatchdog: Defines the interface for the classes which will watch the system.
    • IPlugin: Defines the interface for the classes which is a plugin for a watchdog.
  • Watchdog: Worker service which signals the plugin to execute its own process.
  • WatchdogManager: Manages the starting and stopping of watchdogs configured in the system.
  • PluginSkeleton: Base class for plugin instances.
  • PluginFactory: Creates an object of the specified type using reflection through an argumentless constructor.

Plugin Library

  • HttpRequester: This plugin connects a URL and gets a response. If configured, it checks if the response is matched or not.
  • Pinger: This plugin pings to an address.
  • PortConnector: This plugin connects to an IP on a given port.
  • SmtpConnecter: This plugin is for SMTP servers. It connects, sends EHLO (or HELO) command.

Executor Service

  • WindowsService
  • Installer

Using the Code

For base architecture, see Base Library for Multi-threaded Windows Services[^].

SystemWatchdogConfigurationSectionHandler

<configSections>
<section name="log4net" 
	type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<section name="systemWatchdog" 
	type="SystemWatchdog.Engine.SystemWatchdogConfigurationSectionHandler, 
	SystemWatchdog.Engine" />
</configSections>

SystemWatchdogConfigurationSectionHandler implements the IConfigurationSectionHandler interface for configuration settings.

var section = (XmlNode) ConfigurationManager.GetSection("systemWatchdog");

How Plugins are Created?

public static IPlugin GetPlugin(XmlNode configSection)
{
var type = configSection.Attributes["type"].Value;
return (IPlugin) PluginFactory.Create(type);
}

Watchdog Structure

When execution time comes, watchdog calls plugin to execute itself. If no error occurred, thread will sleep until next execution time which is configured in configuration file. If an error occurred, plugin signals a "PluginErrorEventHandler" event which is caught by watchdog, and then, an e-mail is sent to the operators with SMTP configuration settings.

var section = configSection.SelectNodes("./plugin")[0];
WatchdogPlugin = Tools.GetPlugin(section);
WatchdogPlugin.Log = Log;

WatchdogPlugin.PluginError += WatchdogPlugin_PluginError;

WatchdogPlugin.Configure(section);

private void WatchdogPlugin_PluginError(object sender, PluginErrorEventArgs e)
{
Log.Warn(String.Format("Plugin error received: {0}\r\n{1}", e.Subject, e.Body));

Tools.SendMailToOperators("SystemWatchdog Error - " + e.Subject, e.Body, Log);
}

History

This is the first published version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Efe Erdogru
Software Developer (Senior)
Turkey Turkey
No Biography provided
Follow on   Google+

Comments and Discussions

 
Questioncan't stop and restart PinmemberErnest Bariq5-Sep-14 9:13 
AnswerRe: can't stop and restart PinmemberEfe Erdogru5-Sep-14 9:39 
GeneralRe: can't stop and restart PinmemberErnest Bariq5-Sep-14 10:07 
GeneralRe: can't stop and restart PinmemberEfe Erdogru5-Sep-14 10:32 
GeneralRe: can't stop and restart PinmemberErnest Bariq5-Sep-14 10:42 
GeneralMy vote of 5 Pinmembercrab6506-Nov-13 21:39 
GeneralMy vote of 5 Pinmemberzhaojs25-Dec-11 21:21 
GeneralMy vote of 5 PinmemberKanasz Robert1-Dec-11 2:45 
GeneralMy vote of 5 Pinmemberwaqas31620-May-11 19:44 
GeneralPing does not work Pinmember__Untitled24-Feb-11 20:14 
GeneralNice! PinmemberMember 45586629-Aug-10 2:49 
GeneralMy vote of 5 PinmemberMember 45586629-Aug-10 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 28 Aug 2010
Article Copyright 2010 by Efe Erdogru
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid