This repository contains sample Spring Boot application that exposes metrics to Prometheus and Grafana.
The goal of this project was to showcase how to collect and monitor application's metrics running inside kubernetes or docker compose.
- Spring Boot Micrometer/Prometheus metrics integration.
- Prometheus and Grafana docker-compose set up.
- Kubernetes setup for running demo application with Prometheus Operator.
- Service monitor configuration.
- Java 11
- Docker
- Docker Compose
- Kubernetes
- Helm
Build docker image.
./gradlew bootBuildImage
-
Run docker-compose demo.
docker-compose -f ./docker/docker-compose.yml up -d
-
Check if all applications are running
docker-compose -f ./docker/docker-compose.yml ps Name Command State Ports -------------------------------------------------------------------------------------------- grafana /run.sh Up (healthy) 0.0.0.0:3000->3000/tcp hello-world-service /cnb/process/web Up 0.0.0.0:8080->8080/tcp prometheus /bin/prometheus --config.f ... Up (healthy) 0.0.0.0:9090->9090/tcp
**** all services should be up and running
-
Visit Prometheus targets page and check if hello-world-service scrapper is up and running.
-
Open your web browser and go to Grafana login page. On the login page, enter
admin
for username and password. -
Open http://localhost:3000/dashboard/import and import JVM (Micrometer) dashboard.
-
Stop demo.
docker-compose -f ./docker/docker-compose.yml down -v
-
Install Prometheus Operator inside monitoring namespace.
-
Install helm.
brew install helm
-
Add prometheus-community repo and update helm.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update
-
Create monitoring namespace inside kubernetes.
kubectl create ns monitoring
-
Install operator.
helm install -n monitoring prometheus-operator prometheus-community/kube-prometheus-stack --set prometheus-node-exporter.hostRootFsMount=false
*** --set prometheus-node-exporter.hostRootFsMount=false added to resolve this issue.
-
-
Start hello-world demo with service-monitor.
-
Create hello-world-service namespace.
kubectl apply -f ./k8s/namespace.yml
-
Apply other k8s manifests.
kubectl apply -f ./k8s
-
-
Port forward Prometheus and Grafana services.
kubectl port-forward svc/prometheus-operated 9090:9090 -n monitoring kubectl port-forward svc/prometheus-operator-grafana 3000:80 -n monitoring
-
Visit Prometheus targets page and check if hello-world-service scrapper is up and running.
-
Open your web browser and go to Grafana login page. On the login page, enter
admin
for username andprom-operator
as a password. -
Import JVM (Micrometer) dashboard.
-
Check all dashboards provided by Prometheus Operator.
-
Uninstall demo from kubernetes environment.
helm delete -n monitoring prometheus-operator kubectl delete ns monitoring kubectl delete all --all -n hello-world-service kubectl delete ns hello-world-service
- Micrometer
- Helm
- Prometheus
- kube-prometheus-stack
- kube-prometheus
- Grafana
- Grafana Dashboard - JVM (Micrometer)
- Skaffold - Github releases
- Google Cloud - Cloud Code
Distributed under the MIT License. See LICENSE
for more information.