class TestPrometheusClientScraping(unittest.TestCase): def setUp(self): self.check = Prometheus('prometheus', CONFIG['init_config'], {}, instances=CONFIG['instances']) def runTest(self): self.run_check() def run_check(self): self.setUp() @mock.patch('requests.get', local_get) def testEndpointScraping(self): # check parsing and pushing metrics works self.check.run() time.sleep(65) metrics = self.check.get_metrics() print metrics metric_family_names = set([m['measurement']['name'] for m in metrics]) # check parsed metrics self.assertTrue(metrics) self.assertTrue('apiserver_request_count' in metric_family_names) self.assertEqual( [i['measurement']['value'] for i in metrics if i['measurement']['name'] == 'apiserver_request_count'][0], 403) self.assertEqual( [i['measurement']['dimensions']['instance'] for i in metrics if i['measurement']['name'] == 'apiserver_request_count'][0], u'kubernetes.default:443') self.assertTrue('apiserver_request_latencies_bucket' in metric_family_names) self.assertEqual([i['measurement']['value'] for i in metrics if i['measurement']['name'] == 'apiserver_request_latencies_bucket'][0], 443394) self.assertEqual( [i['measurement']['dimensions']['component'] for i in metrics if i['measurement']['name'] == 'apiserver_request_latencies_bucket'][ 0], 'apiserver') self.assertTrue('datapath.nslookup_common_status' in metric_family_names) self.assertTrue('datapath.nslookup_kvm_instance_status' in metric_family_names) self.assertTrue('kubernetes.container_start_time_sec' in metric_family_names) self.assertTrue('kubernetes.container_memory_usage_bytes' in metric_family_names)
def setUp(self): self.check = Prometheus('prometheus', CONFIG['init_config'], {}, instances=CONFIG['instances'])