Usage

Through HTTP Elastic API

You can call jmx-extractor with Elastic API HTTP endpoint. Example is shown below:

extractAll

Request:

POST /_eapi/ELASTIC_HTTP/jmx-extractor/jmxExtractorService/extractAll HTTP/1.1
Host: localhost:8000
User-Agent: curl/7.58.0
Accept: */*
x-jlns-api-id: RMC
Content-Type: application/json
Content-Length: 2

Response:

HTTP/1.1 200 OK
Server: unknown
Date: Tue, 09 Apr 2019 09:31:04 GMT
Content-Type: application/json
Content-Length: 288998
Connection: keep-alive
Access-Control-Allow-Origin: *

{
  "192.168.0.1:9010": {
    "currency-converter-chf": "MICROSERVICE_OUTPUT_OBJECT",
    [...],
    "MAIN_SERVER": "MAIN_SERVER_OUTPUT_OBJECT"
  },
  "192.168.0.2:9010": {
    "currency-converter-chf": "MICROSERVICE_OUTPUT_OBJECT",
    [...],
    "MAIN_SERVER": "MAIN_SERVER_OUTPUT_OBJECT"
  },
  [...]
}

Where MICROSERVICE_OUTPUT_OBJECT is an output with MBeans (full example can be found here: native, servlet, queue, channel) and where MAIN_SERVER_OUTPUT_OBJECT is an output with MBeans (full example can be found here).

extractSelected

Request:

POST /_eapi/ELASTIC_HTTP/jmx-extractor/jmxExtractorService/extractSelected HTTP/1.1
Host: localhost:8000
User-Agent: curl/7.58.0
Accept: */*
x-jlns-api-id: RMC
Content-Type: application/json
Content-Length: 357

[
  {
    "attributesMainServer": {
      "java.lang:type=Threading": {
        "ThreadCount": true
      }
    },
    "attributesMicroserviceCommon": {
      "java.lang:type=Runtime": {
        "StartTime": true
      }
    },
    "attributesMicroserviceSpecific": {
      "currency-converter-chf": {
        "java.lang:type=ClassLoading": {
          "LoadedClassCount": true
        }
      }
    }
  }
]

Response:

HTTP/1.1 200 OK
Server: unknown
Date: Tue, 09 Apr 2019 10:01:22 GMT
Content-Type: application/json
Content-Length: 457
Connection: keep-alive
Access-Control-Allow-Origin: *

{
  "localhost:9010": {
    "currency-converter-chf": {
      "java.lang:type=ClassLoading": {
        "LoadedClassCount": "5809"
      },
      "java.lang:type=Runtime": {
        "StartTime": "1554802064316"
      }
    },
    "channelMicroservice": {
      "java.lang:type=Runtime": {
        "StartTime": "1554802051778"
      }
    },
    [...],
    "MAIN_SERVER": {
      "java.lang:type=Threading": {
        "ThreadCount": "70"
      }
    }
  }
}

Get nodes IPs and microservices names

If you want to retrieve only nodes IPs and microservices names you can make query with no selected data.

Request:

