(self, queue_manager)
Collect Statistics Messages

        Docs: https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.1.0/com.ibm.mq.mon.doc/q037320_.htm
Collect Statistics Messages
Collect Statistics Messages
def collect(self, queue_manager):
        """
        Collect Statistics Messages

        Docs: https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.1.0/com.ibm.mq.mon.doc/q037320_.htm
        """
        self.log.debug("Collecting stats newer than %s", self.config.instance_creation_datetime)
        queue = Queue(queue_manager, STATISTICS_QUEUE_NAME)

        try:
            # It's expected for the loop to stop when pymqi.MQMIError is raised with reason MQRC_NO_MSG_AVAILABLE.
            while True:
                bin_message = queue.get()
                self.log.trace('Stats binary message: %s', bin_message)

                message, header = pymqi.PCFExecute.unpack(bin_message)
                self.log.trace('Stats unpacked message: %s, Stats unpacked header: %s', message, header)

                stats = self._get_stats(message, header)

                # We only collect metrics generated after the check instance creation.
                if stats.start_datetime < self.config.instance_creation_datetime:
                    self.log.debug(
                        "Skipping messages created before agent startup. "
                        "Message time: %s / Check instance creation time: %s",
                        stats.start_datetime,
                        self.config.instance_creation_datetime,
                    )
                    continue

                if isinstance(stats, ChannelStats):
                    self._collect_channel_stats(stats)
                elif isinstance(stats, QueueStats):
                    self._collect_queue_stats(stats)
                else:
                    self.log.debug('Unknown/NotImplemented command: %s', header.Command)
        except pymqi.MQMIError as e:
            # Don't warn if no messages, see:
            # https://github.com/dsuch/pymqi/blob/v1.12.0/docs/examples.rst#how-to-wait-for-multiple-messages
            if e.comp == pymqi.CMQC.MQCC_FAILED and e.reason == pymqi.CMQC.MQRC_NO_MSG_AVAILABLE:
                self.log.debug("No messages available")
            else:
                raise
        finally:
            try:
                queue.close()
            except pymqi.PYIFError as e:
                self.log.debug("Could not close queue: %s", str(e))
def collect ( self , queue_manager ) : self . log . debug ( "Collecting stats newer than %s" , self . config . instance_creation_datetime ) queue = Queue ( queue_manager , STATISTICS_QUEUE_NAME ) try : # It's expected for the loop to stop when pymqi.MQMIError is raised with reason MQRC_NO_MSG_AVAILABLE. while True : bin_message = queue . get ( ) self . log . trace ( 'Stats binary message: %s' , bin_message ) message , header = pymqi . PCFExecute . unpack ( bin_message ) self . log . trace ( 'Stats unpacked message: %s, Stats unpacked header: %s' , message , header ) stats = self . _get_stats ( message , header ) # We only collect metrics generated after the check instance creation. if stats . start_datetime < self . config . instance_creation_datetime : self . log . debug ( "Skipping messages created before agent startup. " "Message time: %s / Check instance creation time: %s" , stats . start_datetime , self . config . instance_creation_datetime , ) continue if isinstance ( stats , ChannelStats ) : self . _collect_channel_stats ( stats ) elif isinstance ( stats , QueueStats ) : self . _collect_queue_stats ( stats ) else : self . log . debug ( 'Unknown/NotImplemented command: %s' , header . Command ) except pymqi . MQMIError as e : # Don't warn if no messages, see: # https://github.com/dsuch/pymqi/blob/v1.12.0/docs/examples.rst#how-to-wait-for-multiple-messages if e . comp == pymqi . CMQC . MQCC_FAILED and e . reason == pymqi . CMQC . MQRC_NO_MSG_AVAILABLE : self . log . debug ( "No messages available" ) else : raise finally : try : queue . close ( ) except pymqi . PYIFError as e : self . log . debug ( "Could not close queue: %s" , str ( e ) )