How to display local queues where curdepth reached its maxdepth in ibm mq

落花浮王杯 提交于 2021-01-29 14:32:29

问题


I want to display all local queues where curdepth reached its maxdepth. I understand that the below where condition in runmqsc will not work. DIS QL(*) WHERE(CURDEPTH EQ MAXDEPTH) I am trying to parse it with sed and awk but not even close as I am no expert in scripting

Please help in getting desired output. Thanks


回答1:


Isn't this like trying to squeeze a fully blown up balloon into a wine bottle?

It would seem far, far simpler to just run a Java/MQ/PCF application to get both the current and maximum depths and compare the values.

Here is a simple (complete) Java/MQ/PCF application to do that:

Note: It has a filter on the PCF command to only return queues with a current depth greater than zero. Hence, the queue manager's command server will return less data and make over all processing faster.

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;

import com.ibm.mq.MQException;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;
import com.ibm.mq.constants.CMQCFC;
import com.ibm.mq.headers.MQDataException;
import com.ibm.mq.headers.pcf.PCFMessage;
import com.ibm.mq.headers.pcf.PCFMessageAgent;

/**
 * Program Name
 *  MQCurrentDepthMonitor01
 *
 * Description
 *  This java class issues a PCF "inquire queue" request message for all ("*") local queues 
 *  with a queue depth greater than 0 (zero) of a remote queue manager and  
 *  (1) output an error message if current depth is the same as max depth or
 *  (2) output a warning message if current depth is within 90% of max depth.
 *
 * Sample Command Line Parameters
 *  -m MQA1 -h 127.0.0.1 -p 1414 -c TEST.CHL -u UserID -x Password
 *
 * @author Roger Lacroix
 */
public class MQCurrentDepthMonitor01
{
   private static final SimpleDateFormat  LOGGER_TIMESTAMP = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");

   private Hashtable<String,String> params;
   private Hashtable<String,Object> mqht;
   private String qMgrName;

   public MQCurrentDepthMonitor01()
   {
      super();
      params = new Hashtable<String,String>();
      mqht = new Hashtable<String,Object>();
   }

   /**
    * Make sure the required parameters are present.
    * @return true/false
    */
   private boolean allParamsPresent()
   {
      boolean b = params.containsKey("-h") && params.containsKey("-p") &&
                  params.containsKey("-c") && params.containsKey("-m") &&
                  params.containsKey("-u") && params.containsKey("-x");
      if (b)
      {
         try
         {
            Integer.parseInt((String) params.get("-p"));
         }
         catch (NumberFormatException e)
         {
            b = false;
         }
      }

      return b;
   }

   /**
    * Extract the command-line parameters and initialize the MQ HashTable.
    * @param args
    * @throws IllegalArgumentException
    */
   private void init(String[] args) throws IllegalArgumentException
   {
      int port = 1414;
      if (args.length > 0 && (args.length % 2) == 0)
      {
         for (int i = 0; i < args.length; i += 2)
         {
            params.put(args[i], args[i + 1]);
         }
      }
      else
      {
         throw new IllegalArgumentException();
      }

      if (allParamsPresent())
      {
         qMgrName = (String) params.get("-m");

         try
         {
            port = Integer.parseInt((String) params.get("-p"));
         }
         catch (NumberFormatException e)
         {
            port = 1414;
         }

         mqht.put(CMQC.CHANNEL_PROPERTY, params.get("-c"));
         mqht.put(CMQC.HOST_NAME_PROPERTY, params.get("-h"));
         mqht.put(CMQC.PORT_PROPERTY, new Integer(port));
         mqht.put(CMQC.USER_ID_PROPERTY, params.get("-u"));
         mqht.put(CMQC.PASSWORD_PROPERTY, params.get("-x"));

         // I don't want to see MQ exceptions at the console.
         MQException.log = null;
      }
      else
      {
         throw new IllegalArgumentException();
      }
   }

   /**
    * Handle connecting to the queue manager, issuing PCF command then 
    * looping through PCF response messages and disconnecting from 
    * the queue manager. 
    */
   private void doPCF()
   {
      MQQueueManager qMgr = null;
      PCFMessageAgent agent = null;
      PCFMessage   request = null;
      PCFMessage[] responses = null;

      try
      {
         qMgr = new MQQueueManager(qMgrName, mqht);
         MQCurrentDepthMonitor01.logger("successfully connected to "+ qMgrName);

         agent = new PCFMessageAgent(qMgr);
         MQCurrentDepthMonitor01.logger("successfully created agent");

         // https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.1.0/com.ibm.mq.ref.adm.doc/q087800_.htm
         request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);

         /**
          * You can explicitly set a queue name like "TEST.Q1" or
          * use a wild card like "TEST.*"
          */
         request.addParameter(CMQC.MQCA_Q_NAME, "*");

         // Add parameter to request only local queues
         request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);

