Collect xfs stats.

        For an explanation of the following metrics visit
        http://xfs.org/index.php/Runtime_Stats
        https://github.com/torvalds/linux/blob/master/fs/xfs/xfs_stats.h
320211
def collect(self):
        
        data_structure = {
            'extent_alloc': (
                'alloc_extent',
                'alloc_block',
                'free_extent',
                'free_block'
            ),
            'abt': (
                'lookup',
                'compare',
                'insrec',
                'delrec'
            ),
            'blk_map': (
                'read_ops',
                'write_ops',
                'unmap',
                'add_exlist',
                'del_exlist',
                'look_exlist',
                'cmp_exlist'
            ),
            'bmbt': (
                'lookup',
                'compare',
                'insrec',
                'delrec'
            ),
            'dir': (
                'lookup',
                'create',
                'remove',
                'getdents'
            ),
            'trans': (
                'sync',
                'async',
                'empty'
            ),
            'ig': (
                'ig_attempts',
                'ig_found',
                'ig_frecycle',
                'ig_missed',
                'ig_dup',
                'ig_reclaims',
                'ig_attrchg'
            ),
            'log': (
                'writes',
                'blocks',
                'noiclogs',
                'force',
                'force_sleep'
            ),
            'push_ail': (
                'try_logspace',
                'sleep_logspace',
                'pushes',
                'success',
                'pushbuf',
                'pinned',
                'locked',
                'flushing',
                'restarts',
                'flush'
            ),
            'xstrat': (
                'quick',
                'split'
            ),
            'rw': (
                'write_calls',
                'read_calls'
            ),
            'attr': (
                'get',
                'set',
                'remove',
                'list'
            ),
            'icluster': (
                'iflush_count',
                'icluster_flushcnt',
                'icluster_flushinode'
            ),
            'vnodes': (
                'vn_active',
                'vn_alloc',
                'vn_get',
                'vn_hold',
                'vn_rele',
                'vn_reclaim',
                'vn_remove',
                'vn_free'
            ),
            'buf': (
                'xb_get',
                'xb_create',
                'xb_get_locked',
                'xb_get_locked_waited',
                'xb_busy_locked',
                'xb_miss_locked',
                'xb_page_retries',
                'xb_page_found',
                'xb_get_read'
            ),
            'abtb2': (
                'xs_abtb_2_lookup',
                'xs_abtb_2_compare',
                'xs_abtb_2_insrec',
                'xs_abtb_2_delrec',
                'xs_abtb_2_newroot',
                'xs_abtb_2_killroot',
                'xs_abtb_2_increment',
                'xs_abtb_2_decrement',
                'xs_abtb_2_lshift',
                'xs_abtb_2_rshift',
                'xs_abtb_2_split',
                'xs_abtb_2_join',
                'xs_abtb_2_alloc',
                'xs_abtb_2_free',
                'xs_abtb_2_moves'
            ),
            'abtc2': (
                'xs_abtc_2_lookup',
                'xs_abtc_2_compare',
                'xs_abtc_2_insrec',
                'xs_abtc_2_delrec',
                'xs_abtc_2_newroot',
                'xs_abtc_2_killroot',
                'xs_abtc_2_increment',
                'xs_abtc_2_decrement',
                'xs_abtc_2_lshift',
                'xs_abtc_2_rshift',
                'xs_abtc_2_split',
                'xs_abtc_2_join',
                'xs_abtc_2_alloc',
                'xs_abtc_2_free',
                'xs_abtc_2_moves'
            ),
            'bmbt2': (
                'xs_bmbt_2_lookup',
                'xs_bmbt_2_compare',
                'xs_bmbt_2_insrec',
                'xs_bmbt_2_delrec',
                'xs_bmbt_2_newroot',
                'xs_bmbt_2_killroot',
                'xs_bmbt_2_increment',
                'xs_bmbt_2_decrement',
                'xs_bmbt_2_lshift',
                'xs_bmbt_2_rshift',
                'xs_bmbt_2_split',
                'xs_bmbt_2_join',
                'xs_bmbt_2_alloc',
                'xs_bmbt_2_free',
                'xs_bmbt_2_moves'
            ),
            'ibt2': (
                'lookup',
                'compare',
                'insrec',
                'delrec',
                'newroot',
                'killroot',
                'increment',
                'decrement',
                'lshift',
                'rshift',
                'split',
                'join',
                'alloc',
                'free',
                'moves'
            ),
            'fibt2': (
                'lookup',
                'compare',
                'insrec',
                'delrec',
                'newroot',
                'killroot',
                'increment',
                'decrement',
                'lshift',
                'rshift',
                'split',
                'join',
                'alloc',
                'free',
                'moves'
            ),
            'qm': (
                'xs_qm_dquot',
                'xs_qm_dquot_unused'
            ),

            'xpc': (
                'xs_xstrat_bytes',
                'xs_write_bytes',
                'xs_read_bytes'
            ),
            'debug': (
                'debug',
            )
        }

        f = open(self.PROC)
        new_stats = f.readlines()
        f.close()

        stats = {}
        for line in new_stats:
            items = line.rstrip().split()
            stats[items[0]] = [int(a) for a in items[1:]]

        for key in stats.keys():
            for item in enumerate(data_structure[key]):
                metric_name = '.'.join([key, item[1]])
                value = stats[key][item[0]]
                self.publish_counter(metric_name, value)
