コード例 #1
0
    def crawl(self, container_id=None, **kwargs):

        password, user, db = self.get_opt(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

        try:
            metrics = db2_crawler.retrieve_metrics(
                host=ip,
                user=user,
                password=password,
                db=db,
            )
            return [(self.feature_key, metrics, self.feature_type)]
        except:
            logger.info("db2 does not listen on port:%d", port)
            raise ConnectionError("db2 does not listen on port:%d", port)
コード例 #2
0
ファイル: db2_container_crawler.py プロジェクト: CCI-MOC/ABMI
    def crawl(self, container_id=None, **kwargs):

        password, user, db = self.get_opt(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

        try:
            metrics = db2_crawler.retrieve_metrics(
                host=ip,
                user=user,
                password=password,
                db=db,
            )
            return [(self.feature_key, metrics, self.feature_type)]
        except:
            logger.info("db2 does not listen on port:%d", port)
            raise ConnectionError("db2 does not listen on port:%d", port)
    def crawl(self, container_id=None, **kwargs):
        password = "******"
        user = "******"
        db = "sample"

        if "password" in kwargs:
            password = kwargs["password"]

        if "user" in kwargs:
            user = kwargs["user"]

        if "db" in kwargs:
            db = kwargs["db"]

        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 each_port in ports:
            try:
                metrics = db2_crawler.retrieve_metrics(
                    host=ip,
                    user=user,
                    password=password,
                    db=db,
                )
            except CrawlError:
                logger.error("can't find metrics endpoint at %s db %s",
                             ip, db)
                continue
            return [(self.feature_key, metrics, self.feature_type)]

        raise CrawlError("%s has no accessible endpoint for %s",
                         container_id,
                         self.feature_key)
コード例 #4
0
ファイル: db2_host_crawler.py プロジェクト: CCI-MOC/ABMI
    def crawl(self, **options):
        password = "******"
        user = "******"
        db = "sample"

        if "password" in options:
            password = options["password"]

        if "user" in options:
            user = options["user"]

        if "db" in options:
            db = options["db"]

        try:
            metrics = db2_crawler.retrieve_metrics(host="localhost",
                                                   user=user,
                                                   password=password,
                                                   db=db)
            return [(self.feature_key, metrics, self.feature_type)]
        except:
            raise CrawlError("cannot retrice metrics db %s", db)
コード例 #5
0
    def crawl(self, **options):
        password = "******"
        user = "******"
        db = "sample"

        if "password" in options:
            password = options["password"]

        if "user" in options:
            user = options["user"]

        if "db" in options:
            db = options["db"]

        try:
            metrics = db2_crawler.retrieve_metrics(
                host="localhost",
                user=user,
                password=password,
                db=db
            )
            return [(self.feature_key, metrics, self.feature_type)]
        except:
            raise CrawlError("cannot retrice metrics db %s", db)
コード例 #6
0
 def test_ok(self, mock_connect):
     status = db2_crawler.retrieve_metrics()
     self.assertIsInstance(status, DB2Feature)
コード例 #7
0
 def test_exec_error(self):
     with self.assertRaises(CrawlError):
         db2_crawler.retrieve_metrics()
コード例 #8
0
 def test_ok(self, mock_connect):
     status = db2_crawler.retrieve_metrics()
     self.assertIsInstance(status, DB2Feature)
コード例 #9
0
 def test_exec_error(self):
     with self.assertRaises(CrawlError):
         db2_crawler.retrieve_metrics()