Example #1
0
    def collect(self):
        pgs = self.pagesize()
        #
        # Start off with a few simple, system-wide things
        #
        kpg = sh.get_kstat('unix:0:system_pages:pp_kernel', single_val=True)

        self.publish('kernel', int(kpg) * pgs)

        self.publish('arc_size',
                     sh.get_kstat('zfs:0:arcstats:size', single_val=True))

        self.publish(
            'pages.free',
            sh.get_kstat('unix:0:system_pages:pagesfree', single_val=True))

        if (self.config['swap_fields']
                and self.config['swap_fields'] != '__none__'):
            self.collect_swap_cmd()

        if (self.config['vminfo_fields']
                and self.config['vminfo_fields'] != '__none__'):
            self.collect_vminfo(pgs)

        ks = sh.get_kstat('cpu::vm')
        self.collect_in_and_out(ks, 'pg', 'paging')
        self.collect_in_and_out(ks, 'swap', 'swapping')
    def collect(self):
        pgs = self.pagesize()
        #
        # Start off with a few simple, system-wide things
        #
        kpg = sh.get_kstat('unix:0:system_pages:pp_kernel', single_val=True)

        self.publish('kernel', int(kpg) * pgs)

        self.publish('arc_size', sh.get_kstat('zfs:0:arcstats:size',
                     single_val=True))

        self.publish('pages.free',
                     sh.get_kstat('unix:0:system_pages:pagesfree',
                                  single_val=True))

        if (self.config['swap_fields'] and self.config['swap_fields'] !=
                '__none__'):
            self.collect_swap_cmd()

        if (self.config['vminfo_fields'] and
                self.config['vminfo_fields'] != '__none__'):
            self.collect_vminfo(pgs)

        ks = sh.get_kstat('cpu::vm')
        self.collect_in_and_out(ks, 'pg', 'paging')
        self.collect_in_and_out(ks, 'swap', 'swapping')
    def collect(self):
        zid = self.zid()

        # My thinking right now is to send everything in the following
        # modules as if it were a gauge: i.e. no derived values. THIS
        # MAY CHANGE!

        for kstat in ('swapresv', 'lockedmem', 'nprocs', 'cpucaps',
                      'physicalmem', 'memcap'):
            for k, v in sh.get_kstat('caps:%d:%s_zone_%d' % (zid,
                                     kstat, zid), no_times=False,
                                     terse=True).items():
                if k == 'snaptime':
                    continue

                if k == 'value' and v > maxint * 2:
                    continue

                self.publish('%s.%s' % (kstat, k), v)

        # I think nearly everything in the memory_cap kstat module
        # should be considered a rate. Only `rss` and `swap` appear
        # to be genuine gauges (i.e. they go down as well as up.) It's
        # probably useful to have `nover` as a gauge too though: it
        # maybe useful to know how many times you've been "over the
        # limit".

        memcap_no_deriv = ('rss', 'swap', 'nover')

        memcap = sh.get_kstat('memory_cap', no_times=False, terse=True)
        snaptime = long(memcap['snaptime'])
        del memcap['snaptime']

        for stat in memcap_no_deriv:
            self.publish('memory_cap.%s' % stat, memcap[stat])
            del memcap[stat]

        if 'memcap_snaptime' in self.last_values:
            snaptime_delta = snaptime - self.last_values['memcap_snaptime']

            for k, v in memcap.items():
                self.publish('memory_cap.%s' % k,
                             self.derivative(k, v,
                                             time_delta=snaptime_delta))

        self.last_values['memcap_snaptime'] = snaptime
