From 5b027d7054cfc030eb10f072d952d8732c18ca2f Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 3 Jun 2025 18:41:40 +0200 Subject: [PATCH] Add cpu info to serverinfo (#40208) Fixes #40208 Signed-off-by: Thomas Darimont --- .../info/CpuInfoRepresentation.java | 21 +++++++++++++++++++ .../info/ServerInfoRepresentation.java | 9 ++++++++ .../admin/messages/messages_en.properties | 2 ++ js/apps/admin-ui/src/dashboard/Dashboard.tsx | 13 ++++++++++++ .../src/defs/serverInfoRepesentation.ts | 5 +++++ .../admin/info/ServerInfoAdminResource.java | 2 ++ 6 files changed, 52 insertions(+) create mode 100644 core/src/main/java/org/keycloak/representations/info/CpuInfoRepresentation.java diff --git a/core/src/main/java/org/keycloak/representations/info/CpuInfoRepresentation.java b/core/src/main/java/org/keycloak/representations/info/CpuInfoRepresentation.java new file mode 100644 index 000000000000..7cd43fdd288d --- /dev/null +++ b/core/src/main/java/org/keycloak/representations/info/CpuInfoRepresentation.java @@ -0,0 +1,21 @@ +package org.keycloak.representations.info; + +public class CpuInfoRepresentation { + + protected long processorCount; + + public static CpuInfoRepresentation create() { + Runtime runtime = Runtime.getRuntime(); + CpuInfoRepresentation rep = new CpuInfoRepresentation(); + rep.setProcessorCount(runtime.availableProcessors()); + return rep; + } + + public long getProcessorCount() { + return processorCount; + } + + public void setProcessorCount(long processorCount) { + this.processorCount = processorCount; + } +} diff --git a/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java b/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java index adb152098dc8..a20bed5d73df 100755 --- a/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/info/ServerInfoRepresentation.java @@ -31,6 +31,7 @@ public class ServerInfoRepresentation { private SystemInfoRepresentation systemInfo; + private CpuInfoRepresentation cpuInfo; private MemoryInfoRepresentation memoryInfo; private ProfileInfoRepresentation profileInfo; @@ -71,6 +72,14 @@ public void setMemoryInfo(MemoryInfoRepresentation memoryInfo) { this.memoryInfo = memoryInfo; } + public CpuInfoRepresentation getCpuInfo() { + return cpuInfo; + } + + public void setCpuInfo(CpuInfoRepresentation cpuInfo) { + this.cpuInfo = cpuInfo; + } + public ProfileInfoRepresentation getProfileInfo() { return profileInfo; } diff --git a/js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/messages/messages_en.properties b/js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/messages/messages_en.properties index cb28c3b89d73..ce7f878d8525 100644 --- a/js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/messages/messages_en.properties +++ b/js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/messages/messages_en.properties @@ -501,6 +501,8 @@ protocolTypes.openid-connect=OpenID Connect clientTypeHelp='OpenID Connect' allows Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server.'SAML' enables web-based authentication and authorization scenarios including cross-domain single sign-on (SSO) and uses security tokens containing assertions to pass information. addOpenIdProvider=Add OpenID Connect provider memory=Memory +cpu=CPU +processorCount=Processor Count eventTypes.CLIENT_LOGIN.name=Client login mapper.nameid.format.tooltip=This mapper is applied only if the NameID format of the incoming AuthnRequest is equal to this value. hideOnLoginPageHelp=If hidden, login with this provider is possible only if requested explicitly, for example using the 'kc_idp_hint' parameter. diff --git a/js/apps/admin-ui/src/dashboard/Dashboard.tsx b/js/apps/admin-ui/src/dashboard/Dashboard.tsx index 5e0e24c28a41..5d66b254eb9a 100644 --- a/js/apps/admin-ui/src/dashboard/Dashboard.tsx +++ b/js/apps/admin-ui/src/dashboard/Dashboard.tsx @@ -239,6 +239,19 @@ const Dashboard = () => { + {t("cpu")} + + + + + {t("processorCount")} + + + {serverInfo.cpuInfo?.processorCount} + + + + {t("memory")} diff --git a/js/libs/keycloak-admin-client/src/defs/serverInfoRepesentation.ts b/js/libs/keycloak-admin-client/src/defs/serverInfoRepesentation.ts index 5cfed263c06a..f63d9f462351 100644 --- a/js/libs/keycloak-admin-client/src/defs/serverInfoRepesentation.ts +++ b/js/libs/keycloak-admin-client/src/defs/serverInfoRepesentation.ts @@ -11,6 +11,7 @@ import type SystemInfoRepresentation from "./systemInfoRepersantation.js"; */ export interface ServerInfoRepresentation { systemInfo?: SystemInfoRepresentation; + cpuInfo?: CpuInfoRepresentation; memoryInfo?: MemoryInfoRepresentation; profileInfo?: ProfileInfoRepresentation; features?: FeatureRepresentation[]; @@ -63,6 +64,10 @@ export interface MemoryInfoRepresentation { freeFormated: string; } +export interface CpuInfoRepresentation { + processorCount: number; +} + export interface ProtocolMapperTypeRepresentation { id: string; name: string; diff --git a/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java index 609aece9aa25..8ae5388a3707 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/info/ServerInfoAdminResource.java @@ -52,6 +52,7 @@ import org.keycloak.representations.idm.ProtocolMapperRepresentation; import org.keycloak.representations.idm.ProtocolMapperTypeRepresentation; import org.keycloak.representations.info.ClientInstallationRepresentation; +import org.keycloak.representations.info.CpuInfoRepresentation; import org.keycloak.representations.info.CryptoInfoRepresentation; import org.keycloak.representations.info.FeatureRepresentation; import org.keycloak.representations.info.FeatureType; @@ -110,6 +111,7 @@ public ServerInfoAdminResource(KeycloakSession session) { public ServerInfoRepresentation getInfo() { ServerInfoRepresentation info = new ServerInfoRepresentation(); info.setSystemInfo(SystemInfoRepresentation.create(session.getKeycloakSessionFactory().getServerStartupTimestamp(), Version.VERSION)); + info.setCpuInfo(CpuInfoRepresentation.create()); info.setMemoryInfo(MemoryInfoRepresentation.create()); info.setProfileInfo(createProfileInfo()); info.setFeatures(createFeatureRepresentations());