Ejemplo n.º 1
0
    def collect(self):
        labels = disk.get_disk_labels()
        for key, info in disk.get_file_systems().iteritems():
            if labels.has_key(info.device):
                name = labels[info.device]
            else:
                name = info.mount_point.replace('/', '_')
                name = 'root' if name == '_' else name

            data = os.statvfs(info.mount_point)
            block_size = data.f_bsize

            blocks_total, blocks_free, blocks_avail = data.f_blocks, data.f_bfree, data.f_bavail
            inodes_total, inodes_free, inodes_avail = data.f_files, data.f_ffree, data.f_favail

            metric_name = '%s.%s_used' % (name, self.config['byte_unit'])
            metric_value = float(block_size) * float(blocks_total - blocks_free)
            metric_value = diamond.convertor.binary.convert(value = metric_value, oldUnit = 'byte', newUnit = self.config['byte_unit'])
            self.publish(metric_name, metric_value, 2)

            metric_name = '%s.%s_free' % (name, self.config['byte_unit'])
            metric_value = float(block_size) * float(blocks_free)
            metric_value = diamond.convertor.binary.convert(value = metric_value, oldUnit = 'byte', newUnit = self.config['byte_unit'])
            self.publish(metric_name, metric_value, 2)

            metric_name = '%s.%s_avail' % (name, self.config['byte_unit'])
            metric_value = float(block_size) * float(blocks_avail)
            metric_value = diamond.convertor.binary.convert(value = metric_value, oldUnit = 'byte', newUnit = self.config['byte_unit'])
            self.publish(metric_name, metric_value, 2)

            self.publish('%s.inodes_used'  % name, inodes_total - inodes_free)
            self.publish('%s.inodes_free'  % name, inodes_free)
            self.publish('%s.inodes_avail' % name, inodes_avail)
Ejemplo n.º 2
0
    def test_should_work_with_real_data(self, publish_mock):
        statvfs_mock = Mock()
        statvfs_mock.f_bsize = 4096
        statvfs_mock.f_frsize = 4096
        statvfs_mock.f_blocks = 360540255
        statvfs_mock.f_bfree = 285953527
        statvfs_mock.f_bavail = 267639130
        statvfs_mock.f_files = 91578368
        statvfs_mock.f_ffree = 91229495
        statvfs_mock.f_favail = 91229495
        statvfs_mock.f_flag = 4096
        statvfs_mock.f_namemax = 255

        with nested(
                patch('os.stat'), patch('os.major', Mock(return_value=9)),
                patch('os.minor', Mock(return_value=0)),
                patch('__builtin__.open',
                      Mock(return_value=self.getFixture('proc_mounts')))):
            file_systems_mock = disk.get_file_systems()

        with nested(
                patch('disk.get_file_systems',
                      Mock(return_value=file_systems_mock)),
                patch('os.statvfs', Mock(return_value=statvfs_mock))):
            self.collector.collect()

        self.assertPublishedMany(
            publish_mock, {
                'root.gigabyte_used': (284.525, 2),
                'root.gigabyte_free': (1090.826, 2),
                'root.gigabyte_avail': (1020.962, 2),
                'root.inodes_used': 348873,
                'root.inodes_free': 91229495,
                'root.inodes_avail': 91229495
            })
Ejemplo n.º 3
0
    def test_should_work_with_real_data(self, publish_mock):
        statvfs_mock = Mock()
        statvfs_mock.f_bsize   = 4096
        statvfs_mock.f_frsize  = 4096
        statvfs_mock.f_blocks  = 360540255
        statvfs_mock.f_bfree   = 285953527
        statvfs_mock.f_bavail  = 267639130
        statvfs_mock.f_files   = 91578368
        statvfs_mock.f_ffree   = 91229495
        statvfs_mock.f_favail  = 91229495
        statvfs_mock.f_flag    = 4096
        statvfs_mock.f_namemax = 255

        with nested(
            patch('os.stat'),
            patch('os.major', return_value = 9),
            patch('os.minor', return_value = 0),
            patch('__builtin__.open', return_value = get_fixture('proc_mounts'))
        ):
            file_systems_mock = disk.get_file_systems()

        with nested(
            patch('disk.get_file_systems', return_value = file_systems_mock),
            patch('os.statvfs', return_value = statvfs_mock)
        ):
            self.collector.collect()

        self.assertPublishedMany(publish_mock, {
            'root.gbytes_used'  : ( 284.525, 2),
            'root.gbytes_free'  : (1090.826, 2),
            'root.gbytes_avail' : (1020.962, 2),
            'root.inodes_used'  : 348873,
            'root.inodes_free'  : 91229495,
            'root.inodes_avail' : 91229495
        })
