(self, pod_list, instance_tags)
Reports container state & reasons by looking at container statuses
Reports container state & reasons by looking at container statuses
Reports container state & reasons by looking at container statuses
def _report_container_state_metrics(self, pod_list, instance_tags):
        """Reports container state & reasons by looking at container statuses"""
        if pod_list.get('expired_count'):
            self.gauge(self.NAMESPACE + '.pods.expired', pod_list.get('expired_count'), tags=instance_tags)

        for pod in pod_list.get('items', []):
            pod_name = pod.get('metadata', {}).get('name')
            pod_uid = pod.get('metadata', {}).get('uid')

            if not pod_name or not pod_uid:
                continue

            for ctr_status in pod['status'].get('containerStatuses', []):
                c_name = ctr_status.get('name')
                cid = ctr_status.get('containerID')

                if not c_name or not cid:
                    continue

                if self.pod_list_utils.is_excluded(cid, pod_uid):
                    continue

                tags = tagger.tag(replace_container_rt_prefix(cid), tagger.ORCHESTRATOR)
                if not tags:
                    continue
                tags += instance_tags

                restart_count = ctr_status.get('restartCount', 0)
                self.gauge(self.NAMESPACE + '.containers.restarts', restart_count, tags)

                for (metric_name, field_name) in [('state', 'state'), ('last_state', 'lastState')]:
                    c_state = ctr_status.get(field_name, {})

                    for state_name in ['terminated', 'waiting']:
                        state_reasons = WHITELISTED_CONTAINER_STATE_REASONS.get(state_name, [])
                        self._submit_container_state_metric(metric_name, state_name, c_state, state_reasons, tags)
def _report_container_state_metrics ( self , pod_list , instance_tags ) : if pod_list . get ( 'expired_count' ) : self . gauge ( self . NAMESPACE + '.pods.expired' , pod_list . get ( 'expired_count' ) , tags = instance_tags ) for pod in pod_list . get ( 'items' , [ ] ) : pod_name = pod . get ( 'metadata' , { } ) . get ( 'name' ) pod_uid = pod . get ( 'metadata' , { } ) . get ( 'uid' ) if not pod_name or not pod_uid : continue for ctr_status in pod [ 'status' ] . get ( 'containerStatuses' , [ ] ) : c_name = ctr_status . get ( 'name' ) cid = ctr_status . get ( 'containerID' ) if not c_name or not cid : continue if self . pod_list_utils . is_excluded ( cid , pod_uid ) : continue tags = tagger . tag ( replace_container_rt_prefix ( cid ) , tagger . ORCHESTRATOR ) if not tags : continue tags += instance_tags restart_count = ctr_status . get ( 'restartCount' , 0 ) self . gauge ( self . NAMESPACE + '.containers.restarts' , restart_count , tags ) for ( metric_name , field_name ) in [ ( 'state' , 'state' ) , ( 'last_state' , 'lastState' ) ] : c_state = ctr_status . get ( field_name , { } ) for state_name in [ 'terminated' , 'waiting' ] : state_reasons = WHITELISTED_CONTAINER_STATE_REASONS . get ( state_name , [ ] ) self . _submit_container_state_metric ( metric_name , state_name , c_state , state_reasons , tags )