Search in sources :

Example 16 with SolrMetricManager

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

the class Metrics method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    registry = manager.registry(registryName);
    metricsMap = new MetricsMap((detailed, map) -> {
        long now = System.nanoTime();
        long delta = Math.max(now - previous, 1);
        double seconds = delta / 1000000000.0;
        long hits_total = blockCacheHit.get();
        long hits_delta = hits_total - blockCacheHit_last.get();
        blockCacheHit_last.set(hits_total);
        long miss_total = blockCacheMiss.get();
        long miss_delta = miss_total - blockCacheMiss_last.get();
        blockCacheMiss_last.set(miss_total);
        long evict_total = blockCacheEviction.get();
        long evict_delta = evict_total - blockCacheEviction_last.get();
        blockCacheEviction_last.set(evict_total);
        long storeFail_total = blockCacheStoreFail.get();
        long storeFail_delta = storeFail_total - blockCacheStoreFail_last.get();
        blockCacheStoreFail_last.set(storeFail_total);
        long lookups_delta = hits_delta + miss_delta;
        long lookups_total = hits_total + miss_total;
        map.put("size", blockCacheSize.get());
        map.put("lookups", lookups_total);
        map.put("hits", hits_total);
        map.put("evictions", evict_total);
        map.put("storeFails", storeFail_total);
        // hit ratio since the last call
        map.put("hitratio_current", calcHitRatio(lookups_delta, hits_delta));
        // lookups per second since the last call
        map.put("lookups_persec", getPerSecond(lookups_delta, seconds));
        // hits per second since the last call
        map.put("hits_persec", getPerSecond(hits_delta, seconds));
        // evictions per second since the last call
        map.put("evictions_persec", getPerSecond(evict_delta, seconds));
        // evictions per second since the last call
        map.put("storeFails_persec", getPerSecond(storeFail_delta, seconds));
        // seconds since last call
        map.put("time_delta", seconds);
        // TODO: these aren't really related to the BlockCache
        map.put("buffercache.allocations", getPerSecond(shardBuffercacheAllocate.getAndSet(0), seconds));
        map.put("buffercache.lost", getPerSecond(shardBuffercacheLost.getAndSet(0), seconds));
        previous = now;
    });
    manager.registerGauge(this, registryName, metricsMap, true, getName(), getCategory().toString(), scope);
}
Also used : HashSet(java.util.HashSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) MetricRegistry(com.codahale.metrics.MetricRegistry) SolrInfoBean(org.apache.solr.core.SolrInfoBean) Set(java.util.Set) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) MetricsMap(org.apache.solr.metrics.MetricsMap) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) SolrCacheBase(org.apache.solr.search.SolrCacheBase) MetricsMap(org.apache.solr.metrics.MetricsMap)

Example 17 with SolrMetricManager

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

the class SolrInfoBeanTest method testCallMBeanInfo.

/**
   * Gets a list of everything we can find in the classpath and makes sure it has
   * a name, description, etc...
   */
