Tuesday, March 2, 2010

PRTG, MSMQ and PowerShell



Recently I discovered the limitations of WMI when it comes to monitoring MSMQ running in a cluster. I researched the solutions and didn't like the mess I found. One of my MSMQ savvy colleagues wrote me a VBScript utility to connect to queues count the number of messages. His solution was great because it guaranteed that we would have accurate message count data back from the queues and simultaneously tested the queue's up-time. Unfortunately, we discovered that this isn't perfect. The problem is that in order to get the message count we had to create a MSMQ.MSMQManagement COM object (YUCK!).

 Since we're performance minded folks, we monitored cscript.exe while it ran our script. We were shocked to find that although it ran for less than 2 seconds, it used ~160 MB of RAM and 99% of the CPU. This was totally unacceptable. We have over a hundred queues to monitor, and it would crater our monitoring environment. So then we moved on to plan B. I blew the dust off of a Powershell book someone let me borrow that I had been aggressively ignoring.

At first I found Powershell confusing, it was familiar in many ways, but unfamiliar in just as many. Fortunately, the book and with the encouragement of my book's owner I was able to throw down a script to mimic the work of the VBscript but using .NET's System.Messaging's Message Queue class. The trick was making the script reliable so that if it failed, our monitoring tool (PRTG) could send the operator a friendly message. It turns out that it was much easier than I expected. Without further ado, I give you the PRTG MSMQ Monitoring Powershell
Script:



5 comments:

  1. Very good, I was looking for something like this. Out of curiosity, have you managed to list the Incoming and Outgoing Queues in a cluster node? I tried in every possible way, but it doesn't seem to work... Thanks.

    ReplyDelete
  2. I have tried to get this script running for my MSMQ on a cluster but as newbie I don't really know PS1 at all. Is the script above runnable via copy paste to a PS1 file?

    ReplyDelete
  3. Hi all, for some reason my blog never emailed me about your comments. Let me know if you still need help. Also, it looks like the blog mangled the script so I'm re-posting it.

    ReplyDelete
  4. phakesley: Yes, all you need to do is save this script as a .ps1 file and place it in the custom EXE folder for PRTG.

    ReplyDelete
  5. Ryoma: I don't remember if this was tested on a cluster. Unfortunately, I've moved to greener pastures and I don't have a MSMQ cluster available to me. Be sure you're using the cluster name and not the hostname.

    ReplyDelete