Open jermarchand opened 3 years ago
@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:
keycloak_online_sessions{realm="user_realm",client_id="account",} 1.0
Closing a tab does not send a disconnection request. When a session is terminated due to "SSO Session Idle", no event is generated :(
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 + ..). Today we do not know if one of these reasons is to have called too much the "getActiveClientSessionStats" which is not stable when there are more than 500,000 sessions.
I don't know if this PR should be merged until someone do more tests.
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
getActiveClientSessionStats
contains 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
.