(self, _)
Get disk space/inode stats
Get disk space/inode stats
Get disk space / inode stats
def check(self, _):
        """Get disk space/inode stats"""
        if self._tag_by_label and Platform.is_linux():
            self.devices_label = self._get_devices_label()

        for part in psutil.disk_partitions(all=self._include_all_devices):
            # we check all exclude conditions
            if self.exclude_disk(part):
                self.log.debug('Excluding device %s', part.device)
                continue

            # Get disk metrics here to be able to exclude on total usage
            try:
                disk_usage = timeout(self._timeout)(psutil.disk_usage)(part.mountpoint)
            except TimeoutException:
                self.log.warning(
                    u'Timeout after %d seconds while retrieving the disk usage of `%s` mountpoint. '
                    u'You might want to change the timeout length in the settings.',
                    self._timeout,
                    part.mountpoint,
                )
                continue
            except Exception as e:
                self.log.warning(
                    u'Unable to get disk metrics for %s: %s. '
                    u'You can exclude this mountpoint in the settings if it is invalid.',
                    part.mountpoint,
                    e,
                )
                continue

            # Exclude disks with size less than min_disk_size
            if disk_usage.total <= self._min_disk_size:
                if disk_usage.total > 0:
                    self.log.info('Excluding device %s with total disk size %s', part.device, disk_usage.total)
                continue

            self.log.debug('Passed: %s', part.device)

            device_name = part.mountpoint if self._use_mount else part.device

            tags = [part.fstype, 'filesystem:{}'.format(part.fstype)] if self._tag_by_filesystem else []
            tags.extend(self._custom_tags)

            # apply device/mountpoint specific tags
            for regex, device_tags in self._device_tag_re:
                if regex.match(device_name):
                    tags.extend(device_tags)

            # apply device labels as tags (from blkid or lsblk).
            # we want to use the real device name and not the device_name (which can be the mountpoint)
            if self.devices_label.get(part.device):
                tags.extend(self.devices_label.get(part.device))

            # legacy check names c: vs psutil name C:\\
            if Platform.is_win32():
                device_name = device_name.strip('\\').lower()

            tags.append('device:{}'.format(device_name))
            tags.append('device_name:{}'.format(_base_device_name(part.device)))
            for metric_name, metric_value in iteritems(self._collect_part_metrics(part, disk_usage)):
                self.gauge(metric_name, metric_value, tags=tags)

            # Add in a disk read write or read only check
            if self._service_check_rw:
                rwro = {'rw', 'ro'} & set(part.opts.split(','))
                if len(rwro) == 1:
                    self.service_check(
                        'disk.read_write', AgentCheck.OK if rwro.pop() == 'rw' else AgentCheck.CRITICAL, tags=tags
                    )
                else:
                    self.service_check('disk.read_write', AgentCheck.UNKNOWN, tags=tags)

        self.collect_latency_metrics()
def check ( self , _ ) : if self . _tag_by_label and Platform . is_linux ( ) : self . devices_label = self . _get_devices_label ( ) for part in psutil . disk_partitions ( all = self . _include_all_devices ) : # we check all exclude conditions if self . exclude_disk ( part ) : self . log . debug ( 'Excluding device %s' , part . device ) continue # Get disk metrics here to be able to exclude on total usage try : disk_usage = timeout ( self . _timeout ) ( psutil . disk_usage ) ( part . mountpoint ) except TimeoutException : self . log . warning ( u'Timeout after %d seconds while retrieving the disk usage of `%s` mountpoint. ' u'You might want to change the timeout length in the settings.' , self . _timeout , part . mountpoint , ) continue except Exception as e : self . log . warning ( u'Unable to get disk metrics for %s: %s. ' u'You can exclude this mountpoint in the settings if it is invalid.' , part . mountpoint , e , ) continue # Exclude disks with size less than min_disk_size if disk_usage . total <= self . _min_disk_size : if disk_usage . total > 0 : self . log . info ( 'Excluding device %s with total disk size %s' , part . device , disk_usage . total ) continue self . log . debug ( 'Passed: %s' , part . device ) device_name = part . mountpoint if self . _use_mount else part . device tags = [ part . fstype , 'filesystem:{}' . format ( part . fstype ) ] if self . _tag_by_filesystem else [ ] tags . extend ( self . _custom_tags ) # apply device/mountpoint specific tags for regex , device_tags in self . _device_tag_re : if regex . match ( device_name ) : tags . extend ( device_tags ) # apply device labels as tags (from blkid or lsblk). # we want to use the real device name and not the device_name (which can be the mountpoint) if self . devices_label . get ( part . device ) : tags . extend ( self . devices_label . get ( part . device ) ) # legacy check names c: vs psutil name C:\\ if Platform . is_win32 ( ) : device_name = device_name . strip ( '\\' ) . lower ( ) tags . append ( 'device:{}' . format ( device_name ) ) tags . append ( 'device_name:{}' . format ( _base_device_name ( part . device ) ) ) for metric_name , metric_value in iteritems ( self . _collect_part_metrics ( part , disk_usage ) ) : self . gauge ( metric_name , metric_value , tags = tags ) # Add in a disk read write or read only check if self . _service_check_rw : rwro = { 'rw' , 'ro' } & set ( part . opts . split ( ',' ) ) if len ( rwro ) == 1 : self . service_check ( 'disk.read_write' , AgentCheck . OK if rwro . pop ( ) == 'rw' else AgentCheck . CRITICAL , tags = tags ) else : self . service_check ( 'disk.read_write' , AgentCheck . UNKNOWN , tags = tags ) self . collect_latency_metrics ( )