Monitoring

Alauda Application Services Identity Management E1 exposes built-in metrics compatible with Prometheus. Enabling metrics allows you to monitor Keycloak's health, performance, and usage in your observability stack.

Enable Metrics

Metrics are enabled by setting the metrics-enabled option in the Keycloak CR:

spec:
  additionalOptions:
    - name: metrics-enabled
      value: "true"

Once enabled, Keycloak exposes a metrics endpoint on the management port (default: 9000), configurable via spec.httpManagement.port:

  • Within the cluster: http://<keycloak-service-name>.<namespace>:9000/metrics
  • From within a Pod: http://localhost:9000/metrics

The management port is separate from the main HTTP/HTTPS port.

Key Metrics

The following categories of metrics are available:

CategoryExample MetricsDescription
JVMjvm_memory_used_bytes, jvm_gc_pause_seconds, jvm_threads_live_threadsJava Virtual Machine memory, GC, and thread usage
HTTPhttp_server_requests_seconds_count, http_server_requests_seconds_sum, http_server_active_requestsRequest count, cumulative latency, and active connections. Use _count and _sum to calculate average request latency.
Databaseagroal_active_connections, agroal_awaiting_connections, agroal_max_used_connectionsDatabase connection pool usage, contention, and peak utilization
Keycloak Login Eventskeycloak_user_events_total{event="login"}, keycloak_user_events_total{event="login_error"}Authentication success and failure counts per Realm (requires --event-metrics-user-enabled=true). Use the login_error event label to monitor brute force or credential issues.
Keycloak Registrationkeycloak_user_events_total{event="register"}, keycloak_user_events_total{event="register_error"}User self-registration events per Realm
Keycloak Client Loginkeycloak_user_events_total{event="client_login"}, keycloak_user_events_total{event="client_login_error"}Service account (client credentials) authentication events
Infinispan / Cachevendor_cache_manager_*, vendor_statistics_*Distributed cache hit/miss ratios and cluster state (when cache statistics are enabled)
Native Keycloak 26.x Event Metrics

Keycloak 26.x exposes user event metrics natively via the single metric keycloak_user_events_total with an event label (for example, event="login", event="register"). Enable it by adding --event-metrics-user-enabled=true to your build or runtime options. Third-party SPI extensions such as aerogear/keycloak-metrics-spi are not required and use a different naming convention.

The following metrics are recommended as starting points for alerting rules:

IndicatorMetric / QueryAlert Condition
Login failure raterate(keycloak_user_events_total{event="login_error"}[5m])Spike above baseline indicates brute force or configuration issues
HTTP error raterate(http_server_requests_seconds_count{status=~"5.."}[5m])5xx errors above threshold indicate server problems
Database pool exhaustionagroal_awaiting_connections > 0Requests waiting for DB connections indicate pool sizing issues
JVM memory pressurejvm_memory_used_bytes / jvm_memory_max_bytes > 0.9High heap utilization may indicate memory leak or undersizing
Health probe failureKubernetes probe failure eventsLiveness or readiness probe failures indicate instance instability

Configure Prometheus Scraping

Add the following scrape configuration to your Prometheus instance to collect Keycloak metrics:

scrape_configs:
  - job_name: keycloak
    static_configs:
      - targets:
          - <keycloak-service>:9000
    metrics_path: /metrics

If you are using the Prometheus Operator, create a ServiceMonitor:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: keycloak-metrics
  namespace: <namespace>
spec:
  selector:
    matchLabels:
      app: keycloak
  endpoints:
    - port: management
      path: /metrics
      interval: 30s

Liveness and Readiness Probes

The Keycloak Operator configures liveness and readiness probes automatically. You can customize the probe parameters in the Keycloak CR:

spec:
  livenessProbe:
    periodSeconds: 10
    failureThreshold: 3
  readinessProbe:
    periodSeconds: 10
    failureThreshold: 3

The probes use the management endpoint at http://<pod>:9000/health/live and http://<pod>:9000/health/ready.

Health Endpoints

