keycloak - viewing metrics via prometheus and grafana
First of all let's start keycloak
docker run --rm -p 127.0.0.1:8080:8080 -p 9000:9000 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin -e KC_METRICS_ENABLED=true quay.io/keycloak/keycloak:26.4.4 start-dev --metrics-enabled=true --http-enabled=true --hostname-strict=false
Next we will setup prometheus to scap keycloak metrics.
docker run --rm --name prometheus -p 9090:9090 -v ${pwd}/pm.yaml:/etc/prometheus/prometheus.yml prom/prometheus
The content for prometheus.yml are as follows (since i am using docker, so my target would be host.docker.internal:9000)
global:
And then we will setup grafana
Once everything is setup and running in docker, goto check if keycloak metrics is up by opening your browser and hitting http://localhost:9000/metrics. You will see something similiar.
And test if prometheus is working by going to Status -> Target Health. Your target should be up.
And then go into http://localhost:3000 and login to grafana using default username and password which is admin and admin. Then proceed to Add a connection.
And configure prometheus server url
And when you click "Save and test" you should see this here:-
Let's see some metrics on your keycloak by clicking on "Explore".
Once the page has been loaded, proceed to select the metrics you wanted. In this example, we selected cache size and then hit "execute query".And you will see this here.
Comments