Example Spring Boot Actuator app with Prometheus on Kubernetes
10K+
inspired by
Do note that this does not seem to work well with Spring Boot 2.x (e.g. 2.0.0.M6)
If you wish to run Grafana and Prometheus (https://prometheus.io/docs/visualization/grafana/) locally, you'll need to install them.
To run Grafana locally, use:
grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins
And then visit http://0.0.0.0:3000/login with admin / admin
Once this application is running, visit http://localhost:8080/health
Custom metrics we're interested in having in the near future
Features:
| Name | Default | Description |
|---|---|---|
| DEBUG | false | Enable or disable debug mode |
| DEBUG_PORT | 8000 | Debug port |
| JMX | false | Enable or disable jmx mode |
| JMX_PORT | 9010 | Debug port |
| SPRING_PROFILES_ACTIVE | dev | Active Spring profiles |
| JAVA_OPTS | JAVA_OPTS | |
| SERVER_PORT | 8080 | Spring Boot application server port (server.port) |
Build the image with mvn package and push it with mvn deploy. Of course you can also say
mvn dockerfile:build explicitly. This uses dockerfile-maven.
Start your application:
Using Docker CLI
Using the provided docker-compose.yml in this repository:
docker-compose -f compose/docker-compose.yml up
docker run -d -p 8080:8080 -e JAVA_OPTS=-Xms256m -Xmx512m spring-boot-image
The docker-compose.yml file picks its configuration from the .env one.
Using this file, you can set the desired properties:
# Docker
IMAGE_NAME=stevenacoffman/prometheus-spring-actuator
# Application
SERVER_PROTOCOL=http
SERVER_PORT=8080
DEBUG_PORT=8000
JMX_PORT=9010
SPRING_PROFILES_ACTIVE=dev
DEBUG=false
JMX=false
# -Dprop=... -Dparameter=...
JAVA_OPTS=
# Host
HOST_SERVER_PORT=8080
HOST_DEBUG_PORT=8000
HOST_JMX_PORT=9010
To run the application in debug mode, simply set the DEBUG variable to true in the .env file.
Launch the application:
docker-compose -f compose/docker-compose.yml up
By default, the debug port used is the 8000.
To run the application in JMX mode, simply set the JMX variable to true in the .env file.
Launch the application:
docker-compose -f compose/docker-compose.yml up
By default, the debug port used is the 9010.
By default, the application will run with dev Spring profile
To run the application with a specific Spring profile, set the desired one in the .env file:
SPRING_PROFILES_ACTIVE=dev
$ kubectl apply -f ./k8s
Add the proper annotations to your deployment to inform prometheus what and where to scrape:
spec:
replicas: 1 # tells deployment to run 2 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
run: prometheus-spring-actuator
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8888"
Content type
Image
Digest
Size
84.2 MB
Last updated
almost 9 years ago
docker pull stevenacoffman/prometheus-spring-actuator