Overview
/metrics
endpoint and poll the data.Setting up the (server) runtimes to be monitored
WildFly Swarm
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.
OpenLiberty
$ bin/server create mp --template=microProfile1
/metrics
endpoint is secured by default on OpenLiberty.usr/servers/mp1/server.xml
inside the <server>
element.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.yml
with 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']
$prometheus -config.file=prom.yml
http://localhost:9090/
.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).
Conclusion
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.