(self, postfix_config_dir, tags)
root@postfix:/opt/datadog-agent/agent/checks.d# postqueue -p
        ----Queue ID----- --Size-- ---Arrival Time---- --Sender/Recipient------
        3xWyLP6Nmfz23fk        367 Tue Aug 15 16:17:33 root@postfix.devnull.home
                                                            (deferred transport)
                                                            alice@crypto.io

        3xWyD86NwZz23ff!       358 Tue Aug 15 16:12:08 root@postfix.devnull.home
                                                            (deferred transport)
                                                            bob@crypto.io

        -- 1 Kbytes in 2 Requests.
root@postfix:/opt/datadog-agent/agent/checks.d# postqueue -p
        ----Queue ID----- --Size-- ---Arrival Time---- --Sender/Recipient------
        3xWyLP6Nmfz23fk        367 Tue Aug 15 16:17:33 root@postfix.devnull.home
                                                            (deferred transport)
                                                            alice@crypto.io
root@postfix : / opt / datadog - agent / agent / checks . d# postqueue - p ---- Queue ID ----- -- Size -- --- Arrival Time ---- -- Sender / Recipient ------ 3xWyLP6Nmfz23fk 367 Tue Aug 15 16 : 17 : 33 root@postfix . devnull . home ( deferred transport ) alice@crypto . io
def _get_postqueue_stats(self, postfix_config_dir, tags):
        pc_output, _, _ = get_subprocess_output(['postconf', 'authorized_mailq_users'], self.log, False)

        if pc_output:
            authorized_mailq_users = pc_output.strip('\n').split('=')[1].strip()

            self.log.debug('authorized_mailq_users : %s', authorized_mailq_users)

        output, _, _ = get_subprocess_output(['postqueue', '-c', postfix_config_dir, '-p'], self.log, False)
        active_count = 0
        hold_count = 0
        deferred_count = 0

        # postque -p sample output
        '''
        root@postfix:/opt/datadog-agent/agent/checks.d# postqueue -p
        ----Queue ID----- --Size-- ---Arrival Time---- --Sender/Recipient------
        3xWyLP6Nmfz23fk        367 Tue Aug 15 16:17:33 root@postfix.devnull.home
                                                            (deferred transport)
                                                            alice@crypto.io

        3xWyD86NwZz23ff!       358 Tue Aug 15 16:12:08 root@postfix.devnull.home
                                                            (deferred transport)
                                                            bob@crypto.io

        -- 1 Kbytes in 2 Requests.
        '''
        lines = output.splitlines()
        # Check output
        if len(lines) > 1 and not output.startswith('Mail queue is empty'):
            for line in lines:
                if '*' in line:
                    active_count += 1
                elif '!' in line:
                    hold_count += 1
                # Check the line starts with an ID
                elif line[0:1].isalnum():
                    deferred_count += 1

        self.gauge(
            'postfix.queue.size', active_count, tags=tags + ['queue:active', 'instance:{}'.format(postfix_config_dir)]
        )
        self.gauge(
            'postfix.queue.size', hold_count, tags=tags + ['queue:hold', 'instance:{}'.format(postfix_config_dir)]
        )
        self.gauge(
            'postfix.queue.size',
            deferred_count,
            tags=tags + ['queue:deferred', 'instance:{}'.format(postfix_config_dir)],
        )
def _get_postqueue_stats ( self , postfix_config_dir , tags ) : pc_output , _ , _ = get_subprocess_output ( [ 'postconf' , 'authorized_mailq_users' ] , self . log , False ) if pc_output : authorized_mailq_users = pc_output . strip ( '\n' ) . split ( '=' ) [ 1 ] . strip ( ) self . log . debug ( 'authorized_mailq_users : %s' , authorized_mailq_users ) output , _ , _ = get_subprocess_output ( [ 'postqueue' , '-c' , postfix_config_dir , '-p' ] , self . log , False ) active_count = 0 hold_count = 0 deferred_count = 0 # postque -p sample output lines = output . splitlines ( ) # Check output if len ( lines ) > 1 and not output . startswith ( 'Mail queue is empty' ) : for line in lines : if '*' in line : active_count += 1 elif '!' in line : hold_count += 1 # Check the line starts with an ID elif line [ 0 : 1 ] . isalnum ( ) : deferred_count += 1 self . gauge ( 'postfix.queue.size' , active_count , tags = tags + [ 'queue:active' , 'instance:{}' . format ( postfix_config_dir ) ] ) self . gauge ( 'postfix.queue.size' , hold_count , tags = tags + [ 'queue:hold' , 'instance:{}' . format ( postfix_config_dir ) ] ) self . gauge ( 'postfix.queue.size' , deferred_count , tags = tags + [ 'queue:deferred' , 'instance:{}' . format ( postfix_config_dir ) ] , )