Ejemplo n.º 4
0
    def collect(self):
        for key, info in disk.get_file_systems().iteritems():
            name = info.mount_point.replace('/', '_')
            name = 'root' if name == '_' else name

            data = os.statvfs(info.mount_point)
            block_size = data.f_bsize

            blocks_total, blocks_free, blocks_avail = data.f_blocks, data.f_bfree, data.f_bavail
            inodes_total, inodes_free, inodes_avail = data.f_files, data.f_ffree, data.f_favail

            metric_name = '%s.gbytes_used' % name
            metric_value = float(block_size) * float(blocks_total - blocks_free)
            metric_value = diamond.convertor.bytes_to_gbytes(metric_value)
            self.publish(metric_name, metric_value, 2)

            metric_name = '%s.gbytes_free' % name
            metric_value = float(block_size) * float(blocks_free)
            metric_value = diamond.convertor.bytes_to_gbytes(metric_value)
            self.publish(metric_name, metric_value, 2)

            metric_name = '%s.gbytes_avail' % name
            metric_value = float(block_size) * float(blocks_avail)
            metric_value = diamond.convertor.bytes_to_gbytes(metric_value)
            self.publish(metric_name, metric_value, 2)

            self.publish('%s.inodes_used'  % name, inodes_total - inodes_free)
            self.publish('%s.inodes_free'  % name, inodes_free)
            self.publish('%s.inodes_avail' % name, inodes_avail)
Ejemplo n.º 5
0
    def test_should_work_with_real_data(self, publish_mock):
        with nested(
            patch('os.stat'),
            patch('os.major', return_value = 9),
            patch('os.minor', return_value = 0),
            patch('__builtin__.open', return_value = get_fixture('proc_mounts'))
        ):
            file_systems = disk.get_file_systems()

        with patch('__builtin__.open', return_value = get_fixture('proc_diskstats_1')):
            disk_statistics_1 = disk.get_disk_statistics()

        with patch('__builtin__.open', return_value = get_fixture('proc_diskstats_2')):
            disk_statistics_2 = disk.get_disk_statistics()

        with nested(
            patch('disk.get_file_systems', return_value = file_systems),
            patch('disk.get_disk_statistics', return_value = disk_statistics_1)
        ):
            self.collector.collect()

        self.assertPublishedMany(publish_mock, {})

        with nested(
            patch('disk.get_file_systems', return_value = file_systems),
            patch('disk.get_disk_statistics', return_value = disk_statistics_2)
        ):
            self.collector.collect()

        self.assertPublishedMany(publish_mock, {
            'sda.reads' : 0.5,
            'sda.reads_merged' : 0.6,
            'sda.reads_kbytes' : 4.4,
            'sda.reads_milliseconds' : 4.0,
            'sda.writes' : 3.4,
            'sda.writes_merged' : 1.3,
            'sda.writes_kbytes' : 18.8,
            'sda.writes_milliseconds' : 10.0,
            'sda.io_milliseconds' : 9.0,
            'sda.io_milliseconds_weighted' : 14.0,
            'md0.reads' : 0.0,
            'md0.reads_merged' : 0.0,
            'md0.reads_kbytes' : 0.0,
            'md0.reads_milliseconds' : 0.0,
            'md0.writes' : 8.6,
            'md0.writes_merged' : 0.0,
            'md0.writes_kbytes' : 34.4,
            'md0.writes_milliseconds' : 0.0,
            'md0.io_milliseconds' : 0.0,
            'md0.io_milliseconds_weighted' : 0.0,
        })
Ejemplo n.º 6
0
    def test_get_file_systems(self, open_mock):
        result = None
        open_mock.return_value = StringIO("""
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,relatime,size=24769364k,nr_inodes=6192341,mode=755 0 0
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
/dev/disk/by-uuid/81969733-a724-4651-9cf5-64970f86daba / ext3 rw,relatime,errors=continue,barrier=0,data=ordered 0 0
none /sys/kernel/debug debugfs rw,relatime 0 0
none /sys/kernel/security securityfs rw,relatime 0 0
none /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
none /var/run tmpfs rw,nosuid,relatime,mode=755 0 0
none /var/lock tmpfs rw,nosuid,nodev,noexec,relatime 0 0
        """.strip())

        with nested(patch('os.stat'), patch('os.major'),
                    patch('os.minor')) as (os_stat_mock, os_major_mock,
                                           os_minor_mock):
            os_stat_mock.return_value.st_dev = 42
            os_major_mock.return_value = 9
            os_minor_mock.return_value = 0

            result = disk.get_file_systems()

            os_stat_mock.assert_called_once_with('/')
            os_major_mock.assert_called_once_with(42)
            os_minor_mock.assert_called_once_with(42)

            self.assertEqual(
                result, {
                    (9, 0):
                    ('/dev/disk/by-uuid/81969733-a724-4651-9cf5-64970f86daba',
                     '/')
                })

        open_mock.assert_called_once_with('/proc/mounts')
        return result
