def crawl(self, container_id=None, **kwargs): c = dockercontainer.DockerContainer(container_id) # check image name if c.image_name.find(self.feature_key) == -1: logger.error("%s is not %s container", c.image_name, self.feature_key) raise CrawlError("%s does not have expected name for %s (name=%s)", container_id, self.feature_key, c.image_name) # extract IP and Port information ip = c.get_container_ip() ports = c.get_container_ports() # crawl all candidate ports for port in ports: try: metrics = nginx_crawler.retrieve_metrics(ip, port) except CrawlError: logger.error("can't find metrics endpoint at http://%s:%s", ip, port) continue return [(self.feature_key, metrics, self.feature_type)] raise CrawlError("%s has no accessible endpoint for %s", container_id, self.feature_key)
def crawl(self, container_id=None, **kwargs): c = dockercontainer.DockerContainer(container_id) port = None if "annotation.io.kubernetes.container.ports" in\ c.inspect['Config']['Labels']: ports = c.inspect['Config']['Labels'][ 'annotation.io.kubernetes.container.ports'] ports = json.loads(ports) else: ports = c.get_container_ports() for each_port in ports: tmp_port = None if "containerPort" in each_port: tmp_port = int(each_port['containerPort']) else: tmp_port = int(each_port) if tmp_port == self.default_port: port = tmp_port if not port: return state = c.inspect['State'] pid = str(state['Pid']) ips = run_as_another_namespace(pid, ['net'], utils.misc.get_host_ip4_addresses) for each_ip in ips: if each_ip != "127.0.0.1": ip = each_ip break # crawl all candidate ports try: metrics = nginx_crawler.retrieve_metrics(ip, port) return [(self.feature_key, metrics, self.feature_type)] except: logger.error("can't find metrics endpoint at http://%s:%s", ip, port) raise ConnectionError( "can't find metrics endpoint" "at http://%s:%s", ip, port)
def crawl(self, container_id=None, **kwargs): c = dockercontainer.DockerContainer(container_id) # check image name if c.image_name.find(self.feature_key) == -1: logger.error("%s is not %s container", c.image_name, self.feature_key) raise CrawlError( "%s does not have expected name for %s (name=%s)", container_id, self.feature_key, c.image_name ) # extract IP and Port information ip = c.get_container_ip() ports = c.get_container_ports() # crawl all candidate ports for port in ports: try: metrics = nginx_crawler.retrieve_metrics(ip, port) except CrawlError: logger.error("can't find metrics endpoint at http://%s:%s", ip, port) continue return [(self.feature_key, metrics, self.feature_type)] raise CrawlError("%s has no accessible endpoint for %s", container_id, self.feature_key)
def test_hundle_ioerror(self): with self.assertRaises(CrawlError): nginx_crawler.retrieve_metrics()
def test_ok(self): self.assertIsInstance(nginx_crawler.retrieve_metrics(), NginxFeature)
def test_ok(self): self.assertIsInstance(nginx_crawler.retrieve_metrics(), NginxFeature)
def test_hundle_parseerror(self): with self.assertRaises(CrawlError): nginx_crawler.retrieve_metrics()
def crawl(self): metrics = nginx_crawler.retrieve_metrics( host='localhost', port=self.default_port ) return [(self.feature_key, metrics, self.feature_type)]
def crawl(self): metrics = nginx_crawler.retrieve_metrics(host='localhost', port=self.default_port) return [(self.feature_key, metrics, self.feature_type)]