From 82ce4b84f0a37f319a2707275e8bc9164107c773 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Fri, 18 Jun 2010 19:58:17 +0000 Subject: [PATCH] SOLR-1946: Misc improvements to the SystemInfoHandler: /admin/system git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@956112 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 + .../solr/handler/admin/SystemInfoHandler.java | 94 +++++++++---------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 0625204169d..6b9f7938fd2 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -435,6 +435,9 @@ Other Changes ExtendedDismaxQParser has been changed to be determined based on the effective 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.java index 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 + } + } + @Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { @@ -71,7 +89,7 @@ public class SystemInfoHandler extends RequestHandlerBase /** * Get system info */ - private static SimpleOrderedMap getCoreInfo( SolrCore core ) throws Exception + private SimpleOrderedMap getCoreInfo( SolrCore core ) throws Exception { SimpleOrderedMap info = new SimpleOrderedMap(); @@ -79,8 +97,7 @@ public class SystemInfoHandler extends RequestHandlerBase info.add( "schema", schema != null ? schema.getSchemaName():"no schema!" ); // Host - InetAddress addr = InetAddress.getLocalHost(); - info.add( "host", addr.getCanonicalHostName() ); + info.add( "host", hostname ); // Now info.add( "now", new Date() ); @@ -90,6 +107,7 @@ public class SystemInfoHandler extends RequestHandlerBase // Solr Home SimpleOrderedMap dirs = new SimpleOrderedMap(); + 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 RequestHandlerBase Runtime runtime = Runtime.getRuntime(); jvm.add( "processors", runtime.availableProcessors() ); - long used = runtime.totalMemory() - runtime.freeMemory(); // not thread safe, but could be thread local DecimalFormat df = new DecimalFormat("#.#"); - double percentUsed = ((double)(used)/(double)runtime.maxMemory())*100; SimpleOrderedMap mem = new SimpleOrderedMap(); - 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 raw = new SimpleOrderedMap(); + 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 RequestHandlerBase private static SimpleOrderedMap getLuceneInfo() throws Exception { SimpleOrderedMap info = new SimpleOrderedMap(); - - 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; }