madhumitha jarugu
madhumitha jarugu

Reputation: 21

can we enable metrics-listener for keycloak, not via GUI but from cli scripts ? having keycloack from codecentric repo

Keycloak version: 8.2.2 from codecentric

I copied keycloak-metrics-spi-2.5.0.jar to path -/opt/jboss/keycloak/standalone/deployments/ inside pod

and after deployement saw keycloak-metrics-spi-2.5.0.jar.deployed

logs of keycloak for metrics spi:

20:58:04,519 INFO [org.wildfly.extension.microprofile.metrics.smallrye] (ServerService Thread Pool -- 50) WFLYMETRICS0001: Activating Eclipse MicroProfile Metrics Subsystem 20:58:05,342 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: Starting deployment of "keycloak-metrics-spi-2.5.0.jar" (runtime-name: "keycloak-metrics-spi-2.5.0.jar") 20:58:05,913 INFO [org.keycloak.subsystem.server.extension.KeycloakProviderDeploymentProcessor] (MSC service thread 1-1) Deploying Keycloak provider: keycloak-metrics-spi-2.5.0.jar 20:58:09,334 WARN [org.keycloak.services] (ServerService Thread Pool -- 61) KC-SERVICES0047: metrics (org.jboss.aerogear.keycloak.metrics.MetricsEndpointFactory) is implementing the internal SPI realm-restapi-extension. This SPI is internal and may change without notice 20:58:09,337 WARN [org.keycloak.services] (ServerService Thread Pool -- 61) KC-SERVICES0047: metrics-listener (org.jboss.aerogear.keycloak.metrics.MetricsEventListenerFactory) is implementing the internal SPI eventsListener. This SPI is internal and may change without notice 20:58:16,147 INFO [org.jboss.as.server] (ServerService Thread Pool -- 35) WFLYSRV0010: Deployed "keycloak-metrics-spi-2.5.0.jar" (runtime-name : "keycloak-metrics-spi-2.5.0.jar")

I added below line in pre-scripts, and observed metrics-event listener is not comming, though can be seen in siggestions,

add metrics listener

/subsystem=keycloak-server/spi=eventsListener/provider=metrics-listener:add(enabled=true)

Expecting is to have metrics-listener on GUI, dynamically not by manually adding it on GUI enter image description here

can some one help here please ?

Upvotes: 2

Views: 770

Answers (1)

Sirish Kumar Bethala
Sirish Kumar Bethala

Reputation: 9279

You can use Keycloak API to do this

PUT /auth/admin/realms/test/events/config HTTP/1.1
Content-Type: application/json
Authorization: Bearer <token>
Host: auth.localhost

{
    "eventsListeners": [
            "metrics-listener"
    ]
}

You can generate the bearer token using following API

POST /auth/realms/master/protocol/openid-connect/token?= HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: auth.localhost
Content-Length: 69

grant_type=password&username=admin&password=admin&client_id=admin-cli

Upvotes: 1

Related Questions