apache/shenyu · warning · ShenyuException

Error retrieving system information: " + e.getMessage()

Error message

Error retrieving system information: " + e.getMessage()

What it means

SystemInfoUtils.getSystemInfo collects OS/Java runtime metrics (processors, memory) via OperatingSystemMXBean and returns them as JSON. Any exception during metric collection is wrapped in ShenyuException 'Error retrieving system information: <message>'.

Solutions

  1. Upgrade/verify the JDK supports com.sun.management.OperatingSystemMXBean methods used (Java 14+ renamed get{Total,Free}PhysicalMemorySize variants).
  2. Catch and degrade gracefully: return partial system info instead of throwing.
  3. Run on a supported platform/JDK combination matching ShenYu's requirements (Java 17).
  4. Inspect the wrapped message (e.getMessage) to identify the specific MXBean call that failed.

Example fix

// before
String info = SystemInfoUtils.getSystemInfo(); // may throw
// after
String info;
try {
    info = SystemInfoUtils.getSystemInfo();
} catch (Exception e) {
    LOG.warn("system info unavailable: {}", e.getMessage());
    info = "{}";
}
Defensive patterns

Strategy: fallback

Try / catch

try { String info = SystemInfoUtils.getSystemInfo(); } catch (ShenyuException e) { LOG.warn("system info unavailable: {}", e.getMessage()); info = "{}"; }

Prevention

When it happens

Trigger: Calling getSystemInfo on a JVM/platform where the MXBean methods (getTotalMemorySize, etc.) are unavailable or throw, or when JSON serialization of the collected map fails.

Common situations: Running on an older JDK where the OS bean method names differ (com.sun.management.OperatingSystemMXBean API changes); restricted containers blocking MXBean access; custom MBean server setups.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/119e1ec14b0fdadf. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-common/src/main/java/org/apache/shenyu/common/utils/SystemInfoUtils.java:72

     */
    public static String getSystemInfo() {
        try {
            // Get host information using OSHI
            SystemInfo systemInfo = new SystemInfo();

            // Get host information
            OperatingSystemMXBean osBean =
                    (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
            Map<String, Object> hostInfo = Map.of(
                    ARCH, osBean.getArch(),
                    OPERATING_SYSTEM, systemInfo.getOperatingSystem().toString(),
                    AVAILABLE_PROCESSORS, osBean.getAvailableProcessors(),
                    TOTAL_MEMORY_SIZE_GB, bytesToGB(osBean.getTotalMemorySize()) + GB
            );
            return GsonUtils.getInstance().toJson(hostInfo);
        } catch (Exception e) {
            // Handle any exceptions that may occur
            throw new ShenyuException("Error retrieving system information: " + e.getMessage());
        }
    }

    /**
     * Bytes to gb double.
     *
     * @param bytesValue the bytes value
     * @return the double
     */
    private static double bytesToGB(final long bytesValue) {
        return BigDecimal.valueOf(bytesValue / (double) BYTES_IN_GB)
                .setScale(DECIMAL_PLACES, ROUNDING_MODE)
                .doubleValue();
    }
}

View on GitHub (pinned to 567142e072)