Keycloak exposes health endpoints on the management port for monitoring and orchestration:

EndpointDescription
/healthAggregated health check — returns UP only when all sub-checks (liveness, readiness) are healthy. Use as a single entry point for dashboards and external health monitors.
/health/liveReturns UP if the Keycloak process is running. Used by Kubernetes liveness probes.
/health/readyReturns UP if Keycloak is ready to serve requests (database connected, caches initialized). Used by Kubernetes readiness probes.
/health/startedReturns UP after Keycloak has completed startup. Used by Kubernetes startup probes.

Observability Integration

For a complete observability stack, combine Keycloak's built-in capabilities with cluster-level tooling:

SignalSourceTool
Metrics/metrics endpoint (Prometheus format)Prometheus, Thanos
Health/health/* endpointsKubernetes probes, uptime monitors
LogsContainer stdout/stderr (JSON or plain text)Loki, Fluentd, ELK
EventsKeycloak event system (database + listeners)See Event Auditing below
TracingOpenTelemetry (if enabled)Tempo, Jaeger
Distributed Tracing

Keycloak 26.x supports OpenTelemetry-based distributed tracing. The Keycloak Operator provides first-class tracing configuration fields in the Keycloak CR:

spec:
  tracing:
    enabled: true
    endpoint: "http://tempo.observability:4317"
    samplerType: traceidratio
    samplerRatio: 0.1

Available spec.tracing fields:

FieldDescriptionDefault
enabledEnable OpenTelemetry tracingfalse
endpointOTLP collector endpoint URL—
protocolTelemetry protocol (grpc or http/protobuf)grpc
samplerTypeSampler type (traceidratio, always_on, always_off)traceidratio
samplerRatioSampling probability (0.0 to 1.0)—
compressionPayload compression (gzip or none)disabled
serviceNameService name in exported traces—
resourceAttributesAdditional key-value attributes for trace resources—

Use spec.tracing for all standard tracing configuration. Only use additionalOptions for tracing-related options not covered by the first-class fields above.

Event Auditing

Keycloak provides a built-in event system that records login events and admin operations. Events can be stored in the database and forwarded to external listeners.

Enable Login Events

  1. In the Admin Console, go to Realm Settings > Events tab.
  2. In the User events settings section:
    • Enable Save events.
    • Set Expiration to control how long events are retained (for example, 30 days).
    • Select the Event types to record (or leave blank to record all types).
  3. Click Save.

Key Login Event Types

Event TypeDescription
LOGINSuccessful user login
LOGIN_ERRORFailed login attempt
LOGOUTUser logout
REGISTERNew user registration
CODE_TO_TOKENAuthorization code exchanged for tokens
CODE_TO_TOKEN_ERRORFailed token exchange
REFRESH_TOKENToken refresh
CLIENT_LOGINClient (service account) authentication
IMPERSONATEAdmin impersonated a user

Enable Admin Events

  1. In the Admin events settings section:
    • Enable Save events.
    • Enable Include representation to record the full request body of admin operations (useful for audit trails, but increases storage usage).
  2. Click Save.

Admin events record all operations performed via the Admin Console or Admin REST API, including resource type, operation type (CREATE, UPDATE, DELETE), and the admin user who performed the action.

View Events

  • Login events: Go to Events > User events tab. Filter by event type, user, date range, or client.
  • Admin events: Go to Events > Admin events tab. Filter by operation type, resource type, or admin user.

Event Listeners

Event listeners process events as they occur. Keycloak includes two built-in listeners:

ListenerDescription
jboss-loggingWrites events to the Keycloak server log. Useful for log aggregation systems (ELK, Loki).
emailSends email notifications to the user when specific events occur (for example, login from a new device).

Configure listeners in Realm Settings > Events > Event listeners.

Query Events via REST API

# Get recent login events
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "https://<keycloak-host>/admin/realms/<realm>/events?type=LOGIN_ERROR&first=0&max=50"

# Get admin events
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "https://<keycloak-host>/admin/realms/<realm>/admin-events?first=0&max=50"