Exemple #1
0
    def setUp(self):
        config = get_collector_config('MemcachedCollector', {
            'interval': 10,
            'hosts': ['localhost:11211'],
        })

        self.collector = MemcachedCollector(config, None)
Exemple #2
0
    def setUp(self):
        config = get_collector_config(
            'MemcachedCollector', {
                'interval': 10,
                'hosts': {
                    'localhost': {
                        'host': 'localhost',
                        'port': '11211',
                    },
                },
            })

        self.collector = MemcachedCollector(config, None)
    def setUp(self):
        config = get_collector_config('MemcachedCollector', {
            'interval': 10,
            'hosts': ['localhost:11211'],
        })

        self.collector = MemcachedCollector(config, None)
Exemple #4
0
    def setUp(self):
        config = get_collector_config('MemcachedCollector', {
            'interval': 10,
            'hosts':    {
                'localhost': {
                    'host':     'localhost',
                    'port':     '11211',
                },
            },
        })

        self.collector = MemcachedCollector(config, None)
Exemple #5
0
class TestMemcachedCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('MemcachedCollector', {
            'interval': 10,
            'hosts':    {
                'localhost': {
                    'host':     'localhost',
                    'port':     '11211',
                },
            },
        })

        self.collector = MemcachedCollector(config, None)

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        with patch.object(MemcachedCollector,
                          'get_raw_stats',
                          Mock(return_value=self.getFixture(
                              'stats').getvalue())):
            self.collector.collect()

        metrics = {
            'localhost.reclaimed': 0.000000,
            'localhost.expired_unfetched': 0.000000,
            'localhost.hash_is_expanding': 0.000000,
            'localhost.cas_hits': 0.000000,
            'localhost.uptime': 25763.000000,
            'localhost.touch_hits': 0.000000,
            'localhost.delete_misses': 0.000000,
            'localhost.listen_disabled_num': 0.000000,
            'localhost.cas_misses': 0.000000,
            'localhost.decr_hits': 0.000000,
            'localhost.cmd_touch': 0.000000,
            'localhost.incr_hits': 0.000000,
            'localhost.auth_cmds': 0.000000,
            'localhost.limit_maxbytes': 67108864.000000,
            'localhost.bytes_written': 0.000000,
            'localhost.incr_misses': 0.000000,
            'localhost.accepting_conns': 1.000000,
            'localhost.rusage_system': 0.195071,
            'localhost.total_items': 0.000000,
            'localhost.cmd_get': 0.000000,
            'localhost.curr_connections': 10.000000,
            'localhost.touch_misses': 0.000000,
            'localhost.threads': 4.000000,
            'localhost.total_connections': 11.000000,
            'localhost.cmd_set': 0.000000,
            'localhost.curr_items': 0.000000,
            'localhost.conn_yields': 0.000000,
            'localhost.get_misses': 0.000000,
            'localhost.reserved_fds': 20.000000,
            'localhost.bytes_read': 7.000000,
            'localhost.hash_bytes': 524288.000000,
            'localhost.evicted_unfetched': 0.000000,
            'localhost.cas_badval': 0.000000,
            'localhost.cmd_flush': 0.000000,
            'localhost.evictions': 0.000000,
            'localhost.bytes': 0.000000,
            'localhost.connection_structures': 11.000000,
            'localhost.hash_power_level': 16.000000,
            'localhost.auth_errors': 0.000000,
            'localhost.rusage_user': 0.231516,
            'localhost.delete_hits': 0.000000,
            'localhost.decr_misses': 0.000000,
            'localhost.get_hits': 0.000000,
        }

        self.setDocExample(self.collector.__class__.__name__, metrics)
        self.assertPublishedMany(publish_mock, metrics)
