Add keycloak online/offline sessions records#74
Conversation
| PrometheusExporter.instance().recordGenericEvent(event); | ||
| } | ||
|
|
||
| setSessions(session.realms().getRealm(event.getRealmId())); |
There was a problem hiding this comment.
does this have to be executed for every event? Maybe there are certain events that indicate a change in sessions like logins / logouts?
There was a problem hiding this comment.
Our Keycloak cluster is not configured to replicate sessions on all nodes.
If the Login is on one node, and the logout on an other. Until a new login or logout on the fist node, the sessions metrics is not updated for this node.
It's the reason why there is no filter on event's type.
I don't found a better solution to update the metrics in our cluster.
| Map<String,Long> map1 = Map.of("account", new Long(10), "admin-cli", new Long(0)); | ||
| Map<String,Long> map2 = Map.of("account", new Long(0), "admin-cli", new Long(10)); |
There was a problem hiding this comment.
- sourceCompatibility = 1.8(build.gradle:20)
Map.of()is supported since Java 9
There was a problem hiding this comment.
I rewrite it with :
Map<String,Long> map1 = new HashMap<String, Long>() {{
put("account", new Long(10));
put("admin-cli", new Long(0));
}};
Is it better ?
|
@jermarchand I tried it and it seems to work, only one question: when does a session count as offline? I logged in and then closed the tab but the counter is still counting it as online: |
|
Closing a tab does not send a disconnection request. When a ClientId has no more sessions it does not appear in the response of "getActiveClientSessionStats" so it might be necessary to send a metric to 0 for all existing clients .... On one of our Keycloak clusters where we tested this metrics, we had a crash for several reasons (mem + network + ..). I don't know if this PR should be merged until someone do more tests. |
|
@jermarchand Is this PR still relevant? |
Motivation
Add online/offline sessions by realm and clientId. Similar to #51
What
Add 2 Gauge :
Why
Show the number of sessions
How
On each user/admin events, put in a Gauge the result of the
getActiveClientSessionStats.Verification Steps
Add the steps required to check this change. Following an example.
Checklist:
Progress
Additional Notes
I'm a newby with Prometheus metrics, so fell free to comment and propose better implementation.
The
getActiveClientSessionStatscontains only ClientId with active sessions. When all sessions of this client are logout, I don't found a solution to set the metric to0.0.