This is a spring boot sample app with attached [prometheus_jmx] (https://github.com/prometheus/jmx_exporter) agent. Agent exposes JVM metrics to 10245 ports. When the app is deployed on k8s cluster Prometheus automatically reads metrics and makes them available for query.
PS (If this gist will collect 100 starts I will make deeper blog post in this topic)
mvn clean package
docker build -t prometheus-java-sample .
docker run -d -p 8080:8080 -p 10254:10254 prometheus-java-sample
curl 127.0.0.1:8080
curl 127.0.0.1:10254/metrics
eval $(aws ecr --profile=prod get-login --no-include-email --region eu-central-1)
docker tag prometheus-java-sample 11122233.dkr.ecr.eu-central-1.amazonaws.com/repo:prometheus-java-sample
docker push 11122233.dkr.ecr.eu-central-1.amazonaws.com/repo:prometheus-java-sample
kubectl create -f app.yaml
jvm_memory_bytes_used{app="pro-java-sample",area="heap"}