Click here to Skip to main content
6,822,123 members and growing! (20,405 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Libraries » General     Intermediate License: The Code Project Open License (CPOL)

A heartbeat and monitoring class library

By Duncan Edwards Jones

A C# library to add a heartbeat and one or more listeners to an application.
C#, Windows (Win2K, WinXP, Win2003, Vista), .NET (.NET2.0), Dev
Posted:11 Aug 2008
Views:8,187
Bookmarked:13 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
4 votes for this article.
Popularity: 1.00 Rating: 1.67 out of 5
2 votes, 50.0%
1
2 votes, 50.0%
2

3

4

5

Introduction

An application heartbeat is a periodic event which is raised so long as an application is "alive", which can be monitored by one or more listeners which can then act on that heartbeat. This class library demonstrates one way of achieving this, and allows for listeners to be added via the application configuration. (This last is conceptually similar to the way Trace and Debug listeners work.)

Background

The main class is the static Heartbeat class that has a System.Threading.Timer that is initialised the first time the class is referred to, and which raises a "Beat" every second. This beat is then passed on to every listener class (which is a class inheriting from a base HeartbeatMonitorBase) to record or react to as they choose.

The heartbeat listeners collection is read from the application configuration file by the class HeartbeatCustomConfigSection which inherits from the .NET framework 2.0 class System.Configuration.ConfigurationSection, and each class listed in the <heartbeats> section is instantiated when read, by creating a System.Reflection.ConstructorInfo and executing it.

Using the code

At the start of your application, call the Monitoring.Heartbeat.ResetListensersFromConfig(); method to start the heartbeat and create the listeners per the application configuration file.

The application configuration for the heartbeat listeners should be something like:

<configSections>
  <section name ="heartbeatSettings" 
      type="Monitoring.HeartbeatCustomConfigSection, Monitoring, 
            Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"/>
</configSections>

And, the individual listeners would be added thus:

<heartbeatSettings>
    <heartbeats>
      <clear />
      <add Name="HeartbeatTrace"  
            Type="Monitoring.TraceHeartbeatMonitor, Monitoring, 
                  Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
      <add Name="HeartbeatTraceTwo" 
            Type="Monitoring.TraceHeartbeatMonitor, Monitoring, 
                  Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"  
            InitData="foo" />
    </heartbeats>
</heartbeatSettings>

History

  • 2008-08-11 - Created.

License

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

About the Author

Duncan Edwards Jones


Member
Microsoft MVP 2006, 2007
Visual Basic .NET
Occupation: Software Developer (Senior)
Location: Ireland Ireland

Other popular Libraries articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralNice concept, but no details PinmemberDavid B. Taylor22:29 11 Aug '08  
GeneralRe: Nice concept, but no details PinmemberDuncan Edwards Jones23:56 11 Aug '08  
GeneralRe: Nice concept, but no details PinmemberScott Bruno4:25 12 Aug '08  
GeneralRe: Nice concept, but no details Pinmembercatsclaw12:29 25 Sep '08  
GeneralRe: Nice concept, but no details PinmemberDuncan Edwards Jones0:07 26 Sep '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 11 Aug 2008
Editor: Smitha Vijayan
Copyright 2008 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2010
Web20 | Advertise on the Code Project