Coder Social home page Coder Social logo

keycloak-monitoring-prometheus's Introduction

Release Number of Downloads

keycloak-monitoring-prometheus

Out of the box, keycloak does not expose any metrics about what it is doing. It does however allow you to write code that is listening to all kinds of keycloak-internal events. This project counts those events and allows you to expose them to prometheus with the prometheus-filesystem-exporter.

What metrics do you get?

This project will help you expose two metrics:

The magic lies in the labels. The labels basically expose the underlying keycloak event details and allow for detailed filtering. The unique metric + label combination's value will be increased by one whenever an event of this type is emmited in keycloak.

Setup

Install SPI

The code in this project compiles into an SPI that needs to be installed to your keycloak instance. The simplest way is to download the latest JAR from jitpack.io and put it into your keycloak installation directory/providers. Detailled instructions on SPI installation can be found in the keycloak docs. Also make sure to check out the Dockerfile.

Configure SPI

The SPI requires you to provide a configuration option describing where to write the event counter files.

Configuring in standalone.xml

SPI configuration happens in keycloaks standalone.xml. Within <subsystem xmlns="urn:jboss:domain:keycloak-server:1.1"></subsystem> you need to add the following lines:

<spi name="eventsListener">
    <provider name="com.larscheidschmitzhermes:keycloak-monitoring-prometheus" enabled="true">
        <properties>
            <property name="eventsDirectory" value="/metrics"/>
         </properties>
    </provider>
</spi>

For a more advanced example (directory name read from env variable) see the Dockerfile again.

Configuring using an environment variable

The metrics directory can be specified by setting the KEYCLOAK_PROMETHEUS_EVENTS_DIR environment variable. This value will only be used if the eventsDirectory configuration value is not set or if it is an empty string.

Configuration in keycloak

setup In keycloak's admin console under Events > Config you need to add com.larscheidschmitzhermes:keycloak-monitoring-prometheus as an Event Listener. Make sure you do this for every realm you want to monitor!

Configuring using Keycloak CLI

Keycloak supports scripting of configuration changes via CLI. This has the benefit of decoupling configuration changes from the deployed keycloak version allowing easy upgrades of binaries. This is especially beneficial in a containerized environment.

Using CLI to configure Keycloak

To configure the Prometheus exporter via CLI see Dockerfile. The content of jboss-cli is added with jboss-cli.sh and embed-server mode. During docker build you will see Keycloak adding the configuration entries to standalone.xml. For more information refer to Keycloak documentation

Getting your metrics into prometheus

Once everything is setup in keycloak, you will start seeing files like keycloak_admin_events_total;realm=master;operation=CREATE;resource=USER in your configured events directory. These files contain a number stating how often an event with the given parameters was emitted. The naming scheme is compatible with prometheus-filesystem-exporter, which you should run next to keycloak to get your events exposed in a prometheus compatible format.

keycloak-monitoring-prometheus's People

Contributors

hypery2k avatar joyrex2001 avatar msglueck avatar tobilarscheid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.