Search in sources :

Example 1 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class FastLRUCache method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    registry = manager.registry(registryName);
    cacheMap = new MetricsMap((detailed, map) -> {
        if (cache != null) {
            ConcurrentLRUCache.Stats stats = cache.getStats();
            long lookups = stats.getCumulativeLookups();
            long hits = stats.getCumulativeHits();
            long inserts = stats.getCumulativePuts();
            long evictions = stats.getCumulativeEvictions();
            long size = stats.getCurrentSize();
            long clookups = 0;
            long chits = 0;
            long cinserts = 0;
            long cevictions = 0;
            // NOTE: It is safe to iterate on a CopyOnWriteArrayList
            for (ConcurrentLRUCache.Stats statistiscs : statsList) {
                clookups += statistiscs.getCumulativeLookups();
                chits += statistiscs.getCumulativeHits();
                cinserts += statistiscs.getCumulativePuts();
                cevictions += statistiscs.getCumulativeEvictions();
            }
            map.put("lookups", lookups);
            map.put("hits", hits);
            map.put("hitratio", calcHitRatio(lookups, hits));
            map.put("inserts", inserts);
            map.put("evictions", evictions);
            map.put("size", size);
            map.put("warmupTime", warmupTime);
            map.put("cumulative_lookups", clookups);
            map.put("cumulative_hits", chits);
            map.put("cumulative_hitratio", calcHitRatio(clookups, chits));
            map.put("cumulative_inserts", cinserts);
            map.put("cumulative_evictions", cevictions);
            if (detailed && showItems != 0) {
                Map items = cache.getLatestAccessedItems(showItems == -1 ? Integer.MAX_VALUE : showItems);
                for (Map.Entry e : (Set<Map.Entry>) items.entrySet()) {
                    Object k = e.getKey();
                    Object v = e.getValue();
                    String ks = "item_" + k;
                    String vs = v.toString();
                    map.put(ks, vs);
                }
            }
        }
    });
    manager.registerGauge(this, registryName, cacheMap, true, scope, getCategory().toString());
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) MetricsMap(org.apache.solr.metrics.MetricsMap) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) SolrException(org.apache.solr.common.SolrException) List(java.util.List) ConcurrentLRUCache(org.apache.solr.util.ConcurrentLRUCache) Map(java.util.Map) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MetricsMap(org.apache.solr.metrics.MetricsMap) MetricsMap(org.apache.solr.metrics.MetricsMap) Map(java.util.Map)

Example 2 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class AnalyticsComponent method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registry, String scope) {
    MetricsMap metrics = new MetricsMap((detailed, map) -> map.putAll(analyticsCollector.getStatistics()));
    manager.registerGauge(this, registry, metrics, true, getClass().getSimpleName(), getCategory().toString(), scope);
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap)

Example 3 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class SolrJmxReporter method init.

/**
   * Initializes the reporter by finding an MBeanServer
   * and registering the metricManager's metric registry.
   *
   * @param pluginInfo the configuration for the reporter
   */
