Click here to Skip to main content
Licence CPOL
First Posted 11 Aug 2008
Views 13,637
Downloads 100
Bookmarked 14 times

A heartbeat and monitoring class library

By Duncan Edwards Jones | 11 Aug 2008
A C# library to add a heartbeat and one or more listeners to an application.
2 votes, 40.0%
1
2 votes, 40.0%
2
1 vote, 20.0%
3

4

5
1.86/5 - 5 votes
μ 1.86, σa 1.46 [?]

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

Software Developer (Senior)
JP Morgan
Ireland Ireland

Member

Follow on Twitter Follow on Twitter
C# / SQL Server developer
Microsoft MVP 2006, 2007
Visual Basic .NET

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
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  
You could do that, or you could make with the details and see if the community comes up with something. Nothing wrong with a team effort.
 
--
Saving the world, one line of code at a time

GeneralRe: Nice concept, but no details Pinmembercatsclaw12:29 25 Sep '08  
GeneralRe: Nice concept, but no details PinmemberDuncan Edwards Jones0:07 26 Sep '08  
GeneralRe: Nice concept, but no details [modified] Pinmembertaher bayat10:44 28 Jul '11  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 11 Aug 2008
Article Copyright 2008 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid