|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Browsing First and Last Message for Monitoring |
« View previous topic :: View next topic » |
Author |
Message
|
bigjokey |
Posted: Sun May 04, 2008 11:04 pm Post subject: Browsing First and Last Message for Monitoring |
|
|
Newbie
Joined: 04 May 2008 Posts: 3
|
I am currently writing a vbscript which the intention is to monitor some queues to ensure that they are receiving and processing messages. To do this I am attempting to read the PutDateTime of the First and Last Message.
I can currently do this by reading from the first message to the last message on the queue, which is barely satisfactory. I am hoping someone can help me with finding a constant or search criteria that will help me move the browse cursor to the last message in a queue to save processing time when there is a large volume of messages on a queue. The following is a function that performs the scan.
Code: |
Function getQueueMessageTimes(strQueueManager, strQueue, strFirstMsgTime, strLastMsgTime)
Dim MQSess, QMgr, queue, qMsg, qGetOptions
Dim intIndex
Set MQSess = CreateObject("MQAX200.MQSession")
Set QMgr = MQSess.AccessQueueManager(strQueueManager)
' Open queue for input and output
Set queue = QMgr.AccessQueue(strQueue, MQOO_BROWSE + MQOO_INQUIRE)
Set qMsg = MQSess.AccessMessage()
Set qGetOptions = MQSess.AccessGetMessageOptions()
For cnt = 1 To queue.CurrentDepth
qMsg.MessageID = MQMI_NONE
qMsg.CorrelationId = MQCI_NONE
If cnt = 1 Then
qGetOptions.Options = MQGMO_BROWSE_FIRST
Else
qGetOptions.Options = MQGMO_BROWSE_NEXT
End If
' Now get the message
Call queue.Get(qMsg, qGetOptions)
' If the first message time is empty, then populate the first message time
If strFirstMsgTime = "" Then
strFirstMsgTime = qMsg.PutDateTime
ElseIf cnt = queue.CurrentDepth Then
' When we get to the last message, store the message time
strLastMsgTime = qMsg.PutDateTime
End If
Next
WScript.Echo "First Message PutDateTime: " & strFirstMsgTime & ", Last Message PutDateTime: " & strLastMsgTime
queue.close()
QMgr.disconnect()
End Function
|
Any help would be appreciated, even suggestions for performing my requirement another way might be useful. I am aware that there are tools out there that perform specific monitoring, but they are not what I am looking for.
Thanks in advance for your time. |
|
Back to top |
|
 |
Mr Butcher |
Posted: Sun May 04, 2008 11:53 pm Post subject: |
|
|
 Padawan
Joined: 23 May 2005 Posts: 1716
|
you should take a look at the mqseries build-in statistics. i am quite sure there is something that indicates you if a queue is processed or not.
browsing the messages from first to last at every monitoring intervall is not a good idea (imho) _________________ Regards, Butcher |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon May 05, 2008 4:48 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
In fact, browsing the queue for all the messages is exactly the worst way to do this monitoring...
Look at the acct&stats, look at RESET QUEUE STATISTICS, look at the Monitoring manual.
Look at buying and implementing a real monitoring solution. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
bigjokey |
Posted: Mon May 05, 2008 4:19 pm Post subject: |
|
|
Newbie
Joined: 04 May 2008 Posts: 3
|
I know exactly that browsing the queue for all the messages is the worst way of doing this, that is why I asked the question of how to move the browse cursor to the last message; which would prevent the browsing of all messages (I am trying to avoid browsing all messages).
Buying a real monitoring solution is not an option for me, which is why I mentioned that I am aware that they exist, but they are not what I am looking for.
Mr Butcher, are the statistics available via an API? |
|
Back to top |
|
 |
