Beispiel #1
0
    def test_instance_names(self, publish, _get_stats_by_database):
        def side_effect(host, port, user, password):
            if (host, port) == ('127.0.0.1', '6432'):
                return {'foo': {'bar': 42}}
            elif (host, port) == ('localhost', '6433'):
                return {'foo': {'baz': 24}}

        _get_stats_by_database.side_effect = side_effect

        config = get_collector_config(
            'PgbouncerCollector', {
                'instances': {
                    'alpha': {
                        'host': '127.0.0.1',
                        'port': '6432',
                    },
                    'beta': {
                        'host': 'localhost',
                        'port': '6433',
                    },
                }
            })
        collector = PgbouncerCollector(config, None)
        collector.collect()

        self.assertPublished(publish, 'alpha.foo.bar', 42)
        self.assertPublished(publish, 'beta.foo.baz', 24)
Beispiel #2
0
    def test_override_user_password(self, _get_stats_by_database):
        _get_stats_by_database.return_value = {}

        config = get_collector_config(
            'PgbouncerCollector', {
                'instances': {
                    'test1': {
                        'host': '127.0.0.1',
                        'port': '6433',
                        'password': '******',
                    },
                    'test2': {
                        'host': '127.0.0.2',
                        'port': '6432',
                        'user': '******',
                    }
                }
            })
        collector = PgbouncerCollector(config, None)
        collector.collect()

        _get_stats_by_database.assert_any_call('127.0.0.1', '6433', 'postgres',
                                               'foobar')
        _get_stats_by_database.assert_any_call('127.0.0.2', '6432',
                                               'pgbouncer', '')
Beispiel #3
0
    def setUp(self):
        config = get_collector_config('PgbouncerCollector', {})

        self.collector = PgbouncerCollector(config, None)