Search in sources :

Example 26 with MetricsMap

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

the class LFUCache method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    registry = manager.registry(registryName);
    cacheMap = new MetricsMap((detailed, map) -> {
        if (cache != null) {
            ConcurrentLFUCache.Stats stats = cache.getStats();
            long lookups = stats.getCumulativeLookups();
            long hits = stats.getCumulativeHits();
            long inserts = stats.getCumulativePuts();
            long evictions = stats.getCumulativeEvictions();
            long size = stats.getCurrentSize();
            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("timeDecay", timeDecay);
            long clookups = 0;
            long chits = 0;
            long cinserts = 0;
            long cevictions = 0;
            // NOTE: It is safe to iterate on a CopyOnWriteArrayList
            for (ConcurrentLFUCache.Stats statistics : statsList) {
                clookups += statistics.getCumulativeLookups();
                chits += statistics.getCumulativeHits();
                cinserts += statistics.getCumulativePuts();
                cevictions += statistics.getCumulativeEvictions();
            }
            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.getMostUsedItems(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) NAME(org.apache.solr.common.params.CommonParams.NAME) List(java.util.List) Map(java.util.Map) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConcurrentLFUCache(org.apache.solr.util.ConcurrentLFUCache) MetricsMap(org.apache.solr.metrics.MetricsMap) MetricsMap(org.apache.solr.metrics.MetricsMap) Map(java.util.Map)

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