         // Add parameter to request only queue name, current depth and max depth
         request.addParameter(CMQCFC.MQIACF_Q_ATTRS, new int [] { 
                                                                  CMQC.MQCA_Q_NAME,
                                                                  CMQC.MQIA_CURRENT_Q_DEPTH,
                                                                  CMQC.MQIA_MAX_Q_DEPTH
                                                                });

         // Add filter to only return responses with a queue depth greater than 0 (zero)  
         // i.e. non-zero queue depth
         request.addFilterParameter(CMQC.MQIA_CURRENT_Q_DEPTH, CMQCFC.MQCFOP_GREATER, 0);

         responses = agent.send(request);

//         MQCurrentDepthMonitor01.logger("responses.length="+responses.length);

         int curDepth = -1;
         int maxDepth = -1;

         for (int i = 0; i < responses.length; i++)
         {
            if ( ((responses[i]).getCompCode() == CMQC.MQCC_OK) &&
                 ((responses[i]).getParameterValue(CMQC.MQCA_Q_NAME) != null) )
            {
               String name = responses[i].getStringParameterValue(CMQC.MQCA_Q_NAME);
               if (name != null)
                  name = name.trim();

               curDepth = responses[i].getIntParameterValue(CMQC.MQIA_CURRENT_Q_DEPTH);
               maxDepth = responses[i].getIntParameterValue(CMQC.MQIA_MAX_Q_DEPTH);

//               MQCurrentDepthMonitor01.logger("Name="+name + " : curDepth="+curDepth + " : maxDepth="+maxDepth);

               if (curDepth == maxDepth)
                  MQCurrentDepthMonitor01.logger("ERROR: Name="+name + " : current depth equals max depth ["+maxDepth+"]");
               else if (curDepth >= (maxDepth * 0.9))
                  MQCurrentDepthMonitor01.logger("Warning: Name="+name + " : current depth ["+curDepth+"] is within 90% of max depth ["+maxDepth+"]");
            }
         }
      }
      catch (MQException e)
      {
         MQCurrentDepthMonitor01.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
      }
      catch (IOException e)
      {
         MQCurrentDepthMonitor01.logger("IOException:" +e.getLocalizedMessage());
      }
      catch (MQDataException e)
      {
         MQCurrentDepthMonitor01.logger("MQDataException:" +e.getLocalizedMessage());
      }
      finally
      {
         try
         {
            if (agent != null)
            {
               agent.disconnect();
               MQCurrentDepthMonitor01.logger("disconnected from agent");
            }
         }
         catch (MQDataException e)
         {
            MQCurrentDepthMonitor01.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         }

         try
         {
            if (qMgr != null)
            {
               qMgr.disconnect();
               MQCurrentDepthMonitor01.logger("disconnected from "+ qMgrName);
            }
         }
         catch (MQException e)
         {
            MQCurrentDepthMonitor01.logger("CC=" +e.completionCode + " : RC=" + e.reasonCode);
         }
      }
   }

   /**
    * A simple logger method
    * @param data
    */
   public static void logger(String data)
   {
      String className = Thread.currentThread().getStackTrace()[2].getClassName();

      // Remove the package info.
      if ( (className != null) && (className.lastIndexOf('.') != -1) )
         className = className.substring(className.lastIndexOf('.')+1);

      System.out.println(LOGGER_TIMESTAMP.format(new Date())+" "+className+": "+Thread.currentThread().getStackTrace()[2].getMethodName()+": "+data);
   }

   public static void main(String[] args)
   {
      MQCurrentDepthMonitor01 mqlqs = new MQCurrentDepthMonitor01();

      try
      {
         mqlqs.init(args);
         mqlqs.doPCF();
      }
      catch (IllegalArgumentException e)
      {
         MQCurrentDepthMonitor01.logger("Usage: java MQCurrentDepthMonitor01 -m QueueManagerName -h host -p port -c channel -u UserID -x Password");
         System.exit(1);
      }

      System.exit(0);
   }
}


来源:https://stackoverflow.com/questions/62190771/how-to-display-local-queues-where-curdepth-reached-its-maxdepth-in-ibm-mq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!