Example #4
0
    def collect(self):
        zid = self.zid()

        # My thinking right now is to send everything in the following
        # modules as if it were a gauge: i.e. no derived values. THIS
        # MAY CHANGE!

        for kstat in ('swapresv', 'lockedmem', 'nprocs', 'cpucaps',
                      'physicalmem', 'memcap'):
            for k, v in sh.get_kstat('caps:%d:%s_zone_%d' % (zid, kstat, zid),
                                     no_times=False,
                                     terse=True).items():
                if k == 'snaptime':
                    continue

                if k == 'value' and v > maxint * 2:
                    continue

                self.publish('%s.%s' % (kstat, k), v)

        # I think nearly everything in the memory_cap kstat module
        # should be considered a rate. Only `rss` and `swap` appear
        # to be genuine gauges (i.e. they go down as well as up.) It's
        # probably useful to have `nover` as a gauge too though: it
        # maybe useful to know how many times you've been "over the
        # limit".

        memcap_no_deriv = ('rss', 'swap', 'nover')

        memcap = sh.get_kstat('memory_cap', no_times=False, terse=True)
        snaptime = long(memcap['snaptime'])
        del memcap['snaptime']

        for stat in memcap_no_deriv:
            self.publish('memory_cap.%s' % stat, memcap[stat])
            del memcap[stat]

        if 'memcap_snaptime' in self.last_values:
            snaptime_delta = snaptime - self.last_values['memcap_snaptime']

            for k, v in memcap.items():
                self.publish('memory_cap.%s' % k,
                             self.derivative(k, v, time_delta=snaptime_delta))

        self.last_values['memcap_snaptime'] = snaptime
    def collect(self):
        cpu_t = sh.get_kstat('cpu::sys')
        per_cpu = self.split_stats(cpu_t)

        num_cpus = self.vcpus()

        if sh.wanted('vcpus', self.config['fields']):
            self.publish('global.vcpus', num_cpus)

        if sh.wanted('speed', self.config['fields']):
            self.publish('global.clock_speed', self.clock_speed())

            for n in range(0, num_cpus):
                self.publish('%d.cpuinfo.current_speed' % n,
                        self.cpu_stat('current_clock_Hz', n))

        if sh.wanted('state', self.config['fields']):
            for n in range(0, num_cpus):
                states = sh.get_kstat(
                    'cpu_info:%d:cpu_info%d' % (n, n), terse=True)

                for s in ('cstate', 'pstate'):
                    self.publish('%d.cpuinfo.current_%s' % (n, s),
                        float(states['current_%s' % s]))

        # If we want rate metrics, call the method which does that,
        # and remove the things it uses from the kstat list. This
        # needs to be done for each CPU.

        if self.config['as_pc_delta'] or self.config['as_nsec_delta']:

            for cpu, k in per_cpu.items():
                self.ns_and_pc(cpu, k)

                per_cpu[cpu] = {k: per_cpu[cpu][k] for k in
                                per_cpu[cpu] if not
                                k.startswith('cpu_nsec')}

        for cpu, kstats in per_cpu.items():
            kstats.pop('snaptime', None)
            kstats.pop('crtime', None)

            for k, v in kstats.items():
                if sh.wanted(k, self.config['fields']):
                    self.publish('%d.sys.%s' % (cpu, k), v)
    def cpu_stat(self, name, cpu):
        """
        Returns only the value for a given cpu_info kstat
        """

        speed = sh.get_kstat(
                'cpu_info:%d:cpu_info%d:%s' % (cpu, cpu, name),
                terse=True)

        return float(speed[name.lower()])
    def clock_speed(self):
        """
        This works for all the Intel processors I can access. I
        imagine it won't work for AMD, and possibly for other Intel
        models. This seems better than parsing prstat(1).
        """
        speeds = sh.get_kstat(
                'cpu_info:0:cpu_info0:supported_frequencies_Hz',
                terse=True, only_num=False)

        return float(speeds['supported_frequencies_hz'].
                rstrip('\x00').split(':')[-1])
Example #8
0
    def collect_vminfo(self, pgs):
        """
        Collect and present metrics from the 'vminfo' kstat. These
        are in pages, and they need to be converted into rates.

        :param pgs: the system page size. (int)
        """

        for k, v in sh.get_kstat('unix:0:vminfo', terse=True,
                                 no_times=True).items():
            if sh.wanted(k, self.config['vminfo_fields']):
                self.publish('vminfo.%s' % k, self.derivative(k, v) * pgs)
    def collect_vminfo(self, pgs):
        """
        Collect and present metrics from the 'vminfo' kstat. These
        are in pages, and they need to be converted into rates.

        :param pgs: the system page size. (int)
        """

        for k, v in sh.get_kstat('unix:0:vminfo', terse=True,
                                 no_times=True).items():
            if sh.wanted(k, self.config['vminfo_fields']):
                self.publish('vminfo.%s' % k, self.derivative(k, v) * pgs)
