def update(self):
        """Update the FS stats using the input method."""
        # Init new stats
        stats = self.get_init_value()

        if self.input_method == 'local':
            # Update stats using the standard system lib

            # Grab the stats using the psutil disk_partitions
            # If 'all'=False return physical devices only (e.g. hard disks, cd-rom drives, USB keys)
            # and ignore all others (e.g. memory partitions such as /dev/shm)
            try:
                fs_stat = psutil.disk_partitions(all=False)
            except UnicodeDecodeError:
                return self.stats

            # Optionnal hack to allow logicals mounts points (issue #448)
            # Ex: Had to put 'allow=zfs' in the [fs] section of the conf file
            #     to allow zfs monitoring
            for fstype in self.get_conf_value('allow'):
                try:
                    fs_stat += [f for f in psutil.disk_partitions(all=True) if f.fstype.find(fstype) >= 0]
                except UnicodeDecodeError:
                    return self.stats

            # Loop over fs
            for fs in fs_stat:
                # Do not take hidden file system into account
                if self.is_hide(fs.mountpoint):
                    continue
                # Grab the disk usage
                try:
                    fs_usage = psutil.disk_usage(fs.mountpoint)
                except OSError:
                    # Correct issue #346
                    # Disk is ejected during the command
                    continue
                fs_current = {
                    'device_name': fs.device,
                    'fs_type': fs.fstype,
                    # Manage non breaking space (see issue #1065)
                    'mnt_point': u(fs.mountpoint).replace(u'\u00A0', ' '),
                    'size': fs_usage.total,
                    'used': fs_usage.used,
                    'free': fs_usage.free,
                    'percent': fs_usage.percent,
                    'key': self.get_key()}
                stats.append(fs_current)

        elif self.input_method == 'snmp':
            # Update stats using SNMP

            # SNMP bulk command to get all file system in one shot
            try:
                fs_stat = self.get_stats_snmp(snmp_oid=snmp_oid[self.short_system_name],
                                              bulk=True)
            except KeyError:
                fs_stat = self.get_stats_snmp(snmp_oid=snmp_oid['default'],
                                              bulk=True)

            # Loop over fs
            if self.short_system_name in ('windows', 'esxi'):
                # Windows or ESXi tips
                for fs in fs_stat:
                    # Memory stats are grabbed in the same OID table (ignore it)
                    if fs == 'Virtual Memory' or fs == 'Physical Memory' or fs == 'Real Memory':
                        continue
                    size = int(fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit'])
                    used = int(fs_stat[fs]['used']) * int(fs_stat[fs]['alloc_unit'])
                    percent = float(used * 100 / size)
                    fs_current = {
                        'device_name': '',
                        'mnt_point': fs.partition(' ')[0],
                        'size': size,
                        'used': used,
                        'percent': percent,
                        'key': self.get_key()}
                    stats.append(fs_current)
            else:
                # Default behavior
                for fs in fs_stat:
                    fs_current = {
                        'device_name': fs_stat[fs]['device_name'],
                        'mnt_point': fs,
                        'size': int(fs_stat[fs]['size']) * 1024,
                        'used': int(fs_stat[fs]['used']) * 1024,
                        'percent': float(fs_stat[fs]['percent']),
                        'key': self.get_key()}
                    stats.append(fs_current)

        # Update the stats
        self.stats = stats

        return self.stats
def update ( self ) : stats = self . get_init_value ( ) if self . input_method == 'local' : try : fs_stat = psutil . disk_partitions ( all = False ) except UnicodeDecodeError : return self . stats for fstype in self . get_conf_value ( 'allow' ) : try : fs_stat += [ f for f in psutil . disk_partitions ( all = True ) if f . fstype . find ( fstype ) >= 0 ] except UnicodeDecodeError : return self . stats for fs in fs_stat : if self . is_hide ( fs . mountpoint ) : continue try : fs_usage = psutil . disk_usage ( fs . mountpoint ) except OSError : continue fs_current = { 'device_name' : fs . device , 'fs_type' : fs . fstype , 'mnt_point' : u ( fs . mountpoint ) . replace ( u'\u00A0' , ' ' ) , 'size' : fs_usage . total , 'used' : fs_usage . used , 'free' : fs_usage . free , 'percent' : fs_usage . percent , 'key' : self . get_key ( ) } stats . append ( fs_current ) elif self . input_method == 'snmp' : try : fs_stat = self . get_stats_snmp ( snmp_oid = snmp_oid [ self . short_system_name ] , bulk = True ) except KeyError : fs_stat = self . get_stats_snmp ( snmp_oid = snmp_oid [ 'default' ] , bulk = True ) if self . short_system_name in ( 'windows' , 'esxi' ) : for fs in fs_stat : if fs == 'Virtual Memory' or fs == 'Physical Memory' or fs == 'Real Memory' : continue size = int ( fs_stat [ fs ] [ 'size' ] ) * int ( fs_stat [ fs ] [ 'alloc_unit' ] ) used = int ( fs_stat [ fs ] [ 'used' ] ) * int ( fs_stat [ fs ] [ 'alloc_unit' ] ) percent = float ( used * 100 / size ) fs_current = { 'device_name' : '' , 'mnt_point' : fs . partition ( ' ' ) [ 0 ] , 'size' : size , 'used' : used , 'percent' : percent , 'key' : self . get_key ( ) } stats . append ( fs_current ) else : for fs in fs_stat : fs_current = { 'device_name' : fs_stat [ fs ] [ 'device_name' ] , 'mnt_point' : fs , 'size' : int ( fs_stat [ fs ] [ 'size' ] ) * 1024 , 'used' : int ( fs_stat [ fs ] [ 'used' ] ) * 1024 , 'percent' : float ( fs_stat [ fs ] [ 'percent' ] ) , 'key' : self . get_key ( ) } stats . append ( fs_current ) self . stats = stats return self . stats
Update the FS stats using the input method.