How to monitor an Eclipse MicroProfile 1.2 server with Prometheus
/metricsendpoint and poll the data.
Setting up the (server) runtimes to be monitored
java -jar application-swarm.jar. To enable the MicroProfile Metrics to support, you need to pull in the MicroProfile fraction in your build.
mvn install, which will create the usual uber-jar in a target.
WFSWARM0013: Installed fraction: Microprofile-Metrics - EXPERIMENTAL org.wildfly.swarm:microprofile-metrics:2017.11.0-SNAPSHOT
Once the server is ready, it is exposing metrics under
http://localhost:8080/metrics by default.
$ bin/server create mp --template=microProfile1
/metricsendpoint is secured by default on OpenLiberty.
When this is done, you can start the server via
bin/server run mp. With the standard settings, the metrics can then be found under
https://localhost:9443/metrics. Credentials are
theUser/thePassword as seen in line 2 of the above snippet.
Setting up Prometheus
prom.ymlwith the following content:
scrape_configs: # Configuration to poll from WildFly Swarm - job_name: 'swarm' scrape_interval: 15s # translates to http://localhost:8080/metrics static_configs: - targets: ['localhost:8080'] # Configuration to poll from OpenLiberty - job_name: 'liberty' scrape_interval: 15s scheme: https basic_auth: username: 'theUser' password: 'thePassword' tls_config: insecure_skip_verify: true # translates to https://localhost:9443/metrics static_configs: - targets: ['localhost:9443']
In the last chart, you can see that we only asked for the metric,
base:memory_used_heap_bytes but got two graphs, one per MP-server, as both expose the same metric under the same name. Prometheus is adding labels on the fly, which can then be used to distinguish the servers (green is OpenLiberty, brown is Swarm).
MicroProfile Metrics defines a common way to expose metrics from systems. Monitoring tools like Prometheus are thus easily able to monitor those servers in a vendor-independent way.
At the time of this article, the MP-Metrics code may not yet be in a Swarm release but will be soon.
To build your Java EE Microservice visit WildFly Swarm and download the cheat sheet.
Join the Red Hat Developer Program (it's free) and get access to related cheat sheets, books, and product downloads.
To learn more, visit our Join the Red Hat Developer Program (it's free) and get access to related cheat sheets (e.g. containers), books (e.g. microservices), and product downloads that can help you with your microservices and/or container application development.