1049992
def collect(self):
        

        metrics = {}

        if 'scan' in self.config:
            for ld in os.listdir(self.config['owfs']):
                if '.' in ld:
                    self.read_values(ld, self.config['scan'], metrics)

        for oid, files in self.config.iteritems():
            if oid[:3] == 'id:':
                self.read_values(oid[3:], files, metrics)

        for fn, fv in metrics.iteritems():
            self.publish(fn, fv, 2)
196610
def load_stats(self, fdump):
        
        if isinstance(fdump, type('')):
            fdump = open(fdump, 'rb')
        self.index = pickle.load(fdump)
        self.snapshots = pickle.load(fdump)
        self.sorted = []
1217949
def diskstats():
    '''
    
    '''
    def linux_diskstats():
        '''
        linux specific implementation of diskstats
        '''
        ret = {}
        try:
            with salt.utils.files.fopen('/proc/diskstats', 'r') as fp_:
                stats = salt.utils.stringutils.to_unicode(fp_.read())
        except IOError:
            pass
        else:
            for line in stats.splitlines():
                if not line:
                    continue
                comps = line.split()
                ret[comps[2]] = {
                    'major': _number(comps[0]),
                    'minor': _number(comps[1]),
                    'device': _number(comps[2]),
                    'reads_issued': _number(comps[3]),
                    'reads_merged': _number(comps[4]),
                    'sectors_read': _number(comps[5]),
                    'ms_spent_reading': _number(comps[6]),
                    'writes_completed': _number(comps[7]),
                    'writes_merged': _number(comps[8]),
                    'sectors_written': _number(comps[9]),
                    'ms_spent_writing': _number(comps[10]),
                    'io_in_progress': _number(comps[11]),
                    'ms_spent_in_io': _number(comps[12]),
                    'weighted_ms_spent_in_io': _number(comps[13])
                }
        return ret

    def generic_diskstats():
        '''
        generic implementation of diskstats
        note: freebsd and sunos
        '''
        ret = {}
        iostat = __salt__['cmd.run']('iostat -xzd').splitlines()
        header = iostat[1]
        for line in iostat[2:]:
            comps = line.split()
            ret[comps[0]] = {}
            for metric, value in zip(header.split()[1:], comps[1:]):
                ret[comps[0]][metric] = _number(value)
        return ret

    def aix_diskstats():
        '''
        AIX specific implementation of diskstats
        '''
        ret = {}
        procn = None
        fields = []
        disk_name = ''
        disk_mode = ''
        for line in __salt__['cmd.run']('iostat -dDV').splitlines():
            # Note: iostat -dDV is per-system
            #
            #System configuration: lcpu=8 drives=1 paths=2 vdisks=2
            #
            #hdisk0          xfer:  %tm_act      bps      tps      bread      bwrtn
            #                          0.0      0.8      0.0        0.0        0.8
            #                read:      rps  avgserv  minserv  maxserv   timeouts      fails
            #                          0.0      2.5      0.3     12.4           0          0
            #               write:      wps  avgserv  minserv  maxserv   timeouts      fails
            #                          0.0      0.3      0.2      0.7           0          0
            #               queue:  avgtime  mintime  maxtime  avgwqsz    avgsqsz     sqfull
            #                          0.3      0.0      5.3      0.0        0.0         0.0
            #--------------------------------------------------------------------------------
            if not line or line.startswith('System') or line.startswith('-----------'):
                continue

            if not re.match(r'\s', line):
                #have new disk
                dsk_comps = line.split(':')
                dsk_firsts = dsk_comps[0].split()
                disk_name = dsk_firsts[0]
                disk_mode = dsk_firsts[1]
                fields = dsk_comps[1].split()
                ret[disk_name] = []

                procn = len(ret[disk_name])
                ret[disk_name].append({})
                ret[disk_name][procn][disk_mode] = {}
                continue

            if ':' in line:
                comps = line.split(':')
                fields = comps[1].split()
                disk_mode = comps[0].lstrip()
                procn = len(ret[disk_name])
                ret[disk_name].append({})
                ret[disk_name][procn][disk_mode] = {}
            else:
                comps = line.split()
                for i in range(0, len(fields)):
                    if len(comps) > i:
                        ret[disk_name][procn][disk_mode][fields[i]] = comps[i]

        return ret

    # dict that return a function that does the right thing per platform
    get_version = {
        'Linux': linux_diskstats,
        'FreeBSD': generic_diskstats,
        'SunOS': generic_diskstats,
        'AIX': aix_diskstats,
    }

    errmsg = 'This method is unsupported on the current operating system!'
    return get_version.get(__grains__['kernel'], lambda: errmsg)()
