MQ Statistics Monitoring from C#/.NET

2019-02-19 14:04发布

One of the vendors that we trade MQ data with has a monitor that shows the following:

enter image description here

I've written a C# monitor of my own that takes a snap shot of the queue depth every x minutes, but I would like to know how to get the number of message enqueued and dequeued. These two stats seem to me to be of a different nature. To me queue depth is at a given point in time. The report above is actually showing "High Q Depth" for a 5 minute time period.

Can someone point me to something in the C#/.NET MQ API guide on how these statistics can be gathered? If not, what trick or tool might be able to get these stats?

标签: c#-4.0 ibm-mq
2条回答
倾城 Initia
2楼-- · 2019-02-19 14:18

MQ .NET has undocumented "support" for PCF under IBM.WMQ.PCF namespace. There are classes like PCFAgent, PCFMessage and so on. These can be used to read PCF messages.

For statics monitoring, you can turn on "Queue Statics" on queue. As described here queue statics messages include information like number of messages put or retrieved from a queue.

Sample code: This code inquires a queue manager for a queue with name Q1.

    public void InquireQmgr()
    {
        try
        {
            PCFMessageAgent messageAgent = new PCFMessageAgent("QM");

            PCFMessage pcfMsg = new PCFMessage(MQC.MQCMD_INQUIRE_Q);
            pcfMsg.AddParameter(MQC.MQCA_Q_NAME, "Q1");

            PCFMessage[] pcfResponse = messageAgent.Send(pcfMsg);
            int pcfResponseLen = pcfResponse.Length;

            for (int pcfResponseIdx = 0; pcfResponseIdx < pcfResponseLen; pcfResponseIdx++) 
            {
                PCFParameter [] parameters = pcfResponse[pcfResponseIdx].GetParameters();
                foreach(PCFParameter pm in parameters)
                {
                    Console.WriteLine(pm.Parameter +  " - " + pm.GetValue());
                }           
            }
            messageAgent.Disconnect();
        }
        catch(MQException ex)
        {
            Console.Write(ex);
        }
    }
查看更多
Melony?
3楼-- · 2019-02-19 14:35

The display you are seeing uses the (poorly named) Reset Queue Statistics PCF command. I refer to this as "the quantum command" of WMQ because the act of observing the values changes the values.

I see that the .Net manual documents the value for PCF as a message format. But I'm not terribly familiar with the .Net classes and don't know if they natively support PCF or if you'd have to cobble together something. (Perhaps Shashi will respond.)

Because inquiring on the queue stats resets them to zero, you get unpredictable results if more than one thing is making those inquiries. What I usually recommend is to have a background task performing the inquiries and saving the data off. Then the presentation layer queries the database for the stats instead of querying the QMgr directly.

查看更多
登录 后发表回答