This is a Docker container intended to be run in the same pod as your Java containers, to export their metrics for Prometheus.
The default CMD
copies over the required JMX Exporter files to the directory specified by the SHARED_VOLUME_PATH
environment variable.
$SHARED_VOLUME_PATH/jmx_prometheus_javaagent.jar
: the JMX Exporter javaagent JAR file.$SHARED_VOLUME_PATH/config/*.yaml
: example config files for the exporter. You can pick some here
This container is best used as an Init Container.
Add this to initContainers
of your Deployment
or StatefulSet
:
spec:
initContainers:
- name: prometheus-jmx-exporter
image: matsouch/prometheus-jmx-exporter-kubernetes:1.0.1
env:
- name: SHARED_VOLUME_PATH
value: /shared-volume
volumeMounts:
- mountPath: /shared-volume
name: shared-volume
The init container and your application container will share a volume:
volumes:
- name: shared-volume
emptyDir: {}
In your application container, set your Docker application run image params to refer to files placed by the prometheus-jmx-exporter
container into the shared volume.
Example with a Dockerfile and the camel configuration available in the repository :
ENTRYPOINT java -javaagent:/shared-volume/jmx_prometheus_javaagent.jar=9090:/shared-volume/configs/camel-config.yml -jar /app.jar
Don't forget to annotate your resources so Prometheus will scrape your pod's /metrics
endpoint:
annotations:
"prometheus.io/scrape": "true"
"prometheus.io/port": "9090"