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:

  scrape_interval: 15s

scrape_configs:
  - job_name: 'keycloak'
    metrics_path: '/metrics'
    static_configs:
      - targets: ['host.docker.internal:9000']   # hostname or IP of your Keycloak instance


And then we will setup grafana

docker run --rm --name grafana -p 3000:3000  grafana/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

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type