This posts show how to monitor Spring Boot apps using Prometheus when running on Kubernetes. You should already have a running Kubernetes cluster.
$ brew install kubernetes-helm
Then you need to initialize Helm.
$ helm init
Before installing Prometheus Operator, you need to make sure the current account has the permission to manage
CustomResourceDefinitions. A simple way is to assign the role
cluster-admin to current user, see here. If you are using the default system service account, you can use the following command to create the role binding. Replace
system:serviceaccount:kube-system:default with the name of your own account.
$ kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=system:serviceaccount:kube-system:default
Now you can install Prometheus Operator using Helm.
$ helm install stable/prometheus-operator --name prometheus-operator
After installation, you can use the following command to access the Prometheus web UI on
$ kubectl port-forward prometheus-prometheus-operator-prometheus-0 9090
By default, Prometheus Operator monitors various targets of the Kubernetes cluster. To add your own targets, you need to create
You need to have a
Service for your Spring Boot application first.
The yaml file below creates a new
ServiceMonitor that matches the label
app with name
my-service. The endpoint is for Spring Boot Actuator with the path
kubectl create to create this
Please note, the label
release: prometheus-operator is important for the
ServiceMonitor to work. If you run
kubectl get prometheus -o yaml, you can see the following output. This means Prometheus Operator only selects
ServiceMonitors with the label
Now you should see the target for the Spring Boot app in the list of