POST /_eapi/ELASTIC_HTTP/jmx-extractor/jmxExtractorService/extractSelected HTTP/1.1
Host: localhost:8000
User-Agent: curl/7.58.0
Accept: */*
x-jlns-api-id: RMC
Content-Type: application/json
Content-Length: 357

[
  {}
]

Response:

HTTP/1.1 200 OK
Server: unknown
Date: Tue, 09 Apr 2019 10:01:22 GMT
Content-Type: application/json
Content-Length: 457
Connection: keep-alive
Access-Control-Allow-Origin: *

{
  "192.168.0.1:9010": {
    "currency-converter-chf": {},
    "channelMicroservice": {},
    [...],
    "MAIN_SERVER": {}
  },
  "192.168.0.2:9010": {
    "currency-converter-chf": {},
    "channelMicroservice": {},
    [...],
    "MAIN_SERVER": {}
  }
}

Through JLRMC

To communicate with jmx-extractor microservice you must create JLupinDelegator configured to connect JLupin Platform Control Center instance. Then just create communication stub with interfaces provided with JLupin JMX Extractor and call methods you want.

To get required interfaces just add Maven dependency for jmx-extractor-interfaces:

<dependency>
    <groupId>com.jlupin.microservice.partofjlupin</groupId>
    <artifactId>jmx-extractor-interfaces</artifactId>
    <version>1.6.1.0</version>
</dependency>
final JLupinDelegator jlupinDelegator = getJLupinDelegator();

final JMXExtractorService jmxExtractorService = JLupinClientUtil.generateRemote(
        jlupinDelegator, "jmx-extractor", JMXExtractorService.class
);

final Map<String, Object> all = jmxExtractorService.extractAll();

// all is a map where all field are Map or String, dump is shown below
// {
//   "192.168.0.1:9010": {
//     "currency-converter-chf": "MICROSERVICE_OUTPUT_OBJECT",
//     [...],
//     "MAIN_SERVER": "MAIN_SERVER_OUTPUT_OBJECT"
//   },
//   "192.168.0.2:9010": {
//     "currency-converter-chf": "MICROSERVICE_OUTPUT_OBJECT",
//     [...],
//     "MAIN_SERVER": "MAIN_SERVER_OUTPUT_OBJECT"
//   },
//   [...]
// }

Where MICROSERVICE_OUTPUT_OBJECT is an output with MBeans (full example can be found here: native, servlet, queue, channel) and where MAIN_SERVER_OUTPUT_OBJECT is an output with MBeans (full example can be found here).

final JLupinDelegator jlupinDelegator = getJLupinDelegator();

final Map<String, Object> mainServerAttributesMap = new HashMap<>();
{
    final Map<String, Object> map = new HashMap<>();
    map.put("ThreadCount", Boolean.TRUE);
    mainServerAttributesMap.put("java.lang:type=Threading", map);
}

final Map<String, Object> microservicesCommonAttributesMap = new HashMap<>();
{
    final Map<String, Object> map = new HashMap<>();
    map.put("StartTime", Boolean.TRUE);
    microservicesCommonAttributesMap.put("java.lang:type=Runtime", map);
}

final Map<String, Object> currencyConverterChfAttributesMap = new HashMap<>();
{
    final Map<String, Object> map = new HashMap<>();
    map.put("LoadedClassCount", Boolean.TRUE);
    currencyConverterChfAttributesMap.put("java.lang:type=ClassLoading", map);
}

final Attributes mainServerAttributes = new Attributes(mainServerAttributesMap);
final Attributes microservicesCommonAttributes = new Attributes(microservicesCommonAttributesMap);
final Attributes currencyConverterChfAttributes = new Attributes(currencyConverterChfAttributesMap);
final Map<String, Attributes> microservicesSpecificAttributes = new HashMap<>();
microservicesSpecificAttributes.put("currency-converter-chf", currencyConverterChfAttributes);

final AttributesConfiguration attributesConfiguraion = new AttributesConfiguration();

attributesConfiguraion.setAttributesMainServer(mainServerAttributes);
attributesConfiguraion.setAttributesMicroserviceCommon(microservicesCommonAttributes);
attributesConfiguraion.setAttributesMicroserviceSpecific(microservicesSpecificAttributes);

final Map<String, Object> extract = jmxExtractorService.extractSelected(attributesConfiguraion);

// extract is a map where all field are Map or String, dump is shown below
// {
//   "192.168.0.1:9010": {
//     "currency-converter-chf": {
//       "java.lang:type=ClassLoading": {
//         "LoadedClassCount": "5809"
//       },
//       "java.lang:type=Runtime": {
//         "StartTime": "1554802064316"
//       }
//     },
//     "channelMicroservice": {
//       "java.lang:type=Runtime": {
//         "StartTime": "1554802051778"
//       }
//     },
//     [...],
//     "MAIN_SERVER": {
//       "java.lang:type=Threading": {
//         "ThreadCount": "70"
//       }
//     }
//   },
//   "192.168.0.2:9010": {
//     "currency-converter-chf": {
//       "java.lang:type=ClassLoading": {
//         "LoadedClassCount": "5809"
//       },
//       "java.lang:type=Runtime": {
//         "StartTime": "1554802064316"
//       }
//     },
//     "channelMicroservice": {
//       "java.lang:type=Runtime": {
//         "StartTime": "1554802051778"
//       }
//     },
//     [...],
//     "MAIN_SERVER": {
//       "java.lang:type=Threading": {
//         "ThreadCount": "70"
//       }
//     }
//   },
//   [...]
// }