def test_get_component_metrics(init_config, instance): ambari = AmbariCheck(init_config=init_config, instances=[instance]) ambari._make_request = MagicMock(return_value=responses.COMPONENT_METRICS) ambari._submit_gauge = MagicMock() namenode_tags = [ 'ambari_cluster:LabCluster', 'ambari_service:hdfs', 'ambari_component:namenode' ] ambari.get_component_metrics( 'localhost', 'LabCluster', 'HDFS', base_tags=['ambari_cluster:LabCluster', 'ambari_service:hdfs'], component_whitelist=['NAMENODE'], metric_whitelist=['cpu'], ) ambari._make_request.assert_called_with( 'localhost/api/v1/clusters/LabCluster/services/HDFS/components?fields=metrics' ) ambari._submit_gauge.assert_has_calls( [ call('cpu.cpu_idle', 90.3, namenode_tags), call('cpu.cpu_idle._avg', 90.3, namenode_tags), call('cpu.cpu_idle._max', 90.3, namenode_tags), call('cpu.cpu_idle._min', 90.3, namenode_tags), call('cpu.cpu_idle._sum', 90.3, namenode_tags), call('cpu.cpu_nice', 0.0, namenode_tags), call('cpu.cpu_nice._avg', 0.0, namenode_tags), call('cpu.cpu_nice._max', 0.0, namenode_tags), call('cpu.cpu_nice._min', 0.0, namenode_tags), call('cpu.cpu_nice._sum', 0.0, namenode_tags), call('cpu.cpu_system', 1.6333333333333335, namenode_tags), call('cpu.cpu_system._avg', 1.6333333333333335, namenode_tags), call('cpu.cpu_system._max', 1.6333333333333335, namenode_tags), call('cpu.cpu_system._min', 1.6333333333333335, namenode_tags), call('cpu.cpu_system._sum', 1.6333333333333335, namenode_tags), call('cpu.cpu_user', 8.033333333333333, namenode_tags), call('cpu.cpu_user._avg', 8.033333333333333, namenode_tags), call('cpu.cpu_user._max', 8.033333333333333, namenode_tags), call('cpu.cpu_user._min', 8.033333333333333, namenode_tags), call('cpu.cpu_user._sum', 8.033333333333333, namenode_tags), call('cpu.cpu_wio', 0.0, namenode_tags), call('cpu.cpu_wio._avg', 0.0, namenode_tags), call('cpu.cpu_wio._max', 0.0, namenode_tags), call('cpu.cpu_wio._min', 0.0, namenode_tags), call('cpu.cpu_wio._sum', 0.0, namenode_tags), ], any_order=True, )
def test_get_component_metrics(init_config, instance, aggregator): ambari = AmbariCheck(init_config=init_config, instances=[instance]) ambari._make_request = MagicMock(return_value=responses.COMPONENT_METRICS) namenode_tags = [ 'ambari_cluster:LabCluster', 'ambari_service:hdfs', 'ambari_component:namenode' ] ambari.get_component_metrics( 'localhost', 'LabCluster', 'HDFS', base_tags=['ambari_cluster:LabCluster', 'ambari_service:hdfs'], component_whitelist={'NAMENODE': ['cpu']}, ) ambari._make_request.assert_called_with( 'localhost/api/v1/clusters/LabCluster/services/HDFS/components?fields=metrics' ) metrics = [ ('cpu.cpu_idle', 90.3), ('cpu.cpu_idle._avg', 90.3), ('cpu.cpu_idle._max', 90.3), ('cpu.cpu_idle._min', 90.3), ('cpu.cpu_idle._sum', 90.3), ('cpu.cpu_nice', 0.0), ('cpu.cpu_nice._avg', 0.0), ('cpu.cpu_nice._max', 0.0), ('cpu.cpu_nice._min', 0.0), ('cpu.cpu_nice._sum', 0.0), ('cpu.cpu_system', 1.6333333333333335), ('cpu.cpu_system._avg', 1.6333333333333335), ('cpu.cpu_system._max', 1.6333333333333335), ('cpu.cpu_system._min', 1.6333333333333335), ('cpu.cpu_system._sum', 1.6333333333333335), ('cpu.cpu_user', 8.033333333333333), ('cpu.cpu_user._avg', 8.033333333333333), ('cpu.cpu_user._max', 8.033333333333333), ('cpu.cpu_user._min', 8.033333333333333), ('cpu.cpu_user._sum', 8.033333333333333), ('cpu.cpu_wio', 0.0), ('cpu.cpu_wio._avg', 0.0), ('cpu.cpu_wio._max', 0.0), ('cpu.cpu_wio._min', 0.0), ('cpu.cpu_wio._sum', 0.0), ] for m in metrics: aggregator.assert_metric(name='ambari.{}'.format(m[0]), value=m[1], tags=namenode_tags)
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