630436
def metrics(self):
        
        masterThrp, backupThrp = self.getThroughputs(self.instances.masterId)
        r = self.instance_throughput_ratio(self.instances.masterId)
        m = [
            ("{} Monitor metrics:".format(self), None),
            ("Delta", self.Delta),
            ("Lambda", self.Lambda),
            ("Omega", self.Omega),
            ("instances started", self.instances.started),
            ("ordered request counts",
             {i: r[0] for i, r in self.numOrderedRequests.items()}),
            ("ordered request durations",
             {i: r[1] for i, r in self.numOrderedRequests.items()}),
            ("master request latencies", self.masterReqLatencies),
            ("client avg request latencies", {i: self.getLatency(i)
                                              for i in self.instances.ids}),
            ("throughput", {i: self.getThroughput(i)
                            for i in self.instances.ids}),
            ("master throughput", masterThrp),
            ("total requests", self.totalRequests),
            ("avg backup throughput", backupThrp),
            ("master throughput ratio", r)]
        return m
1228943
function _getStats(uri) {
        return new FileSystemStats({
            isFile: true,
            mtime: SESSION_START_TIME.toISOString(),
            size: 0,
            realPath: uri,
            hash: uri
        });
    }
1128531
def collect(self):
        
        stats_config = self.config['stats']
        if USE_PYTHON_BINDING:
            collect_metrics = self.collect_via_pynvml
        else:
            collect_metrics = self.collect_via_nvidia_smi

        collect_metrics(stats_config)
