Subscribe by email

Q&A with Hal Higdon

Each week, coach and author, Hal Higdon answers your questions about running. Here's the latest:

Main | Our Transition to HTML5: Part 1 »
Saturday
Nov172012

Simple Server Density Plugin for Windows to Monitor MSMQ

We've been steadily growing our dependence on Server Density (SD) as a means to monitor our cloud and hosted offerings.  While there are a number of supported plugins and 3rd party offerings, most likely you will run into a situation where you need to do something custom. The plugin architecture for Server Density is pretty awesome. The criteria for a good API is ease of use and a short ramp time. Simply put, when it comes to documentation, samples, and support; Server Density nails it.

First I downloaded the sample C# application and reviewed their support article on writing a custom plugin. Luckily the sample application was using System.Diagnotics which seemed like a good start for writing my plugin.  We use MSMQ for async operations like our Post Workout Notifications, or for offloading heavy work from the webserver.  Its easy to use if you have are in Windows, using some sort of AD, and need reliable queueing.  Anyway, this isn't a post on queue software (that's a whole other post), but suffice to say we need to monitor the size of the queue.  Occasionally, the Windows Process that processes the queue stops receiving messages, due to an elusive bug that is difficult to track down.  In the meantime, we can monitor the queue to look for signs that our queue processor has failed.

Below is the simple plugin used to report on all MSMQ queues for the current server.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using BoxedIce.ServerDensity.Agent.PluginSupport;
   4:  using System.Diagnostics;
   5:  using System.Messaging;
   6:   
   7:  namespace ServerDensity.MSMQ
   8:  {
   9:      public class Check : ICheck
  10:      {
  11:          public string Key
  12:          {
  13:              get { return "MSMQ"; }
  14:          }
  15:   
  16:          public object DoCheck()
  17:          {
  18:              PerformanceCounterCategory myCat = new PerformanceCounterCategory("MSMQ Queue");
  19:   
  20:              IDictionary<string, object> values = new Dictionary<string, object>();
  21:   
  22:              foreach (var name in myCat.GetInstanceNames())
  23:              {
  24:                  var cntr = new PerformanceCounter (myCat.CategoryName, "Messages in Queue", name);                                     
  25:                  var key = cntr.InstanceName.Replace (@"\", @"\\");
  26:                  values.Add(key, cntr.NextValue());                
  27:              }
  28:   
  29:              return values;
  30:          }
  31:      }
  32:  }

 

While writing this plugin, I encountered a few bugs. First with System.Diagnostics API, where Counters wanted a specific name. Second was a more subtle bug with the output of our dictionary. Turns out I was getting the following error in the Windows Event Log:  "URL http://trainingpeaks.serverdensity.com/postback/ returned: JSON Error: Syntax error."  My hunch was that the cntr.InstanceName wasn't properly JSON encoded since it inculdes AD paths. I roped Server Density Support into this, just to see if/how they would respond. Their team was on it right away, giving me the link to help debug my plugin. Their debug logging provided me just what I needed: the JSON output they send to their servers. Some simple Googling turned up JSONLint, which easily pointed me to the bad JSON. I simply needed to replace '\' with '\\' in my string, and I was good to go.

Here is a screen shot of our Server Density Plugin:

The final step was to create an alert on the queue of interest to email/SMS the DevOps crew if this queue gets too big. 

Well, that's enough for this Saturday morning. I'm going on a ride. :)

 

Trent Niemeyer has over 10 years of development experience at small web companies. As the VP of Technology at TrainingPeaks, Trent's role is to incubate new technologies and new ideas in order to scale the TrainingPeaks platform and grow our company. Trent has been racing triathlon for 5 years, with 4 Ironmans and about a dozen 70.3's under his belt. You can follow him on Twitter @trentniemeyer.

References (29)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    If you love football, you likely have a favourite team from the National Football League or two and have a list of players who like to have seen.
  • Response
    Response: Jay Cutler Jersey
    NFL is really one of the largest sports in America. It has a big following.
  • Response
    Response: kiss
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
  • Response
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Katy Landscaping
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
  • Response
    Amazon
  • Response
  • Response
    Response: click here
  • Response
    Response: read more
  • Response
  • Response
    Response: read
  • Response
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: revit 2014
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: belinda broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Belinda Broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Belinda Broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Belinda Broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: belinda broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Belinda Broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Belinda Broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Belinda Broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: Dr. Rashmi Patel
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: belinda broido
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Response: 42nd street photo
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog
  • Response
    Simple Server Density Plugin for Windows to Monitor MSMQ - Tech Blog - TrainingPeaks Blog

Reader Comments (1)

Hi,
I'm in need for a few plugins on Win, Linux and Mac. willing to contract for a short engagement in order to get them ASAP.
If you are interested, please reach out to me before end of year.

shlomi.abraham(at)dothill(dot)com


thanks,
SBA

December 18, 2013 | Unregistered CommenterShlomi Ben Abraham

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>