public void testCallMBeanInfo() throws Exception {
    List<Class> classes = new ArrayList<>();
    classes.addAll(getClassesForPackage(StandardRequestHandler.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(SearchComponent.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(LukeRequestHandler.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(DefaultSolrHighlighter.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(LRUCache.class.getPackage().getName()));
    // System.out.println(classes);
    int checked = 0;
    SolrMetricManager metricManager = h.getCoreContainer().getMetricManager();
    String registry = h.getCore().getCoreMetricManager().getRegistryName();
    String scope = TestUtil.randomSimpleString(random(), 2, 10);
    for (Class clazz : classes) {
        if (SolrInfoBean.class.isAssignableFrom(clazz)) {
            try {
                SolrInfoBean info = (SolrInfoBean) clazz.newInstance();
                if (info instanceof SolrMetricProducer) {
                    ((SolrMetricProducer) info).initializeMetrics(metricManager, registry, scope);
                }
                //System.out.println( info.getClass() );
                assertNotNull(info.getName());
                assertNotNull(info.getDescription());
                assertNotNull(info.getCategory());
                if (info instanceof LRUCache) {
                    continue;
                }
                assertNotNull(info.toString());
                checked++;
            } catch (InstantiationException ex) {
            // expected...
            //System.out.println( "unable to initialize: "+clazz );
            }
        }
    }
    assertTrue("there are at least 10 SolrInfoBean that should be found in the classpath, found " + checked, checked > 10);
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) ArrayList(java.util.ArrayList) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) LRUCache(org.apache.solr.search.LRUCache) LukeRequestHandler(org.apache.solr.handler.admin.LukeRequestHandler) SearchComponent(org.apache.solr.handler.component.SearchComponent) DefaultSolrHighlighter(org.apache.solr.highlight.DefaultSolrHighlighter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) BeforeClass(org.junit.BeforeClass) StandardRequestHandler(org.apache.solr.handler.StandardRequestHandler)

Example 18 with SolrMetricManager

use of org.apache.solr.metrics.SolrMetricManager 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 19 with SolrMetricManager

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

the class BufferStoreTest method setup.

@Before
public void setup() {
    metrics = new Metrics();
    SolrMetricManager metricManager = new SolrMetricManager();
    String registry = TestUtil.randomSimpleString(random(), 2, 10);
    String scope = TestUtil.randomSimpleString(random(), 2, 10);
    metrics.initializeMetrics(metricManager, registry, scope);
    metricsMap = (MetricsMap) metricManager.registry(registry).getMetrics().get("CACHE." + scope + ".hdfsBlockCache");
    BufferStore.initNewBuffer(blockSize, blockSize, metrics);
    store = BufferStore.instance(blockSize);
}
Also used : SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Before(org.junit.Before)

Example 20 with SolrMetricManager

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

the class SolrSlf4jReporterTest method testReporter.

@Test
public void testReporter() throws Exception {
    LogWatcherConfig watcherCfg = new LogWatcherConfig(true, null, null, 100);
    LogWatcher watcher = LogWatcher.newRegisteredLogWatcher(watcherCfg, null);
    watcher.setThreshold("INFO");
    Path home = Paths.get(TEST_HOME());
    // define these properties, they are used in solrconfig.xml
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-slf4jreporter.xml").toFile(), "UTF-8");
    NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
    CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
    h.coreName = DEFAULT_TEST_CORENAME;
    SolrMetricManager metricManager = cc.getMetricManager();
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
    assertTrue(reporters.toString(), reporters.size() >= 2);
    SolrMetricReporter reporter = reporters.get("test1");
    assertNotNull(reporter);
    assertTrue(reporter instanceof SolrSlf4jReporter);
    reporter = reporters.get("test2");
    assertNotNull(reporter);
    assertTrue(reporter instanceof SolrSlf4jReporter);
    watcher.reset();
    Thread.sleep(5000);
    SolrDocumentList history = watcher.getHistory(-1, null);
    // dot-separated names are treated like class names and collapsed
    // in regular log output, but here we get the full name
    assertTrue(history.stream().filter(d -> "solr.node".equals(d.getFirstValue("logger"))).count() > 0);
    assertTrue(history.stream().filter(d -> "foobar".equals(d.getFirstValue("logger"))).count() > 0);
}
Also used : LogWatcherConfig(org.apache.solr.logging.LogWatcherConfig) Path(java.nio.file.Path) LogWatcherConfig(org.apache.solr.logging.LogWatcherConfig) SolrDocumentList(org.apache.solr.common.SolrDocumentList) TestHarness(org.apache.solr.util.TestHarness) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) CoreContainer(org.apache.solr.core.CoreContainer) SolrTestCaseJ4(org.apache.solr.SolrTestCaseJ4) SolrXmlConfig(org.apache.solr.core.SolrXmlConfig) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) Paths(java.nio.file.Paths) Map(java.util.Map) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) LogWatcher(org.apache.solr.logging.LogWatcher) NodeConfig(org.apache.solr.core.NodeConfig) Path(java.nio.file.Path) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) SolrDocumentList(org.apache.solr.common.SolrDocumentList) LogWatcher(org.apache.solr.logging.LogWatcher) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer) TestHarness(org.apache.solr.util.TestHarness) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) NodeConfig(org.apache.solr.core.NodeConfig) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Aggregations

SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)29 Test (org.junit.Test)13 MetricsMap (org.apache.solr.metrics.MetricsMap)9 Map (java.util.Map)8 CoreContainer (org.apache.solr.core.CoreContainer)8 MetricRegistry (com.codahale.metrics.MetricRegistry)6 Metric (com.codahale.metrics.Metric)5 Set (java.util.Set)5 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)5 SolrException (org.apache.solr.common.SolrException)5 SolrCore (org.apache.solr.core.SolrCore)5 Counter (com.codahale.metrics.Counter)4 IOException (java.io.IOException)4 MethodHandles (java.lang.invoke.MethodHandles)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Random (java.util.Random)4