(self, pod_list, instance_tags)
Reports pod requests & limits by looking at pod specs.
Reports pod requests & limits by looking at pod specs.
Reports pod requests & limits by looking at pod specs .
def _report_container_spec_metrics(self, pod_list, instance_tags):
        """Reports pod requests & limits by looking at pod specs."""
        for pod in pod_list.get('items', []):
            pod_name = pod.get('metadata', {}).get('name')
            pod_phase = pod.get('status', {}).get('phase')
            if self._should_ignore_pod(pod_name, pod_phase):
                continue

            for ctr in pod['spec']['containers']:
                if not ctr.get('resources'):
                    continue

                c_name = ctr.get('name', '')
                cid = None
                for ctr_status in pod['status'].get('containerStatuses', []):
                    if ctr_status.get('name') == c_name:
                        # it is already prefixed with 'runtime://'
                        cid = ctr_status.get('containerID')
                        break
                if not cid:
                    continue

                pod_uid = pod.get('metadata', {}).get('uid')
                if self.pod_list_utils.is_excluded(cid, pod_uid):
                    continue

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

                try:
                    for resource, value_str in iteritems(ctr.get('resources', {}).get('requests', {})):
                        value = self.parse_quantity(value_str)
                        self.gauge('{}.{}.requests'.format(self.NAMESPACE, resource), value, tags)
                except (KeyError, AttributeError) as e:
                    self.log.debug("Unable to retrieve container requests for %s: %s", c_name, e)

                try:
                    for resource, value_str in iteritems(ctr.get('resources', {}).get('limits', {})):
                        value = self.parse_quantity(value_str)
                        self.gauge('{}.{}.limits'.format(self.NAMESPACE, resource), value, tags)
                except (KeyError, AttributeError) as e:
                    self.log.debug("Unable to retrieve container limits for %s: %s", c_name, e)
def _report_container_spec_metrics ( self , pod_list , instance_tags ) : for pod in pod_list . get ( 'items' , [ ] ) : pod_name = pod . get ( 'metadata' , { } ) . get ( 'name' ) pod_phase = pod . get ( 'status' , { } ) . get ( 'phase' ) if self . _should_ignore_pod ( pod_name , pod_phase ) : continue for ctr in pod [ 'spec' ] [ 'containers' ] : if not ctr . get ( 'resources' ) : continue c_name = ctr . get ( 'name' , '' ) cid = None for ctr_status in pod [ 'status' ] . get ( 'containerStatuses' , [ ] ) : if ctr_status . get ( 'name' ) == c_name : # it is already prefixed with 'runtime://' cid = ctr_status . get ( 'containerID' ) break if not cid : continue pod_uid = pod . get ( 'metadata' , { } ) . get ( 'uid' ) if self . pod_list_utils . is_excluded ( cid , pod_uid ) : continue tags = tagger . tag ( replace_container_rt_prefix ( cid ) , tagger . HIGH ) if not tags : continue tags += instance_tags try : for resource , value_str in iteritems ( ctr . get ( 'resources' , { } ) . get ( 'requests' , { } ) ) : value = self . parse_quantity ( value_str ) self . gauge ( '{}.{}.requests' . format ( self . NAMESPACE , resource ) , value , tags ) except ( KeyError , AttributeError ) as e : self . log . debug ( "Unable to retrieve container requests for %s: %s" , c_name , e ) try : for resource , value_str in iteritems ( ctr . get ( 'resources' , { } ) . get ( 'limits' , { } ) ) : value = self . parse_quantity ( value_str ) self . gauge ( '{}.{}.limits' . format ( self . NAMESPACE , resource ) , value , tags ) except ( KeyError , AttributeError ) as e : self . log . debug ( "Unable to retrieve container limits for %s: %s" , c_name , e )