本文整理汇总了Python中elasticsearch.ElasticSearchCollector.get_instances方法的典型用法代码示例。如果您正苦于以下问题:Python ElasticSearchCollector.get_instances方法的具体用法?Python ElasticSearchCollector.get_instances怎么用?Python ElasticSearchCollector.get_instances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elasticsearch.ElasticSearchCollector
的用法示例。
在下文中一共展示了ElasticSearchCollector.get_instances方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestElasticSearchCollector
# 需要导入模块: from elasticsearch import ElasticSearchCollector [as 别名]
# 或者: from elasticsearch.ElasticSearchCollector import get_instances [as 别名]
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)))
#.........这里部分代码省略.........