Exemple #6
0
class TestMemcachedCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config(
            'MemcachedCollector', {
                'interval': 10,
                'hosts': {
                    'localhost': {
                        'host': 'localhost',
                        'port': '11211',
                    },
                },
            })

        self.collector = MemcachedCollector(config, None)

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        with patch.object(
                MemcachedCollector, 'get_raw_stats',
                Mock(return_value=self.getFixture('stats').getvalue())):
            self.collector.collect()

        metrics = {
            'localhost.reclaimed': 0.000000,
            'localhost.expired_unfetched': 0.000000,
            'localhost.hash_is_expanding': 0.000000,
            'localhost.cas_hits': 0.000000,
            'localhost.uptime': 25763.000000,
            'localhost.touch_hits': 0.000000,
            'localhost.delete_misses': 0.000000,
            'localhost.listen_disabled_num': 0.000000,
            'localhost.cas_misses': 0.000000,
            'localhost.decr_hits': 0.000000,
            'localhost.cmd_touch': 0.000000,
            'localhost.incr_hits': 0.000000,
            'localhost.auth_cmds': 0.000000,
            'localhost.limit_maxbytes': 67108864.000000,
            'localhost.bytes_written': 0.000000,
            'localhost.incr_misses': 0.000000,
            'localhost.accepting_conns': 1.000000,
            'localhost.rusage_system': 0.195071,
            'localhost.total_items': 0.000000,
            'localhost.cmd_get': 0.000000,
            'localhost.curr_connections': 10.000000,
            'localhost.touch_misses': 0.000000,
            'localhost.threads': 4.000000,
            'localhost.total_connections': 11.000000,
            'localhost.cmd_set': 0.000000,
            'localhost.curr_items': 0.000000,
            'localhost.conn_yields': 0.000000,
            'localhost.get_misses': 0.000000,
            'localhost.reserved_fds': 20.000000,
            'localhost.bytes_read': 7.000000,
            'localhost.hash_bytes': 524288.000000,
            'localhost.evicted_unfetched': 0.000000,
            'localhost.cas_badval': 0.000000,
            'localhost.cmd_flush': 0.000000,
            'localhost.evictions': 0.000000,
            'localhost.bytes': 0.000000,
            'localhost.connection_structures': 11.000000,
            'localhost.hash_power_level': 16.000000,
            'localhost.auth_errors': 0.000000,
            'localhost.rusage_user': 0.231516,
            'localhost.delete_hits': 0.000000,
            'localhost.decr_misses': 0.000000,
            'localhost.get_hits': 0.000000,
        }

        self.setDocExample(self.collector.__class__.__name__, metrics)
        self.assertPublishedMany(publish_mock, metrics)
