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:
watchdogList: This section contains the watchdog services.
operators: This section contains the operators which will be used when an watchdog gets an error.
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.
- Engine Library
- Plugin Library
- Executor Service
- 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
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.