So for all those wondering what the problem was: It turns out I can't just initialize my own CoreContainer; that just gives me a *new* set of cores, and since those are not the cores being used by the SolrDispatchFilter, they're never accessed and thus the stats remain the same (such as having "2" queries performed on the core) throughout the life of the server.
What I had to do was extend the SolrDispatchFilter to gain access to its protected CoreContainer and use that one. (Should Solr expose the core to those who are servicing requests that are not HTTP-based? The SolrDispatchFilter puts the "core" into the request, but not all things that need access to the core are servlets or filters. For example, I'm using an MBean whose actions are called through SNMP.) - Daryl. On Tue, Jun 16, 2009 at 2:42 PM, Development Team <dev.and...@gmail.com>wrote: > Hi all, > I am stumped trying to get statistics from the Solr server. It seems > that every time I get the correct SolrInfoMBean, when I look up the proper > value (by name) in the NamedList, I get the exact same number back each > time. For example, upon start-up the server reports that "2" queries have > been performed, and any time I pull the value out of the MBean after that it > says "2" even though the stats.jsp reports an increasing number of queries > over time. What am I doing wrong? > Here is my sample code: > > public class SolrUtil { > > protected static final CoreContainer coreContainer; > protected static final String DEFAULT_CORE_NAME = ""; > > static { > CoreContainer.Initializer initializer = new > CoreContainer.Initializer(); > try { > coreContainer = initializer.initialize(); > } > catch (Exception e) { > throw new ExceptionInInitializerError("Can't initialize core > container: " + e.getMessage()); > } > initialize(); > } > > private static SolrCore getCore() { > return getCore(DEFAULT_CORE_NAME); > } > > private static SolrCore getCore(String name) { > try { > return coreContainer.getCore(name); > } > catch (Exception e) { > e.printStackTrace(); > } > return null; > } > > public static String getSolrInfoMBeanValue(SolrInfoMBean.Category > category, String entryName, String statName) { > Map<String, SolrInfoMBean> registry = getCore().getInfoRegistry(); > for (Map.Entry<String, SolrInfoMBean> entry : registry.entrySet()) { > String key = entry.getKey(); > SolrInfoMBean solrInfoMBean = entry.getValue(); > if ((solrInfoMBean.getCategory() != category) || > (!entryName.equals(key.trim()))) { > continue; > } > NamedList<?> nl = solrInfoMBean.getStatistics(); > if ((nl != null) && (nl.size() > 0)) { > for (int i = 0; i < nl.size(); i++) { > if (nl.getName(i).equals(statName)) { > return nl.getVal(i).toString(); > } > } > } > } > return null; > } > > [...I have other methods, that also get the value as a long, etc....] > > } > > > > This code is modeled after the SolrDispatchFilter.java, _info.jsp and > stats.jsp. > I'd appreciate any help. (And yes, my core is named "".) > > Sincerely, > > Daryl. >