@Override
public synchronized void init(PluginInfo pluginInfo) {
    super.init(pluginInfo);
    if (!enabled) {
        log.info("Reporter disabled for registry " + registryName);
        return;
    }
    log.debug("Initializing for registry " + registryName);
    if (serviceUrl != null && agentId != null) {
        mBeanServer = JmxUtil.findFirstMBeanServer();
        log.warn("No more than one of serviceUrl({}) and agentId({}) should be configured, using first MBeanServer instead of configuration.", serviceUrl, agentId, mBeanServer);
    } else if (serviceUrl != null) {
        // reuse existing services
        mBeanServer = serviceRegistry.getOrCreate(serviceUrl, () -> JmxUtil.findMBeanServerForServiceUrl(serviceUrl));
    } else if (agentId != null) {
        mBeanServer = JmxUtil.findMBeanServerForAgentId(agentId);
    } else {
        mBeanServer = JmxUtil.findFirstMBeanServer();
        log.debug("No serviceUrl or agentId was configured, using first MBeanServer: " + mBeanServer);
    }
    if (mBeanServer == null) {
        log.warn("No JMX server found. Not exposing Solr metrics via JMX.");
        return;
    }
    if (domain == null || domain.isEmpty()) {
        domain = registryName;
    }
    String fullDomain = domain;
    if (rootName != null && !rootName.isEmpty()) {
        fullDomain = rootName + "." + domain;
    }
    JmxObjectNameFactory jmxObjectNameFactory = new JmxObjectNameFactory(pluginInfo.name, fullDomain);
    registry = metricManager.registry(registryName);
    // filter out MetricsMap gauges - we have a better way of handling them
    MetricFilter mmFilter = (name, metric) -> !(metric instanceof MetricsMap);
    MetricFilter filter;
    if (filters.isEmpty()) {
        filter = mmFilter;
    } else {
        // apply also prefix filters
        SolrMetricManager.PrefixFilter prefixFilter = new SolrMetricManager.PrefixFilter(filters);
        filter = new SolrMetricManager.AndFilter(prefixFilter, mmFilter);
    }
    reporter = JmxReporter.forRegistry(registry).registerWith(mBeanServer).inDomain(fullDomain).filter(filter).createsObjectNamesWith(jmxObjectNameFactory).build();
    reporter.start();
    // workaround for inability to register custom MBeans (to be available in metrics 4.0?)
    listener = new MetricsMapListener(mBeanServer, jmxObjectNameFactory);
    registry.addListener(listener);
    log.info("JMX monitoring for '" + fullDomain + "' (registry '" + registryName + "') enabled at server: " + mBeanServer);
}
Also used : ObjectInstance(javax.management.ObjectInstance) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) JmxUtil(org.apache.solr.util.JmxUtil) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) MetricRegistryListener(com.codahale.metrics.MetricRegistryListener) ObjectName(javax.management.ObjectName) MetricsMap(org.apache.solr.metrics.MetricsMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Locale(java.util.Locale) MBeanServer(javax.management.MBeanServer) MetricFilter(com.codahale.metrics.MetricFilter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) PluginInfo(org.apache.solr.core.PluginInfo) Gauge(com.codahale.metrics.Gauge) InstanceNotFoundException(javax.management.InstanceNotFoundException) JmxReporter(com.codahale.metrics.JmxReporter) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) MetricFilter(com.codahale.metrics.MetricFilter) MetricsMap(org.apache.solr.metrics.MetricsMap) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Example 4 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class HdfsLocalityReporter method initializeMetrics.

/**
   * Provide statistics on HDFS block locality, both in terms of bytes and block counts.
   */
@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    registry = manager.registry(registryName);
    MetricsMap metricsMap = new MetricsMap((detailed, map) -> {
        long totalBytes = 0;
        long localBytes = 0;
        int totalCount = 0;
        int localCount = 0;
        for (Iterator<HdfsDirectory> iterator = cache.keySet().iterator(); iterator.hasNext(); ) {
            HdfsDirectory hdfsDirectory = iterator.next();
            if (hdfsDirectory.isClosed()) {
                iterator.remove();
            } else {
                try {
                    refreshDirectory(hdfsDirectory);
                    Map<FileStatus, BlockLocation[]> blockMap = cache.get(hdfsDirectory);
                    // For every block in every file in this directory, count it
                    for (BlockLocation[] locations : blockMap.values()) {
                        for (BlockLocation bl : locations) {
                            totalBytes += bl.getLength();
                            totalCount++;
                            if (Arrays.asList(bl.getHosts()).contains(hostname)) {
                                localBytes += bl.getLength();
                                localCount++;
                            }
                        }
                    }
                } catch (IOException e) {
                    logger.warn("Could not retrieve locality information for {} due to exception: {}", hdfsDirectory.getHdfsDirPath(), e);
                }
            }
        }
        map.put(LOCALITY_BYTES_TOTAL, totalBytes);
        map.put(LOCALITY_BYTES_LOCAL, localBytes);
        if (localBytes == 0) {
            map.put(LOCALITY_BYTES_RATIO, 0);
        } else {
            map.put(LOCALITY_BYTES_RATIO, localBytes / (double) totalBytes);
        }
        map.put(LOCALITY_BLOCKS_TOTAL, totalCount);
        map.put(LOCALITY_BLOCKS_LOCAL, localCount);
        if (localCount == 0) {
            map.put(LOCALITY_BLOCKS_RATIO, 0);
        } else {
            map.put(LOCALITY_BLOCKS_RATIO, localCount / (double) totalCount);
        }
    });
    manager.registerGauge(this, registryName, metricsMap, true, "hdfsLocality", getCategory().toString(), scope);
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) FileStatus(org.apache.hadoop.fs.FileStatus) IOException(java.io.IOException) BlockLocation(org.apache.hadoop.fs.BlockLocation)

