class SessionRegistryDiagnosticService implements Diagnostic {

    public Map<DiagnosticAttribute, DiagnosticCallback> getDiagnosticData() {
        return new DiagnosticAttributeBuilder()
            .addDiagnosticAttribute(DiagnosticAttributeBuilder.TOTAL_LOGGED_IN_USERS, new DiagnosticCallback<Integer>() {
                @Override
                public Integer getDiagnosticAttributeValue() {
                    return sessionRegistry.getAllPrincipals().size();
                }
            })
            .addDiagnosticAttribute(DiagnosticAttributeBuilder.TOTAL_SESSIONS_BY_USER, new DiagnosticCallback<Map<String, Integer>>() {
                @Override
                public Map<String, Integer> getDiagnosticAttributeValue() {
                    Map<String, Integer> sessionsCountForUser = new HashMap<String, Integer>();
                    for (Object principle : sessionRegistry.getAllPrincipals()) {
                        sessionsCountForUser.put(principle.toString(), sessionRegistry.getAllSessions(principle, false).size());
                    }
                    return sessionsCountForUser;
                }
            }).build();
    }

}