當前位置: 首頁>>代碼示例>>Python>>正文


Python elasticsearch.ElasticSearchCollector類代碼示例

本文整理匯總了Python中elasticsearch.ElasticSearchCollector的典型用法代碼示例。如果您正苦於以下問題:Python ElasticSearchCollector類的具體用法?Python ElasticSearchCollector怎麽用?Python ElasticSearchCollector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ElasticSearchCollector類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestElasticSearchCollector

class TestElasticSearchCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config("ElasticSearchCollector", {})

        self.collector = ElasticSearchCollector(config, None)

    @patch.object(Collector, "publish")
    def test_should_work_with_real_data(self, publish_mock):
        with patch("urllib2.urlopen", Mock(return_value=self.getFixture("stats"))):
            self.collector.collect()

        metrics = {
            "http.current": 1,
            "indices.docs.count": 11968062,
            "indices.docs.deleted": 2692068,
            "indices.datastore.size": 22724243633,
            "process.cpu.percent": 58,
            "process.mem.resident": 5192126464,
            "process.mem.share": 11075584,
            "process.mem.virtual": 7109668864,
            "disk.reads.count": 55996,
            "disk.reads.size": 1235387392,
            "disk.writes.count": 5808198,
            "disk.writes.size": 23287275520,
        }

        self.setDocExample(self.collector.__class__.__name__, metrics)
        self.assertPublishedMany(publish_mock, metrics)

    @patch.object(Collector, "publish")
    def test_should_fail_gracefully(self, publish_mock):
        with patch("urllib2.urlopen", Mock(return_value=self.getFixture("stats_blank"))):
            self.collector.collect()

        self.assertPublishedMany(publish_mock, {})
開發者ID:microsigns,項目名稱:Diamond,代碼行數:35,代碼來源:testelasticsearch.py

示例2: TestElasticSearchCollector

class TestElasticSearchCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('ElasticSearchCollector', {})

        self.collector = ElasticSearchCollector(config, None)

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

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        urlopen_mock = patch('urllib2.urlopen', Mock(
            return_value=self.getFixture('stats')))

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

        metrics = {
            'http.current': 1,

            'indices.docs.count': 11968062,
            'indices.docs.deleted': 2692068,
            'indices.datastore.size': 22724243633,

            'process.cpu.percent': 58,

            'process.mem.resident': 5192126464,
            'process.mem.share': 11075584,
            'process.mem.virtual': 7109668864,

            'disk.reads.count': 55996,
            'disk.reads.size': 1235387392,
            'disk.writes.count': 5808198,
            'disk.writes.size': 23287275520,
        }

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

    @patch.object(Collector, 'publish')
    def test_should_fail_gracefully(self, publish_mock):
        urlopen_mock = patch('urllib2.urlopen', Mock(
                return_value=self.getFixture('stats_blank')))

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

        self.assertPublishedMany(publish_mock, {})
開發者ID:CBarraford,項目名稱:Diamond,代碼行數:52,代碼來源:testelasticsearch.py

示例3: test_new__instances_multi

 def test_new__instances_multi(self):
     config = get_collector_config('ElasticSearchCollector', {
         'instances': [
             'something',
             '[email protected]',
             '[email protected]:1234',
         ]})
     self.collector = ElasticSearchCollector(config, None)
     self.assertEqual(self.collector.get_instances(), {
         'default': ('something', 9200),
         'foo': ('1234', 9200),
         'bar': ('bla', 1234),
     })
開發者ID:sara62,項目名稱:Diamond,代碼行數:13,代碼來源:testelasticsearch.py

示例4: test_multi_instances_with_real_data

    def test_multi_instances_with_real_data(self, publish_mock):
        config = get_collector_config('ElasticSearchCollector', {
            'instances': [
                '[email protected]:9200',
                '[email protected]:9200',
            ]})
        self.collector = ElasticSearchCollector(config, None)
        self.assertEqual(len(self.collector.get_instances()), 2)

        returns = [
            self.getFixture('stats'),
            self.getFixture('indices_stats'),
            self.getFixture('stats2'),
            self.getFixture('indices_stats2'),
        ]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

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

        # check how many fixtures were consumed
        self.assertEqual(urlopen_mock.new.call_count, 4)

        expected_calls = [
            call('http.current', 1, source='esprodata01'),
            call('http.current', 2, source='esprodata02'),

            call('indices.docs.count', 11968062, source='esprodata01'),
            call('indices.docs.count', 11968000, source='esprodata02'),

            call('thread_pool.generic.threads', 1, source='esprodata01'),
            call('thread_pool.generic.threads', 2, source='esprodata02'),

            call('jvm.mem.pools.Par_Survivor_Space.max', 8716288, source='esprodata01'),
            call('jvm.mem.pools.Par_Survivor_Space.max', 8710000, source='esprodata02'),

            call('indices._all.docs.count', 4, source='esprodata01'),
            call('indices._all.docs.count', 8, source='esprodata02'),
        ]

        for exp_call in expected_calls:
            publish_mock.assert_has_calls(exp_call)
開發者ID:sara62,項目名稱:Diamond,代碼行數:44,代碼來源:testelasticsearch.py