Exemple #7
0
class TestMemcachedCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('MemcachedCollector', {
            'interval': 10,
            'hosts': ['localhost:11211'],
        })

        self.collector = MemcachedCollector(config, None)

    def test_import(self):
        self.assertTrue(MemcachedCollector)

    @patch('socket.socket')
    def test_get_raw_stats_works_across_packet_boundaries(self, socket_mock):
        socket_instance = MagicMock()
        socket_mock.return_value = socket_instance
        stats_packets = ['stat foo 1\r\n', 'END\r\n']
        socket_instance.recv.side_effect = stats_packets
        stats = self.collector.get_raw_stats('', None)
        self.assertEqual(stats, ''.join(stats_packets))

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        patch_raw_stats = patch.object(
            MemcachedCollector, 'get_raw_stats',
            Mock(return_value=self.getFixture('stats').getvalue()))

        patch_raw_stats.start()
        self.collector.collect()
        patch_raw_stats.stop()

        metrics = {
            'localhost.reclaimed': 0.000000,
            'localhost.expired_unfetched': 0.000000,
            'localhost.hash_is_expanding': 0.000000,
            'localhost.cas_hits': 0.000000,
            'localhost.uptime': 25763,
            'localhost.touch_hits': 0.000000,
            'localhost.delete_misses': 0.000000,
            'localhost.listen_disabled_num': 0.000000,
            'localhost.cas_misses': 0.000000,
            'localhost.decr_hits': 0.000000,
            'localhost.cmd_touch': 0.000000,
            'localhost.incr_hits': 0.000000,
            'localhost.auth_cmds': 0.000000,
            'localhost.limit_maxbytes': 67108864.000000,
            'localhost.bytes_written': 0.000000,
            'localhost.incr_misses': 0.000000,
            'localhost.rusage_system': 0.195071,
            'localhost.total_items': 0.000000,
            'localhost.cmd_get': 0.000000,
            'localhost.curr_connections': 10.000000,
            'localhost.touch_misses': 0.000000,
            'localhost.threads': 4.000000,
            'localhost.total_connections': 0,
            'localhost.cmd_set': 0.000000,
            'localhost.curr_items': 0.000000,
            'localhost.conn_yields': 0.000000,
            'localhost.get_misses': 0.000000,
            'localhost.reserved_fds': 20.000000,
            'localhost.bytes_read': 0,
            'localhost.hash_bytes': 524288.000000,
            'localhost.evicted_unfetched': 0.000000,
            'localhost.cas_badval': 0.000000,
            'localhost.cmd_flush': 0.000000,
            'localhost.evictions': 0.000000,
            'localhost.bytes': 0.000000,
            'localhost.connection_structures': 11.000000,
            'localhost.hash_power_level': 16.000000,
            'localhost.auth_errors': 0.000000,
            'localhost.rusage_user': 0.231516,
            'localhost.delete_hits': 0.000000,
            'localhost.decr_misses': 0.000000,
            'localhost.get_hits': 0.000000,
            'localhost.repcached_qi_free': 0.000000,
        }

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)
Exemple #8
0
class TestMemcachedCollector(CollectorTestCase):

    def setUp(self):
        config = get_collector_config('MemcachedCollector', {
            'interval': 10,
            'hosts': ['localhost:11211'],
        })

        self.collector = MemcachedCollector(config, None)

    def test_import(self):
        self.assertTrue(MemcachedCollector)

    @patch('socket.socket')
    def test_get_raw_stats_works_across_packet_boundaries(self, socket_mock):
        socket_instance = MagicMock()
        socket_mock.return_value = socket_instance
        stats_packets = ['stat foo 1\r\n', 'END\r\n']
        socket_instance.recv.side_effect = stats_packets
        stats = self.collector.get_raw_stats('', None)
        self.assertEqual(stats, ''.join(stats_packets))

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        patch_raw_stats = patch.object(
            MemcachedCollector,
            'get_raw_stats',
            Mock(return_value=self.getFixture(
                'stats').getvalue()))

        patch_raw_stats.start()
        self.collector.collect()
        patch_raw_stats.stop()

        metrics = {
            'localhost.reclaimed': 0.000000,
            'localhost.expired_unfetched': 0.000000,
            'localhost.hash_is_expanding': 0.000000,
            'localhost.cas_hits': 0.000000,
            'localhost.uptime': 25763,
            'localhost.touch_hits': 0.000000,
            'localhost.delete_misses': 0.000000,
            'localhost.listen_disabled_num': 0.000000,
            'localhost.cas_misses': 0.000000,
            'localhost.decr_hits': 0.000000,
            'localhost.cmd_touch': 0.000000,
            'localhost.incr_hits': 0.000000,
            'localhost.auth_cmds': 0.000000,
            'localhost.limit_maxbytes': 67108864.000000,
            'localhost.bytes_written': 0.000000,
            'localhost.incr_misses': 0.000000,
            'localhost.rusage_system': 0.195071,
            'localhost.total_items': 0.000000,
            'localhost.cmd_get': 0.000000,
            'localhost.curr_connections': 10.000000,
            'localhost.touch_misses': 0.000000,
            'localhost.threads': 4.000000,
            'localhost.total_connections': 0,
            'localhost.cmd_set': 0.000000,
            'localhost.curr_items': 0.000000,
            'localhost.conn_yields': 0.000000,
            'localhost.get_misses': 0.000000,
            'localhost.reserved_fds': 20.000000,
            'localhost.bytes_read': 0,
            'localhost.hash_bytes': 524288.000000,
            'localhost.evicted_unfetched': 0.000000,
            'localhost.cas_badval': 0.000000,
            'localhost.cmd_flush': 0.000000,
            'localhost.evictions': 0.000000,
            'localhost.bytes': 0.000000,
            'localhost.connection_structures': 11.000000,
            'localhost.hash_power_level': 16.000000,
            'localhost.auth_errors': 0.000000,
            'localhost.rusage_user': 0.231516,
            'localhost.delete_hits': 0.000000,
            'localhost.decr_misses': 0.000000,
            'localhost.get_hits': 0.000000,
            'localhost.repcached_qi_free': 0.000000,
        }

        self.setDocExample(collector=self.collector.__class__.__name__,
                           metrics=metrics,
                           defaultpath=self.collector.config['path'])
        self.assertPublishedMany(publish_mock, metrics)