Example 5 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class DataImportHandler method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    super.initializeMetrics(manager, registryName, scope);
    metrics = new MetricsMap((detailed, map) -> {
        if (importer != null) {
            DocBuilder.Statistics cumulative = importer.cumulativeStatistics;
            map.put("Status", importer.getStatus().toString());
            if (importer.docBuilder != null) {
                DocBuilder.Statistics running = importer.docBuilder.importStatistics;
                map.put("Documents Processed", running.docCount);
                map.put("Requests made to DataSource", running.queryCount);
                map.put("Rows Fetched", running.rowsCount);
                map.put("Documents Deleted", running.deletedDocCount);
                map.put("Documents Skipped", running.skipDocCount);
            }
            map.put(DataImporter.MSG.TOTAL_DOC_PROCESSED, cumulative.docCount);
            map.put(DataImporter.MSG.TOTAL_QUERIES_EXECUTED, cumulative.queryCount);
            map.put(DataImporter.MSG.TOTAL_ROWS_EXECUTED, cumulative.rowsCount);
            map.put(DataImporter.MSG.TOTAL_DOCS_DELETED, cumulative.deletedDocCount);
            map.put(DataImporter.MSG.TOTAL_DOCS_SKIPPED, cumulative.skipDocCount);
        }
    });
    manager.registerGauge(this, registryName, metrics, true, "importer", getCategory().toString(), scope);
}
Also used : RequestHandlerBase(org.apache.solr.handler.RequestHandlerBase) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) SolrCoreAware(org.apache.solr.util.plugin.SolrCoreAware) StrUtils(org.apache.solr.common.util.StrUtils) Constructor(java.lang.reflect.Constructor) SolrParams(org.apache.solr.common.params.SolrParams) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase) SolrException(org.apache.solr.common.SolrException) ContentStream(org.apache.solr.common.util.ContentStream) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) IMPORT_CMD(org.apache.solr.handler.dataimport.DataImporter.IMPORT_CMD) Logger(org.slf4j.Logger) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrCore(org.apache.solr.core.SolrCore) MethodHandles(java.lang.invoke.MethodHandles) MetricsMap(org.apache.solr.metrics.MetricsMap) NamedList(org.apache.solr.common.util.NamedList) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) RawResponseWriter(org.apache.solr.response.RawResponseWriter) CommonParams(org.apache.solr.common.params.CommonParams) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrInputDocument(org.apache.solr.common.SolrInputDocument) MetricsMap(org.apache.solr.metrics.MetricsMap)

Aggregations

MetricsMap (org.apache.solr.metrics.MetricsMap)26 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)10 Map (java.util.Map)8 Test (org.junit.Test)7 MetricRegistry (com.codahale.metrics.MetricRegistry)5 MethodHandles (java.lang.invoke.MethodHandles)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 SolrException (org.apache.solr.common.SolrException)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 HashMap (java.util.HashMap)4 Random (java.util.Random)4 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 IOException (java.io.IOException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 Gauge (com.codahale.metrics.Gauge)1 JmxReporter (com.codahale.metrics.JmxReporter)1