3

I'm trying to setup a Prometheus exporter for Keycloak however I'm having difficulty.

I have a web based application built using docker containers and I'm now adding user permissions through the use of keycloak

I found this on github https://github.com/aerogear/keycloak-metrics-spi however I've never really used something like this in conjunction with Docker and so I'm unsure if I performed the steps in the readme correctly

Note I performed all the below steps manually.

  1. Downloaded and unzipped github repo to host machine
  2. Ran the command stated "./gradlew jar"
  3. Created a new directory inside the keycloak directory called providers
  4. Copied the jar file from /build/libs to the providers foler
  5. Went to Keycloak GUI and went to mange -> events -> config and added metrics-listener as a named entry

Based on the github repo after this I went to localhost/auth/realms/master/metrics however there was nothing there. Did I go about setting up this correctly? Alternatively, does anybody know of any other exporters which might be better suited to using a docker setup?

Thanks

1 Answer 1

3

The file needs to go into the following folder:

/opt/jboss/keycloak/standalone/deployments

Here's my InSpec test suite to validate the provider deployment:

control 'keycloak-metrics-1' do
  impact 0.6
  title 'Metrics endpoint activation script'
  desc 'The script should exist and be executable'
  tag 'keycloak','prometheus','monitoring'
  ref 'KeyCloak Metrics SPI README', url: 'https://github.com/aerogear/keycloak-metrics-spi'

  describe file('/opt/jboss/startup-scripts/enable-prometheus-exporter.sh') do
    it { should be_file }
    it { should be_executable }
  end
end

control 'keycloak-metrics-2' do
  impact 1.0
  title 'Metrics provider artifact'
  desc 'The provider jar should exist and be deployed successfully'
  tag 'keycloak','prometheus','monitoring'
  ref 'KeyCloak Metrics SPI README', url: 'https://github.com/aerogear/keycloak-metrics-spi'

  # e.g. keycloak-metrics-spi-1.0.1-SNAPSHOT.jar
  describe command('ls /opt/jboss/keycloak/standalone/deployments/*.jar').stdout.chomp do
    it { should match /keycloak-metrics-spi/ }
  end

  # e.g. keycloak-metrics-spi-1.0.1-SNAPSHOT.jar.deployed
  describe command('ls /opt/jboss/keycloak/standalone/deployments/*.deployed').stdout.chomp do
    it { should match /keycloak-metrics-spi/ }
  end
end

control 'keycloak-metrics-3' do
  impact 0.6
  title 'Metrics endpoint'
  desc 'The metrics endpoint returns expected data'
  tag 'keycloak','prometheus','monitoring'
  ref 'KeyCloak Metrics SPI README', url: 'https://github.com/aerogear/keycloak-metrics-spi'

  describe http('http://localhost:8080/auth/realms/master/metrics') do
    its('status') { should cmp 200 }
    its('body') { should match /keycloak_user_event/ }
  end
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy