Search in sources :

Example 1 with SolrInfoMBean

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;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) IndexDeletionPolicyWrapper(org.apache.solr.core.IndexDeletionPolicyWrapper) DecimalFormat(java.text.DecimalFormat) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SolrSimpleOrderedMap(org.alfresco.solr.adapters.SolrSimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ISimpleOrderedMap(org.alfresco.solr.adapters.ISimpleOrderedMap) IndexCommit(org.apache.lucene.index.IndexCommit) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrInfoMBean(org.apache.solr.core.SolrInfoMBean) File(java.io.File)

Aggregations

File (java.io.File)1 DecimalFormat (java.text.DecimalFormat)1 ISimpleOrderedMap (org.alfresco.solr.adapters.ISimpleOrderedMap)1 SolrSimpleOrderedMap (org.alfresco.solr.adapters.SolrSimpleOrderedMap)1 IndexCommit (org.apache.lucene.index.IndexCommit)1 NamedList (org.apache.solr.common.util.NamedList)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1 IndexDeletionPolicyWrapper (org.apache.solr.core.IndexDeletionPolicyWrapper)1 SolrInfoMBean (org.apache.solr.core.SolrInfoMBean)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)1