Video Screencast Help
Enterprise Vault

Monitoring MSMQ via vbs

Created: 04 Mar 2009 • Updated: 21 May 2009 • 7 comments
Wayne Humphrey's picture
+3 3 Votes
Login to vote

So a while ago I wrote a simple vbs to query MSMQ as the PerfMon counters are not reliable.  There is an updated script I did some ware just need to dig it out.

Option Explicit
Dim MSMQApp ' As MsmqApplication
Set MSMQApp = CreateObject("MSMQ.MSMQApplication")

Dim strComputer

If Wscript.Arguments.Count = 0 Then
                WScript.Echo "usage: msmq.vbs server_name queue "
                WScript.Echo " "
                WScript.Echo "e.g. cscript msmq.vbs tus1ev1idxpin01 queue"
Else
                strComputer = Wscript.Arguments(0)
END If

On Error Resume Next

MSMQApp.Machine=strComputer

Dim qFormat ' As String
For each qFormat in MSMQApp.PrivateQueues
                Dim Mgmt ' As new MSMQManagement
                Set Mgmt = CreateObject("MSMQ.MSMQManagement")
                Mgmt.Init MSMQApp.Machine,,"DIRECT=OS:" & qFormat
                if Wscript.Arguments(1) <> "" then
                                if instr(qformat, Wscript.Arguments(1)) >0 then
                                                WScript.Echo qFormat & "     Messages " & CLng(Mgmt.MessageCount) & "    Size: " & int(CLng(Mgmt.BytesInQueue) / 1024) & " Kb"
                                end if
                else
                                WScript.Echo qFormat & "     Messages " & CLng(Mgmt.MessageCount) & "    Size: " & int(CLng(Mgmt.BytesInQueue) / 1024) & " Kb"
                end if
Next

Comments 7 CommentsJump to latest comment

TonySterling's picture

Thanks Wayne, this is great stuff!

 

Cheers 

0
Login to vote
donnybutts's picture

Thanks Wayne.. good job.

 

Is there anyway to monitor a SPECIFIC queue only?

 

e.g. I have queues named 

myqueue

myqueue1

myqueue2

 

and i only want to monitor 'myqueue'  It always comes back with the results from all the queues.

0
Login to vote
Rob.Wilcox's picture

It can do that out of the box ..

 

Just do:

 

cscript nameofthescript.vbs name-of-the-machine queue-name-in-quotes

 

eg

 

cscript msmqmon.vbs ev1a "enterprise vault storage archive"
0
Login to vote
donnybutts's picture

Right. I get that. And I have it working that way. However, I am monitoring many servers (and that list of servers is always changing) for one queue only. I have a work around, but it's not too elegant. I want to nail down the For each qFormat in MSMQApp.PrivateQueues section to where it only pulls up the one queue that I need, rather than "For each.."

 

Also, when you do it "cscript msmq.vbs servername queuename" it will return everything with names of "queuename, queuename1, queuename2, etc."

0
Login to vote
Rob.Wilcox's picture

Change

if instr(qformat, Wscript.Arguments(1)) >0 then

 

to

 

if right(qformat, len(wscript.arguments(1))) = wscript.arguments(1) then

 

The values will then only be output when the queue name is an exact match.  

0
Login to vote
donnybutts's picture

Thanks so much for all your help Rob.

 

Of course, they changed their requirements, so now I'm back to doing all queues :)  It's working perfectly though.

0
Login to vote
Rob.Wilcox's picture
0
Login to vote