724711
def retrieveVals(self):
        """"""
        fpminfo = PHPfpmInfo(self._host, self._port, self._user, self._password, 
                             self._monpath, self._ssl)
        stats = fpminfo.getStats()
        if self.hasGraph('php_fpm_connections') and stats: 
            self.setGraphVal('php_fpm_connections', 'conn', 
                             stats['accepted conn'])
        if self.hasGraph('php_fpm_processes') and stats: 
            self.setGraphVal('php_fpm_processes', 'active', 
                             stats['active processes'])
            self.setGraphVal('php_fpm_processes', 'idle', 
                             stats['idle processes'])
            self.setGraphVal('php_fpm_processes', 'total', 
                             stats['total processes'])
372197
def _GetStat(self):
    
    stat_object = super(TARFileEntry, self)._GetStat()

    # File data stat information.
    stat_object.size = getattr(self._tar_info, 'size', None)

    # Ownership and permissions stat information.
    stat_object.mode = getattr(self._tar_info, 'mode', None)
    stat_object.uid = getattr(self._tar_info, 'uid', None)
    stat_object.gid = getattr(self._tar_info, 'gid', None)

    # TODO: implement support for:
    # stat_object.uname = getattr(self._tar_info, 'uname', None)
    # stat_object.gname = getattr(self._tar_info, 'gname', None)

    # File entry type stat information.

    # The root file entry is virtual and should have type directory.

    # TODO: determine if this covers all the types:
    # REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE,
    # CHRTYPE, BLKTYPE, GNUTYPE_SPARSE

    # Other stat information.
    # tar_info.pax_headers

    return stat_object
370456
def stats(self):
        """"""
        assert self.backend.LOAD_count >= 0, "LOAD_count < 0"
        assert self.backend.LOAD_byte >= 0, "LOAD_byte < 0"
        assert self.backend.STORE_count >= 0, "STORE_count < 0"
        assert self.backend.STORE_byte >= 0, "STORE_byte < 0"
        assert self.backend.HIT_count >= 0, "HIT_count < 0"
        assert self.backend.HIT_byte >= 0, "HIT_byte < 0"
        assert self.backend.MISS_count >= 0, "MISS_count < 0"
        assert self.backend.MISS_byte >= 0, "MISS_byte < 0"
        assert self.backend.EVICT_count >= 0, "EVICT_count < 0"
        assert self.backend.EVICT_byte >= 0, "EVICT_byte < 0"
        return {'name': self.name,
                'LOAD_count': self.backend.LOAD_count,
                'LOAD_byte': self.backend.LOAD_byte,
                'STORE_count': self.backend.STORE_count,
                'STORE_byte': self.backend.STORE_byte,
                'HIT_count': self.backend.HIT_count,
                'HIT_byte': self.backend.HIT_byte,
                'MISS_count': self.backend.MISS_count,
                'MISS_byte': self.backend.MISS_byte,
                'EVICT_count': self.backend.EVICT_count,
                'EVICT_byte': self.backend.EVICT_byte}
2955
function Stats(dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atim_msec, mtim_msec, ctim_msec, birthtim_msec, path) {
        /* jshint maxparams: 4 */
        if (arguments.length === 1 && typeof arguments[0] === 'object') {
            return Stats.create(arguments[0]);
        }
        if (!Stats.is(this)) {
            return new Stats(dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atim_msec, mtim_msec, ctim_msec,
                birthtim_msec, path);
        }

        var entry = path;
        this.getEntry = function () {
            return entry;
        };

        /* ID of device containing file */
        this.dev = dev;
        /* inode number */
        this.mode = mode;
        /* protection */
        this.nlink = nlink;
        /* number of hard links */
        this.uid = uid;
        /* user ID of owner */
        this.gid = gid;
        /* group ID of owner */
        this.rdev = rdev;
        /* device ID (if special file) */
        this.blksize = blksize;
        /* total size, in bytes */
        this.ino = ino;
        /* blocksize for file system I/O */
        this.size = size;
        /* number of 512B blocks allocated */
        this.blocks = blocks;
        /* time of last access */
        this.atime = new Date(atim_msec);
        /* time of last modification */
        this.mtime = new Date(mtim_msec);
        /* time of last status change */
        this.ctime = new Date(ctim_msec);
        this.birthtime = new Date(birthtim_msec);
    }
