Keycloak Database Metrics

Learn about metrics describing Keycloak's connection to the database

Prerequisites

  • Metrics need to be enabled for Keycloak. Follow the Enabling Keycloak Metrics guide for more details.

  • A monitoring system collecting the metrics.

Database connection pool metrics

Configure Keycloak to use a fixed size database connection pool. See the Concepts for database connection pools guide for more information.

If there is a high count of threads waiting for a database connection, increasing the database connection pool size is not always the best option. It might overload the database which would then become the bottleneck. Consider the following options instead:

  • Reduce the number of HTTP worker threads using the option http-pool-max-threads to make it match the available database connections, and thereby reduce contention and resource usage in Keycloak and increase throughput.

  • Check which database statements are executed on the database. If you see, for example, a lot of information about clients and groups being fetched, and the users and realms cache are full, this might indicate that it is time to increase the sizes of those caches and see if this reduces your database load.

Metric Description

agroal_available_count

Idle database connections.

agroal_active_count

Database connections used in ongoing transactions.

agroal_awaiting_count

Threads waiting for a database connection to become available.

Next steps

On this page