Apache Lucene open-source search software
SOLR-1946: Misc improvements to the SystemInfoHandler: /admin/system
Chris M. Hostetter82ce4b84f0a3
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 0625204169d..6b9f7938fd2 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -435,6 +435,9 @@ Other ChangesExtendedDismaxQParser has been changed to be determined based on theeffective value of the 'q.op' param (hossman)+* SOLR-1946: Misc improvements to the SystemInfoHandler: /admin/system+ (hossman)+Build----------------------diff --git a/solr/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/src/java/org/apache/solr/handler/admin/SystemInfoHandler.javaindex 8d0606ccef5..e6c18e450b5 100644--- a/solr/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java+++ b/solr/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java@@ -26,6 +26,7 @@ import java.lang.management.OperatingSystemMXBean;import java.lang.management.RuntimeMXBean;import java.lang.reflect.Method;import java.net.InetAddress;+import java.net.UnknownHostException;import java.text.DecimalFormat;import java.util.Date;import java.util.Locale;@@ -58,6 +59,23 @@ public class SystemInfoHandler extends RequestHandlerBase{private static Logger log = LoggerFactory.getLogger(SystemInfoHandler.class);++ // on some platforms, resolving canonical hostname can cause the thread+ // to block for several seconds if nameservices aren't available+ // so resolve this once per handler instance+ //(ie: not static, so core reload will refresh)+ private String hostname = null;++ public SystemInfoHandler() {+ super();+ try {+ InetAddress addr = InetAddress.getLocalHost();+ hostname = addr.getCanonicalHostName();+ } catch (UnknownHostException e) {+ //default to null+ }+ }+@Overridepublic void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception{@@ -71,7 +89,7 @@ public class SystemInfoHandler extends RequestHandlerBase/*** Get system info*/- private static SimpleOrderedMap<Object> getCoreInfo( SolrCore core ) throws Exception+ private SimpleOrderedMap<Object> getCoreInfo( SolrCore core ) throws Exception{SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>();@@ -79,8 +97,7 @@ public class SystemInfoHandler extends RequestHandlerBaseinfo.add( "schema", schema != null ? schema.getSchemaName():"no schema!" );// Host- InetAddress addr = InetAddress.getLocalHost();- info.add( "host", addr.getCanonicalHostName() );+ info.add( "host", hostname );// Nowinfo.add( "now", new Date() );@@ -90,6 +107,7 @@ public class SystemInfoHandler extends RequestHandlerBase// Solr HomeSimpleOrderedMap<Object> dirs = new SimpleOrderedMap<Object>();+ dirs.add( "cwd" , new File( System.getProperty("user.dir")).getAbsolutePath() );dirs.add( "instance", new File( core.getResourceLoader().getInstanceDir() ).getAbsolutePath() );dirs.add( "data", new File( core.getDataDir() ).getAbsolutePath() );dirs.add( "index", new File( core.getIndexDir() ).getAbsolutePath() );@@ -193,16 +211,28 @@ public class SystemInfoHandler extends RequestHandlerBaseRuntime runtime = Runtime.getRuntime();jvm.add( "processors", runtime.availableProcessors() );- long used = runtime.totalMemory() - runtime.freeMemory();// not thread safe, but could be thread localDecimalFormat df = new DecimalFormat("#.#");- double percentUsed = ((double)(used)/(double)runtime.maxMemory())*100;SimpleOrderedMap<Object> mem = new SimpleOrderedMap<Object>();- mem.add("free", humanReadableUnits(runtime.freeMemory(), df));- mem.add("total", humanReadableUnits(runtime.totalMemory(), df));- mem.add("max", humanReadableUnits(runtime.maxMemory(), df));- mem.add("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")");+ SimpleOrderedMap<Object> raw = new SimpleOrderedMap<Object>();+ long free = runtime.freeMemory();+ long max = runtime.maxMemory();+ long total = runtime.totalMemory();+ long used = total - free;+ double percentUsed = ((double)(used)/(double)max)*100;+ raw.add("free", free );+ mem.add("free", humanReadableUnits(free, df));+ raw.add("total", total );+ mem.add("total", humanReadableUnits(total, df));+ raw.add("max", max );+ mem.add("max", humanReadableUnits(max, df));+ raw.add("used", used );+ mem.add("used", humanReadableUnits(used, df) ++ " (%" + df.format(percentUsed) + ")");+ raw.add("used%", percentUsed);++ mem.add("raw", raw);jvm.add("memory", mem);// JMX properties -- probably should be moved to a different handler@@ -215,11 +245,10 @@ public class SystemInfoHandler extends RequestHandlerBase// the input arguments passed to the Java virtual machine// which does not include the arguments to the main method.jmx.add( "commandLineArgs", mx.getInputArguments());- // a map of names and values of all system properties.- //jmx.add( "SYSTEM PROPERTIES", mx.getSystemProperties());jmx.add( "startTime", new Date(mx.getStartTime()));jmx.add( "upTimeMS", mx.getUptime() );+}catch (Exception e) {log.warn("Error getting JMX properties", e);@@ -231,46 +260,17 @@ public class SystemInfoHandler extends RequestHandlerBaseprivate static SimpleOrderedMap<Object> getLuceneInfo() throws Exception{SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>();-- String solrImplVersion = "";- String solrSpecVersion = "";- String luceneImplVersion = "";- String luceneSpecVersion = "";- // ---Package p = SolrCore.class.getPackage();- StringWriter tmp = new StringWriter();- solrImplVersion = p.getImplementationVersion();- if (null != solrImplVersion) {- XML.escapeCharData(solrImplVersion, tmp);- solrImplVersion = tmp.toString();- }- tmp = new StringWriter();- solrSpecVersion = p.getSpecificationVersion() ;- if (null != solrSpecVersion) {- XML.escapeCharData(solrSpecVersion, tmp);- solrSpecVersion = tmp.toString();- }++ info.add( "solr-spec-version", p.getSpecificationVersion() );+ info.add( "solr-impl-version", p.getImplementationVersion() );p = LucenePackage.class.getPackage();- tmp = new StringWriter();- luceneImplVersion = p.getImplementationVersion();- if (null != luceneImplVersion) {- XML.escapeCharData(luceneImplVersion, tmp);- luceneImplVersion = tmp.toString();- }- tmp = new StringWriter();- luceneSpecVersion = p.getSpecificationVersion() ;- if (null != luceneSpecVersion) {- XML.escapeCharData(luceneSpecVersion, tmp);- luceneSpecVersion = tmp.toString();- }-- // Add it to the list- info.add( "solr-spec-version", solrSpecVersion );- info.add( "solr-impl-version", solrImplVersion );- info.add( "lucene-spec-version", luceneSpecVersion );- info.add( "lucene-impl-version", luceneImplVersion );++ info.add( "lucene-spec-version", p.getSpecificationVersion() );+ info.add( "lucene-impl-version", p.getImplementationVersion() );+return info;}