예제 #1
0
 def test_parse_metric_family(self):
     f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'prometheus', 'protobuf.bin')
     with open(f_name, 'rb') as f:
         data = f.read()
         self.assertEqual(len(data), 51855)
         messages = list(parse_metric_family(data))
         self.assertEqual(len(messages), 61)
         self.assertEqual(messages[-1].name, 'process_virtual_memory_bytes')
예제 #2
0
 def setUpClass(cls):
     """
     Preload all protobuf messages in a dict so we can use during
     unit tests without cycling every time the binary buffer.
     """
     cls.messages = {}
     f_name = os.path.join(os.path.dirname(__file__), 'fixtures',
                           'prometheus', 'protobuf.bin')
     with open(f_name, 'rb') as f:
         for msg in parse_metric_family(f.read()):
             cls.messages[msg.name] = msg
예제 #3
0
    def _update_kube_state_metrics(self, instance):
        """
        Retrieve the binary payload and process Prometheus metrics into
        Datadog metrics.
        """
        kube_state_url = instance.get('kube_state_url')
        if kube_state_url is None:
            raise CheckException("Unable to find kube_state_url in config file.")

        try:
            payload = self._get_kube_state(kube_state_url)
            msg = "Got a payload of size {} from Kube State API at url:{}".format(len(payload), kube_state_url)
            self.log.debug(msg)
            for metric in parse_metric_family(payload):
                self.kube_state_processor.process(metric, instance=instance)
        except Exception as e:
            self.log.error("Unable to retrieve metrics from Kube State API: {}".format(e))