Ejemplo n.º 7
0
    def test_get_file_systems(self, open_mock):
        result = None
        open_mock.return_value = StringIO("""
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,relatime,size=24769364k,nr_inodes=6192341,mode=755 0 0
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
/dev/disk/by-uuid/81969733-a724-4651-9cf5-64970f86daba / ext3 rw,relatime,errors=continue,barrier=0,data=ordered 0 0
none /sys/kernel/debug debugfs rw,relatime 0 0
none /sys/kernel/security securityfs rw,relatime 0 0
none /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
none /var/run tmpfs rw,nosuid,relatime,mode=755 0 0
none /var/lock tmpfs rw,nosuid,nodev,noexec,relatime 0 0
        """.strip())

        with nested(
            patch('os.stat'), patch('os.major'), patch('os.minor')
        ) as (os_stat_mock, os_major_mock, os_minor_mock):
            os_stat_mock.return_value.st_dev = 42
            os_major_mock.return_value = 9
            os_minor_mock.return_value = 0

            result = disk.get_file_systems()

            os_stat_mock.assert_called_once_with('/')
            os_major_mock.assert_called_once_with(42)
            os_minor_mock.assert_called_once_with(42)

            self.assertEqual(result, {
                (9, 0) : ('/dev/disk/by-uuid/81969733-a724-4651-9cf5-64970f86daba', '/')
            })

        open_mock.assert_called_once_with('/proc/mounts')
        return result
Ejemplo n.º 8
0
    def test_should_work_with_real_data(self, publish_mock):
        with nested(
            patch('os.stat'),
            patch('os.major', Mock(return_value = 9)),
            patch('os.minor', Mock(return_value = 0)),
            patch('__builtin__.open', Mock(return_value = self.getFixture('proc_mounts')))
        ):
            file_systems = disk.get_file_systems()

        with patch('__builtin__.open', Mock(return_value = self.getFixture('proc_diskstats_1'))):
            disk_statistics_1 = disk.get_disk_statistics()

        with patch('__builtin__.open', Mock(return_value = self.getFixture('proc_diskstats_2'))):
            disk_statistics_2 = disk.get_disk_statistics()

        with nested(
            patch('disk.get_file_systems', Mock(return_value = file_systems)),
            patch('disk.get_disk_statistics', Mock(return_value = disk_statistics_1)),
            patch('time.time', Mock(return_value = 10))
        ):
            self.collector.collect()

        self.assertPublishedMany(publish_mock, {})

        with nested(
            patch('disk.get_file_systems', Mock(return_value = file_systems)),
            patch('disk.get_disk_statistics', Mock(return_value = disk_statistics_2)),
            patch('time.time', Mock(return_value = 20))
        ):
            self.collector.collect()

        self.assertPublishedMany(publish_mock, {
            'sda.average_queue_length':             0.0,
            'sda.average_request_size_kilobyte':    10.7,
            'sda.await':                            0.0,
            'sda.concurrent_io':                    0.0,
            'sda.io':                               0.3,
            'sda.io_in_progress':                   0.0,
            'sda.io_milliseconds':                  0.0,
            'sda.io_milliseconds_weighted':         0.0,
            'sda.iops':                             0.03,
            'sda.read_kilobyte_per_second':         0.0,
            'sda.read_requests_merged_per_second':  0.0,
            'sda.reads':                            0.0,
            'sda.reads_kilobyte':                   0.0,
            'sda.reads_merged':                     0.0,
            'sda.reads_milliseconds':               0.0,
            'sda.reads_per_second':                 0.0,
            'sda.service_time':                     0.0,
            'sda.util_percentage':                  0.0,
            'sda.write_kilobyte_per_second':        0.32,
            'sda.write_requests_merged_per_second': 0.05,
            'sda.writes':                           0.3,
            'sda.writes_kilobyte':                  3.2,
            'sda.writes_merged':                    0.5,
            'sda.writes_milliseconds':              0.0,
            'sda.writes_per_second':                0.03,
            'sdb.average_queue_length':             49570.0,
            'sdb.average_request_size_kilobyte':    6.3,

            'sdb.await':                            0.8,
            'sdb.concurrent_io':                    0.05,
            'sdb.io':                               921.4,
            'sdb.io_in_progress':                   0,
            'sdb.io_milliseconds':                  495.7,
            'sdb.io_milliseconds_weighted':         749.2,
            'sdb.iops':                             92.14,
            'sdb.read_kilobyte_per_second':         186.24,
            'sdb.read_requests_merged_per_second':  0.0,
            'sdb.reads':                            116.4,
            'sdb.reads_kilobyte':                   1862.4,
            'sdb.reads_merged':                     0.0,
            'sdb.reads_milliseconds':               716.3,
            'sdb.reads_per_second':                 11.64,
            'sdb.service_time':                     0.5,
            'sdb.util_percentage':                  49.57,
            'sdb.write_kilobyte_per_second':        391.43,
            'sdb.write_requests_merged_per_second': 20.17,
            'sdb.writes':                           805.0,
            'sdb.writes_kilobyte':                  3914.3,
            'sdb.writes_merged':                    201.7,
            'sdb.writes_milliseconds':              33.7,
            'sdb.writes_per_second':                80.5,
        })