Skip to content

Commit

Permalink
Keycloak: Simplify userSessions counting in metrics collection
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdarimont committed May 17, 2023
1 parent 1289228 commit 0531e5c
Showing 1 changed file with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,8 @@ public void updateRealmMetrics(KeycloakSession session, RealmMetricUpdater metri

private RealmSessionStats collectRealmSessionStats(KeycloakSession session, RealmModel realm) {

Map<String, Long> userSessionsCounts = session.sessions().getActiveClientSessionStats(realm, false);
Map<String, Long> offlineUserSessionCounts = session.sessions().getActiveClientSessionStats(realm, false);

long userSessionsCount = 0L;
for (var entry : userSessionsCounts.entrySet()) {
userSessionsCount += entry.getValue();
}

long offlineSessionsCount = 0L;
for (var entry : offlineUserSessionCounts.entrySet()) {
offlineSessionsCount += entry.getValue();
}
var userSessionsCount = session.sessions().getActiveClientSessionStats(realm, false).values().stream().reduce(0L, Long::sum);
var offlineSessionsCount = session.sessions().getActiveClientSessionStats(realm, false).values().stream().reduce(0L, Long::sum);

return new RealmSessionStats(userSessionsCount, offlineSessionsCount);
}
Expand Down

0 comments on commit 0531e5c

Please sign in to comment.