def retrieve_metrics(host='localhost',
                     port=9443,
                     user='******',
                     password='******',
                     feature_type='application'):
    url = "https://%s:%s/IBMJMXConnectorREST/mbeans/" % (host, port)

    status = retrieve_status_page(user, password, url)
    json_obj = json.loads(status)
    base_url = "https://%s:%s" % (host, port)

    mbeans_url_array = get_url(json_obj,
                               "com.ibm.ws.webcontainer.monitor.ServletStats")
    for url in mbeans_url_array:
        serv_stats = get_servlet_stats(base_url, url, user, password)
        servlet_attributes = feature.LibertyServletFeature(
            serv_stats.get("name"), serv_stats.get("appName"),
            serv_stats.get("reqCount"), serv_stats.get("responseMean"),
            serv_stats.get("responseMax"), serv_stats.get("responseMin"))
        yield ('liberty_servlet_status', servlet_attributes, feature_type)

    mbeans_url_array = get_url(json_obj, "com.ibm.ws.monitors.helper.JvmStats")

    for url in mbeans_url_array:
        jvm_stats = get_jvm_stats(base_url, url, user, password)
        jvm_attributes = feature.LibertyJVMFeature(jvm_stats.get("Heap"),
                                                   jvm_stats.get("FreeMemory"),
                                                   jvm_stats.get("UsedMemory"),
                                                   jvm_stats.get("ProcessCPU"),
                                                   jvm_stats.get("GcCount"),
                                                   jvm_stats.get("GcTime"),
                                                   jvm_stats.get("UpTime"))
        yield ('liberty_jvm_status', jvm_attributes, feature_type)

    mbeans_url_array = get_url(json_obj,
                               "com.ibm.ws.monitors.helper.ThreadPoolStats")

    for url in mbeans_url_array:
        thread_stats = get_thread_stats(base_url, url, user, password)
        thread_attributes = feature.LibertyThreadFeature(
            thread_stats.get("ActiveThreads"), thread_stats.get("PoolSize"),
            thread_stats.get("PoolName"))
        yield ('liberty_thread_status', thread_attributes, feature_type)

    mbeans_url_name_array = get_url_and_name(
        json_obj, "com.ibm.ws.session.monitor"
        ".SessionStats")

    for url_name in mbeans_url_name_array:
        session_stats = get_session_stats(base_url, url_name[0], user,
                                          password)
        session_attributes = feature.LibertySessionFeature(
            url_name[1],
            session_stats.get("CreateCount"),
            session_stats.get("LiveCount"),
            session_stats.get("ActiveCount"),
            session_stats.get("InvalidatedCount"),
            session_stats.get("InvalidatedCountbyTimeout"),
        )
        yield ('liberty_session_status', session_attributes, feature_type)
Exemplo n.º 2
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')]