Example #10
0
    def disk_tags(self):
        """
        Wavefront gives us the ability to tag points. If the user
        wishes, we will tag each point with the model name and serial
        number of the disk, producing more meaningful alerts
        """

        ret = {}

        for k, v in sh.get_kstat(':::', ks_class='device_error',
                                 only_num=False,
                                 statlist=self.config['sn_fields']).items():
            dev, stat = self.get_devs(k)

            if dev not in ret:
                ret[dev] = {}

            ret[dev][stat] = v.strip()

        return ret
 def kstats(self):
     return sh.get_kstat('smbsrv:0:smb2_commands',
                         terse=True,
                         no_times=True)
    def test_get_kstat(self):
        self.assertEqual(sh.get_kstat('nosuch:0:kstat:name'), {})
        self.assertEqual(sh.get_kstat('nosuch:0::name'), {})
        self.assertEqual(sh.get_kstat('nosuch:::name'), {})
        self.assertEqual(sh.get_kstat('nosuch:0:kstat'), {})
        self.assertEqual(sh.get_kstat('nosuch:0'), {})
        self.assertEqual(sh.get_kstat('nosuch'), {})

        self.assertIsInstance(sh.get_kstat('cpu:0:sys:canch',
                                           single_val=True), long)

        self.assertEqual(len(sh.get_kstat('cpu::vm:pgin')),
                         len(sh.run_cmd('/usr/sbin/psrinfo')))
        self.assertEqual(len(sh.get_kstat('cpu:0:vm:pgin')), 1)
        self.assertEqual(sh.get_kstat('cpu:0:vm:pgin', ks_class='disk'), {})

        res = sh.get_kstat('cpu:0:vm')
        self.assertIsInstance(res, dict)

        self.assertIn('cpu:0:vm:execpgin', res.keys())
        self.assertIn('cpu:0:vm:crtime', res.keys())

        self.assertNotIn('cpu:0:vm:crtime', sh.get_kstat('cpu:0:vm',
                         no_times=True))

        self.assertNotIn('cpu:0:vm:crtime', sh.get_kstat('cpu:0:vm',
                         no_times=True))

        self.assertNotIn('cpu_info:0:cpu_info0:brand',
                         sh.get_kstat('cpu_info:0:cpu_info0').keys())

        self.assertIn('cpu_info:0:cpu_info0:brand',
                      sh.get_kstat('cpu_info:0:cpu_info0',
                                   only_num=False).keys())

        self.assertIn('brand',
                      sh.get_kstat('cpu_info:0:cpu_info0', only_num=False,
                                   terse=True).keys())

        self.assertNotIn('cpu_info:0:cpu_info0:brand',
                         sh.get_kstat('cpu_info:0:cpu_info0',
                                      only_num=False, terse=True).keys())

        self.assertNotRegexpMatches(''.join(sh.get_kstat('ip:0:icmp').
                                    keys()), '[A-Z]')

        self.assertEqual(sh.get_kstat(':::', ks_class='nosuch'), {})
        self.assertEqual(sh.get_kstat('cpu:0:vm', ks_class='disk'), {})

        self.assertIn('ilb:0:global:snaptime', sh.get_kstat(':::',
                      ks_class='kstat'))

        self.assertNotIn('ilb:0:global:snaptime', sh.get_kstat(':::',
                         ks_class='kstat', no_times=True))

        self.assertEqual(sh.get_kstat('cpu_info:0:cpu_info0',
                         only_num=False, statlist=['nosuch']), {})

        res = sh.get_kstat('cpu_info:0:cpu_info0', only_num=False,
                           terse=True, statlist=('state', 'core_id'))

        self.assertEqual(len(res), 2)
        self.assertItemsEqual(res.keys(), ['state', 'core_id'])

        self.assertIn('core_id', sh.get_kstat('cpu_info:0:cpu_info0',
                      statlist='__all__', terse=True))