PeterPotkay |
Posted: Mon May 05, 2008 5:00 pm Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
Download the MO71 Support Pack which will allow you to play with these parms without writing code. Queue Statistics is what you want. Make sure the Queue Manager has Performance Events turned on.
You can get Queue Statistics by submitting PCF commands to the Queue Manager if you want to roll your own.
I'll repeat the advice about not browsing to try and accomplish this. It will not tell you anything. For example, put 10 messages in a queue with no expiry and have an app send in thousands of messages while a second does selective gets ignoring the 1st 10 messages that sit there forever. 1st and last message put times would tell you nothing is going thru this queue. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
Vitor |
Posted: Tue May 06, 2008 12:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
bigjokey wrote: |
I am trying to avoid browsing all messages |
There is no way to avoid it programatically, which is one of the reasons it's such a bad solution. My associate has listed some of the others.
bigjokey wrote: |
Buying a real monitoring solution is not an option for me |
It should be an option for your budget holder. Get them to investigate TCO for a commercial monitoring solution against what you're producing. Most people are surprised by the result.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
bigjokey |
Posted: Tue May 20, 2008 10:18 pm Post subject: Solution |
|
|
Newbie
Joined: 04 May 2008 Posts: 3
|
Thanks for the suggestions. In the end I found the easiest way was to use the RUNMQSC command line tool. In version 5.3 there wasn't much useful information regarding queue statistics, but version 6 of MQ has exactly the information that I require.
My solution was to call the RUNMQSC command from within a vbscript, capture the output and then parse the output to get the values required.
Note: This script requires the MQ Manager's "Queue Monitoring" property to be set to at least 'Low', otherwise you will not receive the useful queue statistics.
The following is the code I have written if anyone requires a similar solution:
Code: |
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim strQueueQuery, dtLastPut, dtLastGet, intCurrentDepth, intMessageAge
strQueueQuery = QueryQueue("Q_MGR_NAME", "MY.QUEUE.NAME")
Call ParseQueueStatus(strQueueQuery, dtLastPut, dtLastGet, intCurrentDepth, intMessageAge)
Function QueryQueue(strQueueManager, strQueueName)
Dim wshShell, oExec, strCmdOutput
Set wshShell = CreateObject("WScript.Shell")
Set oExec = wshShell.Exec("runmqsc " & strQueueManager)
oExec.StdIn.Write "display qstatus(" & strQueueName & ") All" & vbCrLf
oExec.StdIn.Write "End" & vbCrLf
Do While not oExec.StdOut.AtEndOfStream
strCmdOutput = strCmdOutput & oExec.StdOut.Read(1)
Loop
Do While oExec.Status = 0
WScript.Sleep 100
Loop
WScript.Echo oExec.Status
QueryQueue = strCmdOutput
set wshshell = nothing
End Function
Function ParseQueueStatus(strQueryOutput, dtLastPut, dtLastGet, intCurrentDepth, intMessageAge)
dim strDate, strTime
strDate = getQueueStatusValue(strQueryOutput, "LPUTDATE")
strTime = getQueueStatusValue(strQueryOutput, "LPUTTIME")
dtLastPut = ParseQueueDateTime( strDate, strTime )
strDate = getQueueStatusValue(strQueryOutput, "LGETDATE")
strTime = getQueueStatusValue(strQueryOutput, "LGETTIME")
dtLastGet = ParseQueueDateTime( strDate, strTime )
intCurrentDepth = getQueueStatusValue(strQueryOutput, "CURDEPTH")
intMessageAge = getQueueStatusValue(strQueryOutput, "MSGAGE")
WScript.Echo "dtLastPut: " & dtLastPut & ", dtLastGet: " & dtLastGet & ", intCurrentDepth: " & intCurrentDepth & ", intMessageAge: " & intMessageAge
WScript.Echo "Message Age (Days): " & ConvertMessageAge(intMessageAge, "d")
WScript.Echo "Message Age (Hours): " & ConvertMessageAge(intMessageAge, "h")
WScript.Echo "Message Age (Minutes): " & Fix(ConvertMessageAge(intMessageAge, "n"))
End Function
Function getQueueStatusValue(strQueryOutput, StatusKey)
Dim intStartIndex, intEndIndex, strKeySearch
strKeySearch = UCase(StatusKey) & "("
intStartIndex = InStr(strQueryOutput, strKeySearch )
If intStartIndex > 0 Then
intEndIndex = InStr(intStartIndex, strQueryOutput, ")" )
intStartIndex = intStartIndex + Len(strKeySearch)
getQueueStatusValue = Mid( strQueryOutput, intStartIndex, intEndIndex - intStartIndex )
Else
getQueueStatusValue = ""
End If
End Function
Function ParseQueueDateTime(strDate, strTime)
dim dtTime
dtTime = CDate(strDate & " " & Replace(strTime, ".", ":"))
ParseQueueDateTime = dtTime
End Function
Function ConvertMessageAge(intAge, strFormat)
' n = minutes
' h = hours
' d = days
Select Case LCase(strFormat)
Case "n"
ConvertMessageAge = intAge / 60
Case "h"
ConvertMessageAge = intAge / 3600
Case "d"
ConvertMessageAge = intAge / 86400
Case Else
ConvertMessageAge = intAge
End Select
End Function
|
|
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|