Search in sources :

Example 26 with SolrMetricManager

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

Example 27 with SolrMetricManager

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

the class BasicFunctionalityTest method testSomeStuff.

@Test
public void testSomeStuff() throws Exception {
    clearIndex();
    SolrCore core = h.getCore();
    // test that we got the expected config, not just hardcoded defaults
    assertNotNull(core.getRequestHandler("mock"));
    // test stats call
    SolrMetricManager manager = core.getCoreContainer().getMetricManager();
    String registry = core.getCoreMetricManager().getRegistryName();
    Map<String, Metric> metrics = manager.registry(registry).getMetrics();
    assertTrue(metrics.containsKey("CORE.coreName"));
    assertTrue(metrics.containsKey("CORE.refCount"));
    Gauge<Number> g = (Gauge<Number>) metrics.get("CORE.refCount");
    assertTrue(g.getValue().intValue() > 0);
    lrf.args.put(CommonParams.VERSION, "2.2");
    assertQ("test query on empty index", req("qlkciyopsbgzyvkylsjhchghjrdf"), "//result[@numFound='0']");
    // test escaping of ";"
    assertU("deleting 42 for no reason at all", delI("42"));
    assertU("adding doc#42", adoc("id", "42", "val_s", "aa;bb"));
    assertU("does commit work?", commit());
    assertQ("backslash escaping semicolon", req("id:42 AND val_s:aa\\;bb"), "//*[@numFound='1']", "//int[@name='id'][.='42']");
    assertQ("quote escaping semicolon", req("id:42 AND val_s:\"aa;bb\""), "//*[@numFound='1']", "//int[@name='id'][.='42']");
    assertQ("no escaping semicolon", req("id:42 AND val_s:aa"), "//*[@numFound='0']");
    assertU(delI("42"));
    assertU(commit());
    assertQ(req("id:42"), "//*[@numFound='0']");
    // test overwrite default of true
    assertU(adoc("id", "42", "val_s", "AAA"));
    assertU(adoc("id", "42", "val_s", "BBB"));
    assertU(commit());
    assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='BBB']");
    assertU(adoc("id", "42", "val_s", "CCC"));
    assertU(adoc("id", "42", "val_s", "DDD"));
    assertU(commit());
    assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='DDD']");
    // test deletes
    String[] adds = new String[] { add(doc("id", "101"), "overwrite", "true"), add(doc("id", "101"), "overwrite", "true"), add(doc("id", "105"), "overwrite", "false"), add(doc("id", "102"), "overwrite", "true"), add(doc("id", "103"), "overwrite", "false"), add(doc("id", "101"), "overwrite", "true") };
    for (String a : adds) {
        assertU(a, a);
    }
    assertU(commit());
    // test maxint
    assertQ(req("q", "id:[100 TO 110]", "rows", "2147483647"), "//*[@numFound='4']");
    // test big limit
    assertQ(req("q", "id:[100 TO 111]", "rows", "1147483647"), "//*[@numFound='4']");
    assertQ(req("id:[100 TO 110]"), "//*[@numFound='4']");
    assertU(delI("102"));
    assertU(commit());
    assertQ(req("id:[100 TO 110]"), "//*[@numFound='3']");
    assertU(delI("105"));
    assertU(commit());
    assertQ(req("id:[100 TO 110]"), "//*[@numFound='2']");
    assertU(delQ("id:[100 TO 110]"));
    assertU(commit());
    assertQ(req("id:[100 TO 110]"), "//*[@numFound='0']");
    assertU(h.simpleTag("rollback"));
    assertU(commit());
}
Also used : SolrCore(org.apache.solr.core.SolrCore) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Metric(com.codahale.metrics.Metric) Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Example 28 with SolrMetricManager

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

the class SolrIndexSearcher method register.

/**
   * Register sub-objects such as caches and our own metrics
   */
public void register() {
    final Map<String, SolrInfoBean> infoRegistry = core.getInfoRegistry();
    // register self
    infoRegistry.put(STATISTICS_KEY, this);
    infoRegistry.put(name, this);
    for (SolrCache cache : cacheList) {
        cache.setState(SolrCache.State.LIVE);
        infoRegistry.put(cache.name(), cache);
    }
    SolrMetricManager manager = core.getCoreContainer().getMetricManager();
    String registry = core.getCoreMetricManager().getRegistryName();
    for (SolrCache cache : cacheList) {
        cache.initializeMetrics(manager, registry, SolrMetricManager.mkName(cache.name(), STATISTICS_KEY));
    }
    initializeMetrics(manager, registry, STATISTICS_KEY);
    registerTime = new Date();
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Date(java.util.Date)

Example 29 with SolrMetricManager

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

the class SolrDispatchFilter method setupJvmMetrics.

private void setupJvmMetrics(CoreContainer coresInit) {
    SolrMetricManager metricManager = coresInit.getMetricManager();
    final Set<String> hiddenSysProps = coresInit.getConfig().getMetricsConfig().getHiddenSysProps();
    try {
        String registry = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
        metricManager.registerAll(registry, new AltBufferPoolMetricSet(), true, "buffers");
        metricManager.registerAll(registry, new ClassLoadingGaugeSet(), true, "classes");
        metricManager.registerAll(registry, new OperatingSystemMetricSet(), true, "os");
        metricManager.registerAll(registry, new GarbageCollectorMetricSet(), true, "gc");
        metricManager.registerAll(registry, new MemoryUsageGaugeSet(), true, "memory");
        // todo should we use CachedThreadStatesGaugeSet instead?
        metricManager.registerAll(registry, new ThreadStatesGaugeSet(), true, "threads");
        MetricsMap sysprops = new MetricsMap((detailed, map) -> {
            System.getProperties().forEach((k, v) -> {
                if (!hiddenSysProps.contains(k)) {
                    map.put(String.valueOf(k), v);
                }
            });
        });
        metricManager.registerGauge(null, registry, sysprops, true, "properties", "system");
    } catch (Exception e) {
        log.warn("Error registering JVM metrics", e);
    }
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) MemoryUsageGaugeSet(com.codahale.metrics.jvm.MemoryUsageGaugeSet) OperatingSystemMetricSet(org.apache.solr.metrics.OperatingSystemMetricSet) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) AltBufferPoolMetricSet(org.apache.solr.metrics.AltBufferPoolMetricSet) ClassLoadingGaugeSet(com.codahale.metrics.jvm.ClassLoadingGaugeSet) ThreadStatesGaugeSet(com.codahale.metrics.jvm.ThreadStatesGaugeSet) ServletException(javax.servlet.ServletException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException) GarbageCollectorMetricSet(com.codahale.metrics.jvm.GarbageCollectorMetricSet)

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