Skip to content

Commit

Permalink
KEYCLOAK-10120: enable statistics with env variable.
Browse files Browse the repository at this point in the history
Signed-off-by: Cédric Couralet <[email protected]>
  • Loading branch information
micedre authored and Bruno Oliveira da Silva committed Sep 3, 2019
1 parent 2d9e6d6 commit 14e07f8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,19 @@ It is also possible to provide an additional CA bundle and setup Mutual TLS this

NOTE: See `openshift-examples` directory for an out of the box setup for OpenShift.

### Enable some metrics

Keycloak image can collect some statistics for various subsystem which will then be available in the management console and the `/metrics` endpoint.
You can enable it with the KEYCLOAK_STATISTICS environment variables which take a list of statistics to enable:
* `db` for the `datasources` subsystem
* `http` for the `undertow` subsystem
* `jgroups` for the `jgroups` subsystem

for instance, `KEYCLOAK_STATISTICS=db,http` will enable statistics for the datasources and undertow subsystem.

The special value `all` enables all statistics.

Once enabled, you should see the metrics values changing on the `/metrics` endpoint for the management endpoint.

## Other details

Expand Down
5 changes: 5 additions & 0 deletions server/tools/cli/metrics/db.cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
embed-server --server-config=standalone-ha.xml --std-out=echo
batch
/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=statistics-enabled, value=true)
run-batch
stop-embedded-server
5 changes: 5 additions & 0 deletions server/tools/cli/metrics/http.cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
embed-server --server-config=standalone-ha.xml --std-out=echo
batch
/subsystem=undertow:write-attribute(name=statistics-enabled,value=true)
run-batch
stop-embedded-server
5 changes: 5 additions & 0 deletions server/tools/cli/metrics/jgroups.cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
embed-server --server-config=standalone-ha.xml --std-out=echo
batch
/subsystem=jgroups/channel=ee:write-attribute(name=statistics-enabled, value=true)
run-batch
stop-embedded-server
9 changes: 9 additions & 0 deletions server/tools/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ if [ -z "$BIND_OPTS" ]; then
fi
SYS_PROPS+=" $BIND_OPTS"

#########################################
# Expose management console for metrics #
#########################################

if [ -n "$KEYCLOAK_STATISTICS" ] ; then
SYS_PROPS+=" -Djboss.bind.address.management=0.0.0.0"
fi

#################
# Configuration #
#################
Expand Down Expand Up @@ -203,6 +211,7 @@ fi

/opt/jboss/tools/x509.sh
/opt/jboss/tools/jgroups.sh
/opt/jboss/tools/statistics.sh
/opt/jboss/tools/autorun.sh

##################
Expand Down
12 changes: 12 additions & 0 deletions server/tools/statistics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

if [ -n "$KEYCLOAK_STATISTICS" ]; then
IFS=',' read -ra metrics <<< "$KEYCLOAK_STATISTICS"
for file in /opt/jboss/tools/cli/metrics/*.cli; do
name=${file##*/}
base=${name%.cli}
if [[ $KEYCLOAK_STATISTICS == *"$base"* ]] || [[ $KEYCLOAK_STATISTICS == *"all"* ]]; then
$JBOSS_HOME/bin/jboss-cli.sh --file="$file" >& /dev/null
fi
done
fi

0 comments on commit 14e07f8

Please sign in to comment.