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
This commit is contained in:
Chris M. Hostetter 2010-06-18 19:58:17 +00:00
parent cda18f0bd6
commit 82ce4b84f0
2 changed files with 50 additions and 47 deletions

View File

@ -435,6 +435,9 @@ Other Changes
ExtendedDismaxQParser has been changed to be determined based on the ExtendedDismaxQParser has been changed to be determined based on the
effective value of the 'q.op' param (hossman) effective value of the 'q.op' param (hossman)
* SOLR-1946: Misc improvements to the SystemInfoHandler: /admin/system
(hossman)
Build Build
---------------------- ----------------------

View File

@ -26,6 +26,7 @@ import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean; import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
@ -58,6 +59,23 @@ public class SystemInfoHandler extends RequestHandlerBase
{ {
private static Logger log = LoggerFactory.getLogger(SystemInfoHandler.class); 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 @Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{ {
@ -71,7 +89,7 @@ public class SystemInfoHandler extends RequestHandlerBase
/** /**
* Get system info * 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>(); SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>();
@ -79,8 +97,7 @@ public class SystemInfoHandler extends RequestHandlerBase
info.add( "schema", schema != null ? schema.getSchemaName():"no schema!" ); info.add( "schema", schema != null ? schema.getSchemaName():"no schema!" );
// Host // Host
InetAddress addr = InetAddress.getLocalHost(); info.add( "host", hostname );
info.add( "host", addr.getCanonicalHostName() );
// Now // Now
info.add( "now", new Date() ); info.add( "now", new Date() );
@ -90,6 +107,7 @@ public class SystemInfoHandler extends RequestHandlerBase
// Solr Home // Solr Home
SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<Object>(); SimpleOrderedMap<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( "instance", new File( core.getResourceLoader().getInstanceDir() ).getAbsolutePath() );
dirs.add( "data", new File( core.getDataDir() ).getAbsolutePath() ); dirs.add( "data", new File( core.getDataDir() ).getAbsolutePath() );
dirs.add( "index", new File( core.getIndexDir() ).getAbsolutePath() ); dirs.add( "index", new File( core.getIndexDir() ).getAbsolutePath() );
@ -193,16 +211,28 @@ public class SystemInfoHandler extends RequestHandlerBase
Runtime runtime = Runtime.getRuntime(); Runtime runtime = Runtime.getRuntime();
jvm.add( "processors", runtime.availableProcessors() ); jvm.add( "processors", runtime.availableProcessors() );
long used = runtime.totalMemory() - runtime.freeMemory();
// not thread safe, but could be thread local // not thread safe, but could be thread local
DecimalFormat df = new DecimalFormat("#.#"); DecimalFormat df = new DecimalFormat("#.#");
double percentUsed = ((double)(used)/(double)runtime.maxMemory())*100;
SimpleOrderedMap<Object> mem = new SimpleOrderedMap<Object>(); SimpleOrderedMap<Object> mem = new SimpleOrderedMap<Object>();
mem.add("free", humanReadableUnits(runtime.freeMemory(), df)); SimpleOrderedMap<Object> raw = new SimpleOrderedMap<Object>();
mem.add("total", humanReadableUnits(runtime.totalMemory(), df)); long free = runtime.freeMemory();
mem.add("max", humanReadableUnits(runtime.maxMemory(), df)); long max = runtime.maxMemory();
mem.add("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")"); 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); jvm.add("memory", mem);
// JMX properties -- probably should be moved to a different handler // 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 // the input arguments passed to the Java virtual machine
// which does not include the arguments to the main method. // which does not include the arguments to the main method.
jmx.add( "commandLineArgs", mx.getInputArguments()); 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( "startTime", new Date(mx.getStartTime()));
jmx.add( "upTimeMS", mx.getUptime() ); jmx.add( "upTimeMS", mx.getUptime() );
} }
catch (Exception e) { catch (Exception e) {
log.warn("Error getting JMX properties", e); log.warn("Error getting JMX properties", e);
@ -231,46 +260,17 @@ public class SystemInfoHandler extends RequestHandlerBase
private static SimpleOrderedMap<Object> getLuceneInfo() throws Exception private static SimpleOrderedMap<Object> getLuceneInfo() throws Exception
{ {
SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>(); SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>();
String solrImplVersion = "";
String solrSpecVersion = "";
String luceneImplVersion = "";
String luceneSpecVersion = "";
// ---
Package p = SolrCore.class.getPackage(); Package p = SolrCore.class.getPackage();
StringWriter tmp = new StringWriter();
solrImplVersion = p.getImplementationVersion(); info.add( "solr-spec-version", p.getSpecificationVersion() );
if (null != solrImplVersion) { info.add( "solr-impl-version", p.getImplementationVersion() );
XML.escapeCharData(solrImplVersion, tmp);
solrImplVersion = tmp.toString();
}
tmp = new StringWriter();
solrSpecVersion = p.getSpecificationVersion() ;
if (null != solrSpecVersion) {
XML.escapeCharData(solrSpecVersion, tmp);
solrSpecVersion = tmp.toString();
}
p = LucenePackage.class.getPackage(); p = LucenePackage.class.getPackage();
tmp = new StringWriter();
luceneImplVersion = p.getImplementationVersion(); info.add( "lucene-spec-version", p.getSpecificationVersion() );
if (null != luceneImplVersion) { info.add( "lucene-impl-version", p.getImplementationVersion() );
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 );
return info; return info;
} }