Enabling / reading cache statistics using jboss-cli.sh


I’m trying to obtain statistics about cache usage in Keycloak, but I’m not having any luck. Any pointers would be much appreciated.

What I’ve tried is to use jboss-cli.sh to configure and read cache statistics, as follows:

root@vagrant:/opt/keycloak/bin# ./jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9990 /] /subsystem=infinispan/cache-container=keycloak:write-attribute(name=statistics-enabled,value=true)
{"outcome" => "success"}

[standalone@localhost:9990 /] /subsystem=infinispan/cache-container=keycloak/local-cache=users:write-attribute(name=statistics-enabled,value=true)
{"outcome" => "success"}

[standalone@localhost:9990 /] :reload
    "outcome" => "success",
    "result" => undefined

I had expected that this would enable statistics on the local cache named ‘users’. However, even after some activity, when I try to read those statistics, I’m not seeing any data.

[standalone@localhost:9990 /] /subsystem=infinispan/cache-container=keycloak/local-cache=users:read-resource(include-runtime=true, attributes-only=true)
    "outcome" => "success",
    "result" => {
        "activations" => 0L,
        "average-read-time" => undefined,
        "average-write-time" => undefined,
        "batching" => false,
        "cache-status" => "RUNNING",
        "elapsed-time" => undefined,
        "hit-ratio" => undefined,
        "hits" => undefined,
        "indexing" => "NONE",
        "indexing-properties" => undefined,
        "invalidations" => undefined,
        "jndi-name" => undefined,
        "misses" => undefined,
        "module" => undefined,
        "number-of-entries" => undefined,
        "passivations" => 0L,
        "read-write-ratio" => undefined,
        "remove-hits" => undefined,
        "remove-misses" => undefined,
        "start" => "LAZY",
        "statistics-enabled" => true,
        "stores" => undefined,
        "time-since-reset" => undefined

As you can see, most values are undefined. What am I doing wrong?

I’m unsure if I’m doing things wrong with trying to obtain statistics this way, or if things are not functional. I don’t appear the only one with these issues. Sadly, no follow-ups seem to be posted, leaving future people looking for this in limbo.

As a work-around, I have had some success with reading statistics through JMX. I’m sharing it here in the hope that it’ll prevent someone else tumbling down the rabbit-hole…

Note that the remainder of this text is probably easily replaced with using jconsole, but the environments that I’m operating in don’t make it easy to use graphical UIs.

The people at CyclopsGroup make available a command-line JMX terminal client, which can be used to read statistics from a command line interface.

Note that statistics need to be enabled before they can be read. I’m enabling the statistics using the steps in my original post (jboss-cli.sh, write-attribute, reload), but presumably making this change in the XML configuration files also works. I’ve not tried that.

After downloading jmxterm, I’m doing the following (I’ve pruned the output a bit to improve readability):

$ java -jar jmxterm-1.0.2-uber.jar
Welcome to JMX terminal. Type "help" for available commands.

1958     (m) - jboss-modules.jar -mp /opt/keycloak/modules org.jboss.as.standalone -Djboss.home.dir=/opt/keycloak (...snip...)

$>open 1958
#Connection to 1958 is opened

$>domain org.wildfly.clustering.infinispan
#domain is set to org.wildfly.clustering.infinispan

$>bean org.wildfly.clustering.infinispan:component=Statistics,manager="keycloak",name="users(local)",type=Cache
#bean is set to org.wildfly.clustering.infinispan:component=Statistics,manager="keycloak",name="users(local)",type=Cache

$>get numberOfEntries hits misses
#mbean = org.wildfly.clustering.infinispan:component=Statistics,manager="keycloak",name="users(local)",type=Cache:
numberOfEntries = 18;

hits = 282;

misses = 272;

When statistics have not been enabled, the bean won’t be available.

1 Like