From dd7fe635bfc0a576021cec8f81bacdafeeeb9f58 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Tue, 22 Jun 2010 13:40:52 +0000 Subject: QPID-2555 : Improvements on info plugin, using SOAP Patch provided by Sorin Suciu git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@956887 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/qpid/info/SystemInfo.java | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java (limited to 'qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java') diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java new file mode 100644 index 0000000000..25095b62dc --- /dev/null +++ b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java @@ -0,0 +1,90 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.qpid.info; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; +import java.util.Map.Entry; + +/** + * Collector for system specific information + */ +public class SystemInfo +{ + + private static Map sysInfoMap = new TreeMap(); + + private static final List sysProps = Arrays.asList( + "java.class.path", "java.home", "java.vm.name", "java.vm.vendor", + "java.vm.version", "java.class.version", "java.runtime.version", + "os.arch", "os.name", "os.version", "sun.arch.data.model", + "user.home", "user.dir", "user.name", "user.timezone"); + + /** + * getInfo collects all the properties specified in sysprops list + * @return A Map + */ + public static Map getInfo() + { + + // Get the hostname + try + { + InetAddress addr = InetAddress.getLocalHost(); + String hostname = addr.getHostName(); + sysInfoMap.put("hostname", hostname); + sysInfoMap.put("ip", addr.getHostAddress()); + } catch (UnknownHostException e) + { + // + } + // Get the runtime info + sysInfoMap.put("CPUCores", Runtime.getRuntime().availableProcessors() + + ""); + sysInfoMap.put("Maximum_Memory", Runtime.getRuntime().maxMemory() + ""); + sysInfoMap.put("Free_Memory", Runtime.getRuntime().freeMemory() + ""); + + // Gather the selected system props + Properties sysprops = System.getProperties(); + String propName; + for (Iterator> it = sysprops.entrySet() + .iterator(); it.hasNext();) + { + Entry en = it.next(); + propName = en.getKey().toString(); + if (sysProps.indexOf(propName) >= 0) + { + sysInfoMap.put(propName, en.getValue().toString()); + } + } + + return sysInfoMap; + + } + +} -- cgit v1.2.1 From b3c9cdb55d0c0f054bc4329f51492c0bee001ada Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Tue, 22 Jun 2010 13:42:41 +0000 Subject: Qpid-2555 Patch 4 provided by Sorin Suciu, based on local review comments git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@956893 13f79535-47bb-0310-9956-ffa450edef68 --- .../info/src/main/java/org/apache/qpid/info/SystemInfo.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java') diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java index 25095b62dc..8bd94fe14d 100644 --- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java +++ b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java @@ -32,7 +32,7 @@ import java.util.TreeMap; import java.util.Map.Entry; /** - * Collector for system specific information + * Collector for system specific information */ public class SystemInfo { @@ -46,8 +46,8 @@ public class SystemInfo "user.home", "user.dir", "user.name", "user.timezone"); /** - * getInfo collects all the properties specified in sysprops list - * @return A Map + * getInfo collects all the properties specified in sysprops list + * @return A Map */ public static Map getInfo() { @@ -59,9 +59,10 @@ public class SystemInfo String hostname = addr.getHostName(); sysInfoMap.put("hostname", hostname); sysInfoMap.put("ip", addr.getHostAddress()); - } catch (UnknownHostException e) + } + catch (UnknownHostException e) { - // + // drop everything to be silent } // Get the runtime info sysInfoMap.put("CPUCores", Runtime.getRuntime().availableProcessors() -- cgit v1.2.1