1279610
def retrieveVals(self):
        """"""
        file_stats = self._fileInfo.getContainerStats()
        for contname in self._fileContList:
            stats = file_stats.get(contname)
            if stats is not None:
                if self.hasGraph('rackspace_cloudfiles_container_size'):
                    self.setGraphVal('rackspace_cloudfiles_container_size', contname,
                                     stats.get('size'))
                if self.hasGraph('rackspace_cloudfiles_container_count'):
                    self.setGraphVal('rackspace_cloudfiles_container_count', contname,
                                     stats.get('count'))
921680
def get_stats(self):
        
        stats = {}
        for name, cls in self.stats.items():
            path = self.paths[name]
            if os.path.exists(path):
                try:
                    stats[name] = self._PARSERS[cls](fileops.read(path))
                except IOError as e:
                    # XXX: we have to distinguish unexpected errors from the expected ones
                    if e.errno == errno.EOPNOTSUPP:
                        # Since 3.5 memory.memsw.* are always created even if disabled.
                        # If disabled we will get EOPNOTSUPP when read or write them.
                        # See commit af36f906c0f4c2ffa0482ecdf856a33dc88ae8c5 of the kernel.
                        pass
                    if e.errno == errno.EIO:
                        # memory.kmem.slabinfo throws EIO until limit_in_bytes is set.
                        pass
                    else:
                        raise
        return stats
641600
def _iostat_fbsd(interval, count, disks):
    '''
    
    '''
    if disks is None:
        iostat_cmd = 'iostat -xC -w {0} -c {1} '.format(interval, count)
    elif isinstance(disks, six.string_types):
        iostat_cmd = 'iostat -x -w {0} -c {1} {2}'.format(interval, count, disks)
    else:
        iostat_cmd = 'iostat -x -w {0} -c {1} {2}'.format(interval, count, ' '.join(disks))

    sys_stats = []
    dev_stats = collections.defaultdict(list)
    sys_header = []
    dev_header = []
    h_len = 1000  # randomly absurdly high

    ret = iter(__salt__['cmd.run_stdout'](iostat_cmd, output_loglevel='quiet').splitlines())
    for line in ret:
        if not line.startswith('device'):
            continue
        elif not dev_header:
            dev_header = line.split()[1:]
        while line is not False:
            line = next(ret, False)
            if not line or not line[0].isalnum():
                break
            line = line.split()
            disk = line[0]
            stats = [decimal.Decimal(x) for x in line[1:]]
            # h_len will become smallest number of fields in stat lines
            if len(stats) < h_len:
                h_len = len(stats)
            dev_stats[disk].append(stats)

    iostats = {}

    # The header was longer than the smallest number of fields
    # Therefore the sys stats are hidden in there
    if h_len < len(dev_header):
        sys_header = dev_header[h_len:]
        dev_header = dev_header[0:h_len]

        for disk, stats in dev_stats.items():
            if len(stats[0]) > h_len:
                sys_stats = [stat[h_len:] for stat in stats]
                dev_stats[disk] = [stat[0:h_len] for stat in stats]

        iostats['sys'] = _iostats_dict(sys_header, sys_stats)

    for disk, stats in dev_stats.items():
        iostats[disk] = _iostats_dict(dev_header, stats)

    return iostats
549889
def _GetStat(self):
    
    stat_object = vfs_stat.VFSStat()

    # File data stat information.
    stat_object.size = self.path_spec.range_size

    # File entry type stat information.
    stat_object.type = stat_object.TYPE_FILE

    return stat_object
