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

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

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

        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:
            return liberty_crawler.retrieve_metrics(
                host=ip,
                port=each_port,
                user=user,
                password=password,
                feature_type=self.feature_type)

        raise CrawlError("%s has no accessible endpoint for %s", container_id,
                         self.feature_key)
    def crawl(self, container_id=None, **kwargs):

        password, user = 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:
            return liberty_crawler.retrieve_metrics(
                host=ip,
                port=port,
                user=user,
                password=password,
                feature_type=self.feature_type)
        except:
            logger.info("liberty does not listen on port:%d", port)
            raise ConnectionError("liberty does not listen on port:%d", port)
コード例 #3
0
    def crawl(self, container_id=None, **kwargs):

        password, user = 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:
            return liberty_crawler.retrieve_metrics(
                host=ip,
                port=port,
                user=user,
                password=password,
                feature_type=self.feature_type)
        except:
            logger.info("liberty does not listen on port:%d", port)
            raise ConnectionError("liberty does not listen on port:%d", port)
コード例 #4
0
ファイル: liberty_host_crawler.py プロジェクト: CCI-MOC/ABMI
    def crawl(self, **options):
        password = "******"
        user = "******"

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

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

        return liberty_crawler.retrieve_metrics(host='localhost',
                                                port=self.default_port,
                                                user=user,
                                                password=password,
                                                feature_type=self.feature_type)
コード例 #5
0
 def test_ok(self, server_status_value):
     status = list(liberty_crawler.retrieve_metrics())
     assert status == [('liberty_servlet_status',
                        feature.LibertyServletFeature(
                            name='JMXRESTProxyServlet',
                            appName='com.ibm.ws.jmx.connector.server.rest',
                            reqCount='292',
                            responseMean='1646404.6780821919',
                            responseMax='129746827',
                            responseMin='257689'),
                        'application'),
                       ('liberty_jvm_status',
                        feature.LibertyJVMFeature(
                            heap='31588352',
                            freeMemory='9104704',
                            usedMemory='23213312',
                            processCPU='0.07857719811500322',
                            gcCount='1325',
                            gcTime='1001',
                            upTime='155755366'),
                        'application'),
                       ('liberty_thread_status',
                        feature.LibertyThreadFeature(
                            activeThreads='1',
                            poolSize='4',
                            poolName='Default Executor'),
                        'application'),
                       ('liberty_session_status',
                        feature.LibertySessionFeature(
                            name='default_host/IBMJMXConnectorREST',
                            createCount='1',
                            liveCount='0',
                            activeCount='0',
                            invalidatedCount='1',
                            invalidatedCountByTimeout='2'),
                        'application'),
                       ('liberty_mongo_connection_status',
                        feature.LibertyMongoConnectionFeature(
                            checkedOutCount='1',
                            waitQueueSize='2',
                            maxSize='4',
                            minSize='3',
                            host='test',
                            port='12',
                            size='7'),
                        'application')]
コード例 #6
0
 def test_ok(self, server_status_value):
     status = list(liberty_crawler.retrieve_metrics())
     assert status == [('liberty_servlet_status',
                        feature.LibertyServletFeature(
                            name='JMXRESTProxyServlet',
                            appName='com.ibm.ws.jmx.connector.server.rest',
                            reqCount='292',
                            responseMean='1646404.6780821919',
                            responseMax='129746827',
                            responseMin='257689'),
                        'application'),
                       ('liberty_jvm_status',
                        feature.LibertyJVMFeature(
                            heap='31588352',
                            freeMemory='9104704',
                            usedMemory='23213312',
                            processCPU='0.07857719811500322',
                            gcCount='1325',
                            gcTime='1001',
                            upTime='155755366'),
                        'application'),
                       ('liberty_thread_status',
                        feature.LibertyThreadFeature(
                            activeThreads='1',
                            poolSize='4',
                            poolName='Default Executor'),
                        'application'),
                       ('liberty_session_status',
                        feature.LibertySessionFeature(
                            name='default_host/IBMJMXConnectorREST',
                            createCount='1',
                            liveCount='0',
                            activeCount='0',
                            invalidatedCount='1',
                            invalidatedCountByTimeout='2'),
                        'application'),
                       ('liberty_mongo_connection_status',
                        feature.LibertyMongoConnectionFeature(
                            checkedOutCount='1',
                            waitQueueSize='2',
                            maxSize='4',
                            minSize='3',
                            host='test',
                            port='12',
                            size='7'),
                        'application')]
コード例 #7
0
 def test_read(self):
     liberty_crawler.retrieve_status_page("user", "pass", "localhost")
     self.assertNotIsInstance(liberty_crawler.retrieve_metrics(),
                              feature.LibertyServletFeature)
コード例 #8
0
 def test_read(self):
     liberty_crawler.retrieve_status_page("user", "pass", "localhost")
     self.assertNotIsInstance(liberty_crawler.retrieve_metrics(),
                              feature.LibertyServletFeature)