コード例 #1
0
def test_get_host_metrics(instance):
    ambari = AmbariCheck(instances=[instance])
    ambari._get_hosts_info = MagicMock(return_value=responses.HOSTS_INFO)
    ambari._submit_gauge = MagicMock()
    ambari.set_external_tags = MagicMock()
    cluster_tag = ['ambari_cluster:cluster1']

    ambari.get_host_metrics('localhost', ['cluster1'])
    ambari.set_external_tags.assert_called_with([('my_host_1', {
        'ambari': cluster_tag
    }), ('my_host_2', {
        'ambari': cluster_tag
    })])

    assert ambari._submit_gauge.call_count == 30
    ambari._submit_gauge.assert_has_calls(
        [
            call('boottime', 1555934503.0, cluster_tag, 'my_host_2'),
            call('cpu.cpu_idle', 62.8, cluster_tag, 'my_host_2'),
            call('cpu.cpu_nice', 0.0, cluster_tag, 'my_host_2'),
            call('cpu.cpu_num', 4.0, cluster_tag, 'my_host_2'),
            call('cpu.cpu_system', 5.1, cluster_tag, 'my_host_2'),
            call('cpu.cpu_user', 32.0, cluster_tag, 'my_host_2'),
            call('cpu.cpu_wio', 0.0, cluster_tag, 'my_host_2'),
            call('disk.disk_free', 124.35, cluster_tag, 'my_host_2'),
            call('disk.disk_total', 148.29, cluster_tag, 'my_host_2'),
            call('disk.read_bytes', 1594053632.0, cluster_tag, 'my_host_2'),
            call('disk.read_count', 42717.0, cluster_tag, 'my_host_2'),
            call('disk.read_time', 240986.0, cluster_tag, 'my_host_2'),
            call('disk.write_bytes', 117000843264.0, cluster_tag, 'my_host_2'),
            call('disk.write_count', 499318.0, cluster_tag, 'my_host_2'),
            call('disk.write_time', 5946304.0, cluster_tag, 'my_host_2'),
            call('load.load_fifteen', 0.99, cluster_tag, 'my_host_2'),
            call('load.load_five', 1.35, cluster_tag, 'my_host_2'),
            call('load.load_one', 0.57, cluster_tag, 'my_host_2'),
            call('memory.mem_cached', 3554248.0, cluster_tag, 'my_host_2'),
            call('memory.mem_free', 11327848.0, cluster_tag, 'my_host_2'),
            call('memory.mem_shared', 0.0, cluster_tag, 'my_host_2'),
            call('memory.mem_total', 15399208.0, cluster_tag, 'my_host_2'),
            call('memory.swap_free', 0.0, cluster_tag, 'my_host_2'),
            call('memory.swap_total', 0.0, cluster_tag, 'my_host_2'),
            call('network.bytes_in', 683.2346950556641, cluster_tag,
                 'my_host_2'),
            call('network.bytes_out', 12517.203580542699, cluster_tag,
                 'my_host_2'),
            call('network.pkts_in', 8.499187630576825, cluster_tag,
                 'my_host_2'),
            call('network.pkts_out', 10.498996484830196, cluster_tag,
                 'my_host_2'),
            call('process.proc_run', 0.0, cluster_tag, 'my_host_2'),
            call('process.proc_total', 128.0, cluster_tag, 'my_host_2'),
        ],
        any_order=True,
    )
コード例 #2
0
def test_get_host_metrics(instance):
    ambari = AmbariCheck(instances=[instance])
    ambari._get_hosts_info = MagicMock(return_value=responses.HOSTS_INFO)
    ambari._submit_gauge = MagicMock()
    ambari.set_external_tags = MagicMock()

    ambari.get_host_metrics('localhost', ['cluster1'], [])
    ambari.set_external_tags.assert_called_with([('my_host_1', {
        'ambari': ['ambari_cluster:cluster1']
    }), ('my_host_2', {
        'ambari': ['ambari_cluster:cluster1']
    })])
    assert ambari._submit_gauge.call_count == 30
コード例 #3
0
ファイル: test_ambari.py プロジェクト: tyz/integrations-core
def test_get_host_metrics(instance, aggregator):
    ambari = AmbariCheck(instances=[instance])
    ambari._get_hosts_info = MagicMock(return_value=responses.HOSTS_INFO)
    ambari.set_external_tags = MagicMock()
    cluster_tag = ['ambari_cluster:cluster1']

    ambari.get_host_metrics('localhost', ['cluster1'])
    ambari.set_external_tags.assert_called_with([('my_host_1', {
        'ambari': cluster_tag
    }), ('my_host_2', {
        'ambari': cluster_tag
    })])

    metrics = [
        ('boottime', 1555934503.0),
        ('cpu.cpu_idle', 62.8),
        ('cpu.cpu_nice', 0.0),
        ('cpu.cpu_num', 4.0),
        ('cpu.cpu_system', 5.1),
        ('cpu.cpu_user', 32.0),
        ('cpu.cpu_wio', 0.0),
        ('disk.disk_free', 124.35),
        ('disk.disk_total', 148.29),
        ('disk.read_bytes', 1594053632.0),
        ('disk.read_count', 42717.0),
        ('disk.read_time', 240986.0),
        ('disk.write_bytes', 117000843264.0),
        ('disk.write_count', 499318.0),
        ('disk.write_time', 5946304.0),
        ('load.load_fifteen', 0.99),
        ('load.load_five', 1.35),
        ('load.load_one', 0.57),
        ('memory.mem_cached', 3554248.0),
        ('memory.mem_free', 11327848.0),
        ('memory.mem_shared', 0.0),
        ('memory.mem_total', 15399208.0),
        ('memory.swap_free', 0.0),
        ('memory.swap_total', 0.0),
        ('network.bytes_in', 683.2346950556641),
        ('network.bytes_out', 12517.203580542699),
        ('network.pkts_in', 8.499187630576825),
        ('network.pkts_out', 10.498996484830196),
        ('process.proc_run', 0.0),
        ('process.proc_total', 128.0),
    ]
    for m in metrics:
        aggregator.assert_metric(name='ambari.{}'.format(m[0]),
                                 value=m[1],
                                 tags=cluster_tag,
                                 hostname='my_host_2')
コード例 #4
0
def test_should_not_collect_if_disabled(instance):
    ambari = AmbariCheck('Ambari', {'collect_service_metrics': False, 'collect_service_status': False}, [instance])
    _mock_clusters(ambari)
    ambari.get_host_metrics = MagicMock()
    ambari.get_service_status_and_metrics = MagicMock()
    ambari.check(instance)

    assert not ambari.get_service_status_and_metrics.called
コード例 #5
0
def test_should_collect_host_metrics(instance):
    ambari = AmbariCheck(
        init_config={'collect_service_metrics': False, 'collect_service_status': False}, instances=[instance]
    )
    _mock_clusters(ambari)
    ambari.get_host_metrics = MagicMock()
    ambari.get_service_status_and_metrics = MagicMock()
    ambari.check(instance)

    assert ambari.get_host_metrics.called
    assert not ambari.get_service_status_and_metrics.called
コード例 #6
0
def test_should_collect_service_status(instance):
    ambari = AmbariCheck('Ambari', {'collect_service_metrics': False, 'collect_service_status': True}, [instance])
    _mock_clusters(ambari)
    ambari.get_host_metrics = MagicMock()
    ambari.get_component_metrics = MagicMock()
    ambari.get_service_checks = MagicMock()
    ambari.check(instance)

    assert ambari.get_host_metrics.called
    assert not ambari.get_component_metrics.called
    assert ambari.get_service_checks.called