In part 1 of this series we discussed how we can add Prometheus instrumentation to our sample Java Spring Boot application. But as someone said “Not always we have the luxury of being able to instrument our code”. Comes to rescue the Blackbox monitoring. In such situations we can use a monitoring agent(called “ Exporter ” in Prometheus world) to monitor our applications and publish all the informations available in a format that can be understood by Prometheus.
We will start of with the same uninstrumented sample Java Spring Boot application used previously. The respective code and pom.xml file for the same are as below
We will be using the official JMX Exporter by Prometheus as a java agent to monitor our application. We can either directly use a pre-built jar available in their Maven repository or we can built the jar from the source . Once we have the JMX Exporter jar we can run it with our application as:

java -javaagent:<path-to-the-jmx_exporter.jar>=<port>:<path-to-the-jmx_exporter_config.yaml> -jar <yourApplication.jar>

<port> specifies the port number at which the JMX Exporter will be exposing your the metrics. You can use <host>:<port> to bind it to a specific IP address. <path-to-the-jmx_exporter_config.yaml> specifies a YAML configuration file that the JMX Exporter uses. A minimal configuration {} is required, which will make the exporter process all mBeans collecting everything from the local JVM in the default format irrespective of whether they are exported or not exported.
You can refer to the official documentation for a complete overview of the options that you can use in the configuration file. A good configuration to start with can be the minimalistic httpserver_sample configuration that can be found in the repo’s example folder along with some other example configurations.
Once it’s all setup, ready and rolling you can find the exposed metrics at the <port> specified which now can be easy consumed and processed by Prometheus.

This content was originally published here.