示例5: test_multi_instances_with_real_data

    def test_multi_instances_with_real_data(self, publish_mock):
        config = get_collector_config('ElasticSearchCollector', {
            'instances': [
                '[email protected]:9200',
                '[email protected]:9200',
            ]})
        self.collector = ElasticSearchCollector(config, None)
        self.assertEqual(len(self.collector.instances), 2)

        returns = [
            self.getFixture('stats'),
            self.getFixture('indices_stats'),
            self.getFixture('stats2'),
            self.getFixture('indices_stats2'),
        ]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

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

        # check how many fixtures were consumed
        self.assertEqual(urlopen_mock.new.call_count, 4)

        metrics = {
            'esprodata01.http.current': 1,
            'esprodata02.http.current': 2,

            'esprodata01.indices.docs.count': 11968062,
            'esprodata02.indices.docs.count': 11968000,

            'esprodata01.thread_pool.generic.threads': 1,
            'esprodata02.thread_pool.generic.threads': 2,

            'esprodata01.jvm.mem.pools.Par_Survivor_Space.max': 8716288,
            'esprodata02.jvm.mem.pools.Par_Survivor_Space.max': 8710000,

            'esprodata01.indices._all.docs.count': 4,
            'esprodata02.indices._all.docs.count': 8,
        }

        self.assertPublishedMany(publish_mock, metrics)
開發者ID:AnderEnder,項目名稱:Diamond,代碼行數:43,代碼來源:testelasticsearch.py

示例6: setUp

    def setUp(self):
        config = get_collector_config('ElasticSearchCollector', {})

        self.collector = ElasticSearchCollector(config, None)
開發者ID:Vasilui,項目名稱:Diamond,代碼行數:4,代碼來源:testelasticsearch.py

示例7: test_new__instances_single

 def test_new__instances_single(self):
     config = get_collector_config('ElasticSearchCollector', {
         'instances': 'bla'})
     self.collector = ElasticSearchCollector(config, None)
     self.assertEqual(self.collector.get_instances(), {'default': ('bla', 9200)})
開發者ID:sara62,項目名稱:Diamond,代碼行數:5,代碼來源:testelasticsearch.py

示例8: test_new__instances_default

 def test_new__instances_default(self):
     config = get_collector_config('ElasticSearchCollector', {})
     self.collector = ElasticSearchCollector(config, None)
     self.assertEqual(self.collector.get_instances(), {'': ('127.0.0.1', 9200)})
開發者ID:sara62,項目名稱:Diamond,代碼行數:4,代碼來源:testelasticsearch.py

示例9: TestElasticSearchCollector

class TestElasticSearchCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('ElasticSearchCollector', {})

        self.collector = ElasticSearchCollector(config, None)

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

    def test_new__instances_default(self):
        config = get_collector_config('ElasticSearchCollector', {})
        self.collector = ElasticSearchCollector(config, None)
        self.assertEqual(self.collector.get_instances(), {'': ('127.0.0.1', 9200)})

    def test_new__instances_single(self):
        config = get_collector_config('ElasticSearchCollector', {
            'instances': 'bla'})
        self.collector = ElasticSearchCollector(config, None)
        self.assertEqual(self.collector.get_instances(), {'default': ('bla', 9200)})

    def test_new__instances_multi(self):
        config = get_collector_config('ElasticSearchCollector', {
            'instances': [
                'something',
                '[email protected]',
                '[email protected]:1234',
            ]})
        self.collector = ElasticSearchCollector(config, None)
        self.assertEqual(self.collector.get_instances(), {
            'default': ('something', 9200),
            'foo': ('1234', 9200),
            'bar': ('bla', 1234),
        })

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        returns = [
            self.getFixture('stats'),
            self.getFixture('cluster_stats'),
            self.getFixture('indices_stats'),
        ]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

        self.collector.config['cluster'] = True

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

        # check how many fixtures were consumed
        self.assertEqual(urlopen_mock.new.call_count, 3)

        metrics = {
            'http.current': 1,

            'indices.docs.count': 11968062,
            'indices.docs.deleted': 2692068,
            'indices.datastore.size': 22724243633,

            'indices._all.docs.count': 4,
            'indices._all.docs.deleted': 0,
            'indices._all.datastore.size': 2674,

            'indices.test.docs.count': 4,
            'indices.test.docs.deleted': 0,
            'indices.test.datastore.size': 2674,

            'process.cpu.percent': 58,

            'process.mem.resident': 5192126464,
            'process.mem.share': 11075584,
            'process.mem.virtual': 7109668864,

            'disk.reads.count': 55996,
            'disk.reads.size': 1235387392,
            'disk.writes.count': 5808198,
            'disk.writes.size': 23287275520,

            'thread_pool.generic.threads': 1,

            'network.tcp.active_opens': 2299,

            'jvm.mem.pools.CMS_Old_Gen.used': 530915016,
        }

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

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data_logstash_mode(self, publish_mock):
        returns = [
            self.getFixture('stats'),
            self.getFixture('logstash_indices_stats'),
        ]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