Example #13
0
    def test_get_kstat(self):
        self.assertEqual(sh.get_kstat('nosuch:0:kstat:name'), {})
        self.assertEqual(sh.get_kstat('nosuch:0::name'), {})
        self.assertEqual(sh.get_kstat('nosuch:::name'), {})
        self.assertEqual(sh.get_kstat('nosuch:0:kstat'), {})
        self.assertEqual(sh.get_kstat('nosuch:0'), {})
        self.assertEqual(sh.get_kstat('nosuch'), {})

        self.assertIsInstance(sh.get_kstat('cpu:0:sys:canch', single_val=True),
                              long)

        self.assertEqual(len(sh.get_kstat('cpu::vm:pgin')),
                         len(sh.run_cmd('/usr/sbin/psrinfo')))
        self.assertEqual(len(sh.get_kstat('cpu:0:vm:pgin')), 1)
        self.assertEqual(sh.get_kstat('cpu:0:vm:pgin', ks_class='disk'), {})

        res = sh.get_kstat('cpu:0:vm')
        self.assertIsInstance(res, dict)

        self.assertIn('cpu:0:vm:execpgin', res.keys())
        self.assertIn('cpu:0:vm:crtime', res.keys())

        self.assertNotIn('cpu:0:vm:crtime',
                         sh.get_kstat('cpu:0:vm', no_times=True))

        self.assertNotIn('cpu:0:vm:crtime',
                         sh.get_kstat('cpu:0:vm', no_times=True))

        self.assertNotIn('cpu_info:0:cpu_info0:brand',
                         sh.get_kstat('cpu_info:0:cpu_info0').keys())

        self.assertIn(
            'cpu_info:0:cpu_info0:brand',
            sh.get_kstat('cpu_info:0:cpu_info0', only_num=False).keys())

        self.assertIn(
            'brand',
            sh.get_kstat('cpu_info:0:cpu_info0', only_num=False,
                         terse=True).keys())

        self.assertNotIn(
            'cpu_info:0:cpu_info0:brand',
            sh.get_kstat('cpu_info:0:cpu_info0', only_num=False,
                         terse=True).keys())

        self.assertNotRegexpMatches(''.join(sh.get_kstat('ip:0:icmp').keys()),
                                    '[A-Z]')

        self.assertEqual(sh.get_kstat(':::', ks_class='nosuch'), {})
        self.assertEqual(sh.get_kstat('cpu:0:vm', ks_class='disk'), {})

        self.assertIn('ilb:0:global:snaptime',
                      sh.get_kstat(':::', ks_class='kstat'))

        self.assertNotIn('ilb:0:global:snaptime',
                         sh.get_kstat(':::', ks_class='kstat', no_times=True))

        self.assertEqual(
            sh.get_kstat('cpu_info:0:cpu_info0',
                         only_num=False,
                         statlist=['nosuch']), {})

        res = sh.get_kstat('cpu_info:0:cpu_info0',
                           only_num=False,
                           terse=True,
                           statlist=('state', 'core_id'))

        self.assertEqual(len(res), 2)
        self.assertItemsEqual(res.keys(), ['state', 'core_id'])

        self.assertIn(
            'core_id',
            sh.get_kstat('cpu_info:0:cpu_info0',
                         statlist='__all__',
                         terse=True))
 def kstats(self):
     return sh.get_kstat(':::', ks_class='disk', no_times=True,
                         statlist=self.config['fields'])
 def kstats(self):
     return sh.get_kstat('smbsrv:0:smb2_commands', terse=True,
                         no_times=True)
Example #16
0
 def kstats(self, group):
     return sh.get_kstat('zfs:0:%s' % group,
                         terse=True,
                         no_times=True,
                         statlist=self.config[group])
Example #17
0
 def kstats(self):
     return sh.get_kstat(':::', no_times=True, ks_class='device_error')
 def kstats(self, nfs_ver):
     return sh.get_kstat('nfs:0:rfsproccnt_v%s' % nfs_ver, terse=True,
                         no_times=True, statlist=self.config['fields'])
 def kstats(self, nfs_ver):
     return sh.get_kstat('nfs:0:rfsproccnt_v%s' % nfs_ver,
                         terse=True,
                         no_times=True,
                         statlist=self.config['fields'])
 def kstats(self):
     return sh.get_kstat(':::',
                         ks_class='disk',
                         no_times=True,
                         statlist=self.config['fields'])
Example #21
0
 def kstats(self, group):
     return sh.get_kstat('zfs:0:%s' % group, terse=True,
                         no_times=True, statlist=self.config[group])
 def kstats(self, zid):
     return sh.get_kstat('caps:%s' % zid, no_times=True)