Session Tracking
The session tracking feature allows monitoring the maximum number of simultaneous users' sessions.
How it works
In the provided Keycloak, the platform has included a Keycloak SPI (Service Provider Interface) that emits an AMQP message when the number of sessions is updated, for instance:
When a user logs in
When a user logs out
...
Note that no messages are emitted when a session expires.
Usage
The scenario-service listens to emitted messages and stores them in a MongoDB collection.
By default, there are two ways to view the stored messages:
by configuring the log level
by using a dedicated REST endpoint
The stored data are automatically deleted after 2 years.
Logs
To check any updates on the number of active sessions, you need to set the log level to debug for the
class com.decisionbrain.keycloak.spi.event.consumer.impl.LoggerConsumer
In your application.yml of the scenario service extension, add the following:
logging:
level:
com.decisionbrain.keycloak.spi.event.consumer.impl.LoggerConsumer: DEBUGREST endpoint
If needed, an endpoint can give metrics about any user session. To access these metrics, you need
to be logged in as a user that has the role SESSION_TRACKING.
Then, you can call the endpoint /api/scenario/session-tracking/aggregation. This endpoint will
respond a JSON having the following format:
{
"min": 4,
"max": 8
}You can filter out the results by giving a start and an end parameter to the endpoint. These parameters
represent timestamps.
For example:
/api/scenario/session-tracking/aggregation?start=1651356000000&end=1653948000000