183456
private void gatherMetatypeFilesAndStats() throws IOException, JAXBException {
        for (File bundle : directory.listFiles()) {
            if (bundle.isFile()) {
                analyzeBundle(bundle);
            }
        }
    }
954843
private void collectPoolInfoMetrics() {
    Map<PoolInfo, PoolInfoMetrics> newPoolNameToMetrics = new HashMap<PoolInfo,
      PoolInfoMetrics>();
    long now = ClusterManager.clock.getTime();

    Map<PoolInfo, Long> poolInfoAverageFirstWaitMs =
        sessionManager.getTypePoolInfoAveFirstWaitMs(type);

    // The gets + puts below are OK because only one thread is doing it.
    for (PoolGroupSchedulable poolGroup : poolGroupManager.getPoolGroups()) {
      int poolGroupSessions = 0;
      for (PoolSchedulable pool : poolGroup.getPools()) {
        MetricsRecord poolRecord =
            poolInfoToMetricsRecord.get(pool.getPoolInfo());
        if (poolRecord == null) {
          poolRecord = metrics.getContext().createRecord(
              "pool-" + pool.getName());
          poolInfoToMetricsRecord.put(pool.getPoolInfo(), poolRecord);
        }

        PoolInfoMetrics poolMetrics = new PoolInfoMetrics(pool.getPoolInfo(),
            type, poolRecord);
        poolMetrics.setCounter(
            MetricName.GRANTED, pool.getGranted());
        poolMetrics.setCounter(
            MetricName.REQUESTED, pool.getRequested());
        poolMetrics.setCounter(
            MetricName.SHARE, (long) pool.getShare());
        poolMetrics.setCounter(
            MetricName.MIN, pool.getMinimum());
        poolMetrics.setCounter(
            MetricName.MAX, pool.getMaximum());
        poolMetrics.setCounter(
            MetricName.WEIGHT, (long) pool.getWeight());
        poolMetrics.setCounter(
            MetricName.SESSIONS, pool.getScheduleQueue().size());
        poolMetrics.setCounter(
            MetricName.STARVING, pool.getStarvingTime(now) / 1000);
        Long averageFirstTypeMs =
            poolInfoAverageFirstWaitMs.get(pool.getPoolInfo());
        poolMetrics.setCounter(MetricName.AVE_FIRST_WAIT_MS,
            (averageFirstTypeMs == null) ?
                0 : averageFirstTypeMs.longValue());

        newPoolNameToMetrics.put(pool.getPoolInfo(), poolMetrics);
        poolGroupSessions += pool.getScheduleQueue().size();
      }

      MetricsRecord poolGroupRecord =
          poolInfoToMetricsRecord.get(poolGroup.getName());
      if (poolGroupRecord == null) {
        poolGroupRecord = metrics.getContext().createRecord(
            "poolgroup-" + poolGroup.getName());
        poolInfoToMetricsRecord.put(poolGroup.getPoolInfo(), poolGroupRecord);
      }

      PoolInfoMetrics poolGroupMetrics =
          new PoolInfoMetrics(poolGroup.getPoolInfo(), type, poolGroupRecord);
      poolGroupMetrics.setCounter(
          MetricName.GRANTED, poolGroup.getGranted());
      poolGroupMetrics.setCounter(
          MetricName.REQUESTED, poolGroup.getRequested());
      poolGroupMetrics.setCounter(
          MetricName.SHARE, (long) poolGroup.getShare());
      poolGroupMetrics.setCounter(
          MetricName.MIN, poolGroup.getMinimum());
      poolGroupMetrics.setCounter(
          MetricName.MAX, poolGroup.getMaximum());
      poolGroupMetrics.setCounter(
          MetricName.SESSIONS, poolGroupSessions);
      newPoolNameToMetrics.put(poolGroup.getPoolInfo(), poolGroupMetrics);
    }

    poolInfoToMetrics = newPoolNameToMetrics;
  }