use of org.apache.solr.core.SolrInfoMBean in project SearchServices by Alfresco.
the class SolrInformationServer method getCoreStats.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Iterable<Entry<String, Object>> getCoreStats() throws IOException {
// This is still local, not totally cloud-friendly
// TODO Make this cloud-friendly by aggregating the stats across the cloud
SolrQueryRequest request = null;
NamedList<Object> coreSummary = new SimpleOrderedMap<Object>();
RefCounted<SolrIndexSearcher> refCounted = null;
try {
request = getLocalSolrQueryRequest();
NamedList docTypeCounts = this.getFacets(request, "*:*", FIELD_DOC_TYPE, 0);
long aclCount = getSafeCount(docTypeCounts, DOC_TYPE_ACL);
coreSummary.add("Alfresco Acls in Index", aclCount);
long nodeCount = getSafeCount(docTypeCounts, DOC_TYPE_NODE);
coreSummary.add("Alfresco Nodes in Index", nodeCount);
long txCount = getSafeCount(docTypeCounts, DOC_TYPE_TX);
coreSummary.add("Alfresco Transactions in Index", txCount);
long aclTxCount = getSafeCount(docTypeCounts, DOC_TYPE_ACL_TX);
coreSummary.add("Alfresco Acl Transactions in Index", aclTxCount);
long stateCount = getSafeCount(docTypeCounts, DOC_TYPE_STATE);
coreSummary.add("Alfresco States in Index", stateCount);
long unindexedNodeCount = getSafeCount(docTypeCounts, DOC_TYPE_UNINDEXED_NODE);
coreSummary.add("Alfresco Unindexed Nodes", unindexedNodeCount);
long errorNodeCount = getSafeCount(docTypeCounts, DOC_TYPE_ERROR_NODE);
coreSummary.add("Alfresco Error Nodes in Index", errorNodeCount);
refCounted = core.getSearcher(false, true, null);
SolrIndexSearcher solrIndexSearcher = refCounted.get();
coreSummary.add("Searcher", solrIndexSearcher.getStatistics());
Map<String, SolrInfoMBean> infoRegistry = core.getInfoRegistry();
for (String key : infoRegistry.keySet()) {
SolrInfoMBean infoMBean = infoRegistry.get(key);
if (key.equals("/alfresco")) {
// TODO Do we really need to fixStats in solr4?
coreSummary.add("/alfresco", fixStats(infoMBean.getStatistics()));
}
if (key.equals("/afts")) {
coreSummary.add("/afts", fixStats(infoMBean.getStatistics()));
}
if (key.equals("/cmis")) {
coreSummary.add("/cmis", fixStats(infoMBean.getStatistics()));
}
if (key.equals("filterCache")) {
coreSummary.add("/filterCache", infoMBean.getStatistics());
}
if (key.equals("queryResultCache")) {
coreSummary.add("/queryResultCache", infoMBean.getStatistics());
}
if (key.equals("alfrescoAuthorityCache")) {
coreSummary.add("/alfrescoAuthorityCache", infoMBean.getStatistics());
}
if (key.equals("alfrescoPathCache")) {
coreSummary.add("/alfrescoPathCache", infoMBean.getStatistics());
}
}
// Adds detailed stats for each registered searcher
int searcherIndex = 0;
List<SolrIndexSearcher> searchers = getRegisteredSearchers();
for (SolrIndexSearcher searcher : searchers) {
NamedList<Object> details = new SimpleOrderedMap<Object>();
details.add("Searcher", searcher.getStatistics());
coreSummary.add("Searcher-" + searcherIndex, details);
searcherIndex++;
}
coreSummary.add("Number of Searchers", searchers.size());
// This is zero for Solr4, whereas we had some local caches before
coreSummary.add("Total Searcher Cache (GB)", 0);
IndexDeletionPolicyWrapper delPolicy = core.getDeletionPolicy();
IndexCommit indexCommit = delPolicy.getLatestCommit();
// race?
if (indexCommit == null) {
indexCommit = solrIndexSearcher.getIndexReader().getIndexCommit();
}
if (indexCommit != null) {
// Tells Solr to stop deleting things for 20 seconds so we can get a snapshot of all the files on the index
delPolicy.setReserveDuration(solrIndexSearcher.getIndexReader().getVersion(), 20000);
Long fileSize = 0L;
File dir = new File(solrIndexSearcher.getPath());
for (String name : indexCommit.getFileNames()) {
File file = new File(dir, name);
if (file.exists()) {
fileSize += file.length();
}
}
DecimalFormat df = new DecimalFormat("###,###.######");
coreSummary.add("On disk (GB)", df.format(fileSize / 1024.0f / 1024.0f / 1024.0f));
coreSummary.add("Per node B", nodeCount > 0 ? fileSize / nodeCount : 0);
}
} finally {
if (request != null) {
request.close();
}
if (refCounted != null) {
refCounted.decref();
}
}
return coreSummary;
}
Aggregations