#.........這裏部分代碼省略.........
開發者ID:sara62,項目名稱:Diamond,代碼行數:101,代碼來源:testelasticsearch.py

示例10: TestElasticSearchCollector

class TestElasticSearchCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('ElasticSearchCollector', {})

        self.collector = ElasticSearchCollector(config, None)

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

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        returns = [self.getFixture('stats'), self.getFixture('indices_stats')]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

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

        metrics = {
            'http.current': 1,

            'indices.docs.count': 11968062,
            'indices.docs.deleted': 2692068,
            'indices.datastore.size': 22724243633,

            'indices._all.docs.count': 4,
            'indices._all.docs.deleted': 0,
            'indices._all.datastore.size': 2674,

            'indices.test.docs.count': 4,
            'indices.test.docs.deleted': 0,
            'indices.test.datastore.size': 2674,

            'process.cpu.percent': 58,

            'process.mem.resident': 5192126464,
            'process.mem.share': 11075584,
            'process.mem.virtual': 7109668864,

            'disk.reads.count': 55996,
            'disk.reads.size': 1235387392,
            'disk.writes.count': 5808198,
            'disk.writes.size': 23287275520,

            'thread_pool.generic.threads': 1,

            'network.tcp.active_opens': 2299,

            'jvm.mem.pools.CMS_Old_Gen.used': 530915016,
        }

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

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data_logstash_mode(self, publish_mock):
        returns = [
            self.getFixture('stats'),
            self.getFixture('logstash_indices_stats'),
        ]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

        self.collector.config['logstash_mode'] = True

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

        # Omit all non-indices metrics, since those were already
        # checked in previous test.
        metrics = {
            'indices.docs.count': 11968062,
            'indices.docs.deleted': 2692068,
            'indices.datastore.size': 22724243633,

            'indices._all.docs.count': 35856619,
            'indices._all.docs.deleted': 0,
            'indices._all.datastore.size': 21903813340,

            'indices._all.get.exists_time_in_millis': 0,
            'indices._all.get.exists_total': 0,
            'indices._all.get.missing_time_in_millis': 0,
            'indices._all.get.missing_total': 0,
            'indices._all.get.time_in_millis': 0,
            'indices._all.get.total': 0,
            'indices._all.indexing.delete_time_in_millis': 0,
            'indices._all.indexing.delete_total': 0,
            'indices._all.indexing.index_time_in_millis': 29251475,
            'indices._all.indexing.index_total': 35189321,
            'indices._all.search.fetch_time_in_millis': 6962,
            'indices._all.search.fetch_total': 4084,
            'indices._all.search.query_time_in_millis': 41211,
            'indices._all.search.query_total': 4266,
            'indices._all.store.throttle_time_in_millis': 0,

            'indices.logstash-adm-syslog.indexes_in_group': 3,
#.........這裏部分代碼省略.........
開發者ID:50onRed,項目名稱:Diamond,代碼行數:101,代碼來源:testelasticsearch.py

示例11: TestElasticSearchCollector

class TestElasticSearchCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('ElasticSearchCollector', {})

        self.collector = ElasticSearchCollector(config, None)

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

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        returns = [self.getFixture('stats'), self.getFixture('indices_stats')]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

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

        metrics = {
            'http.current': 1,

            'indices.docs.count': 11968062,
            'indices.docs.deleted': 2692068,
            'indices.datastore.size': 22724243633,

            'indices._all.docs.count': 4,
            'indices._all.docs.deleted': 0,
            'indices._all.datastore.size': 2674,

            'indices.test.docs.count': 4,
            'indices.test.docs.deleted': 0,
            'indices.test.datastore.size': 2674,

            'process.cpu.percent': 58,

            'process.mem.resident': 5192126464,
            'process.mem.share': 11075584,
            'process.mem.virtual': 7109668864,

            'disk.reads.count': 55996,
            'disk.reads.size': 1235387392,
            'disk.writes.count': 5808198,
            'disk.writes.size': 23287275520,

            'thread_pool.generic.threads': 1,

            'network.tcp.active_opens': 2299,

            'jvm.mem.pools.CMS_Old_Gen.used': 530915016,
        }

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

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_0_90_data(self, publish_mock):
        returns = [
            self.getFixture('stats0.90'), self.getFixture('indices_stats')]
        urlopen_mock = patch('urllib2.urlopen', Mock(
            side_effect=lambda *args: returns.pop(0)))

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

        # test some 0.90 specific stats
        metrics = {
            'cache.filter.size': 1700,
            'cache.filter.evictions': 9,
            'cache.id.size': 98,
            'fielddata.size': 1448,
            'fielddata.evictions': 12,
        }

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

    @patch.object(Collector, 'publish')
    def test_should_fail_gracefully(self, publish_mock):
        urlopen_mock = patch('urllib2.urlopen', Mock(
                return_value=self.getFixture('stats_blank')))

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

        self.assertPublishedMany(publish_mock, {})
開發者ID:MediaMath,項目名稱:Diamond,代碼行數:92,代碼來源:testelasticsearch.py


注:本文中的elasticsearch.ElasticSearchCollector類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。