Search in sources :

Example 21 with SolrMetricManager

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

the class SolrCloudReportersTest method testDefaultPlugins.

@Test
public void testDefaultPlugins() throws Exception {
    String solrXml = IOUtils.toString(SolrCloudReportersTest.class.getResourceAsStream("/solr/solr.xml"), "UTF-8");
    configureCluster(2).withSolrXml(solrXml).configure();
    cluster.uploadConfigSet(Paths.get(TEST_PATH().toString(), "configsets", "minimal", "conf"), "test");
    System.out.println("ZK: " + cluster.getZkServer().getZkAddress());
    CollectionAdminRequest.createCollection("test_collection", "test", 2, 2).setMaxShardsPerNode(4).process(cluster.getSolrClient());
    waitForState("Expected test_collection with 2 shards and 2 replicas", "test_collection", clusterShape(2, 2));
    cluster.getJettySolrRunners().forEach(jetty -> {
        CoreContainer cc = jetty.getCoreContainer();
        SolrMetricManager metricManager = cc.getMetricManager();
        Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.cluster");
        assertEquals(reporters.toString(), 0, reporters.size());
        for (String registryName : metricManager.registryNames(".*\\.shard[0-9]\\.replica.*")) {
            reporters = metricManager.getReporters(registryName);
            assertEquals(reporters.toString(), 0 + jmxReporter, reporters.size());
        }
    });
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 22 with SolrMetricManager

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

the class SolrGangliaReporterTest method testReporter.

@Test
public void testReporter() throws Exception {
    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");
    GMetric ganglia = mock(GMetric.class);
    final List<String> names = new ArrayList<>();
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        names.add((String) args[0]);
        return null;
    }).when(ganglia).announce(anyString(), anyString(), any(GMetricType.class), anyString(), any(GMetricSlope.class), anyInt(), anyInt(), anyString());
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-gangliareporter.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() >= 1);
    SolrMetricReporter reporter = reporters.get("test");
    assertNotNull(reporter);
    assertTrue(reporter instanceof SolrGangliaReporter);
    SolrGangliaReporter gangliaReporter = (SolrGangliaReporter) reporter;
    gangliaReporter.setGMetric(ganglia);
    gangliaReporter.start();
    Thread.sleep(5000);
    assertTrue(names.size() >= 3);
    String[] frozenNames = (String[]) names.toArray(new String[names.size()]);
    for (String name : frozenNames) {
        assertTrue(name, name.startsWith("test.solr.node.CONTAINER.cores."));
    }
}
Also used : Path(java.nio.file.Path) GMetricSlope(info.ganglia.gmetric4j.gmetric.GMetricSlope) ArrayList(java.util.ArrayList) GMetricType(info.ganglia.gmetric4j.gmetric.GMetricType) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) GMetric(info.ganglia.gmetric4j.gmetric.GMetric) 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)

Example 23 with SolrMetricManager

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

the class TestSolrFieldCacheBean method assertEntryListIncluded.

private void assertEntryListIncluded(boolean checkJmx) {
    SolrFieldCacheBean mbean = new SolrFieldCacheBean();
    Random r = random();
    String registryName = TestUtil.randomSimpleString(r, 1, 10);
    SolrMetricManager metricManager = h.getCoreContainer().getMetricManager();
    mbean.initializeMetrics(metricManager, registryName, null);
    MetricsMap metricsMap = (MetricsMap) metricManager.registry(registryName).getMetrics().get("CACHE.fieldCache");
    Map<String, Object> metrics = checkJmx ? metricsMap.getValue(true) : metricsMap.getValue();
    assertTrue(((Number) metrics.get("entries_count")).longValue() > 0);
    assertNotNull(metrics.get("total_size"));
    assertNotNull(metrics.get("entry#0"));
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) Random(java.util.Random) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Example 24 with SolrMetricManager

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

the class TestLFUCache method testSimple.

@Test
public void testSimple() throws IOException {
    SolrMetricManager metricManager = new SolrMetricManager();
    Random r = random();
    String registry = TestUtil.randomSimpleString(r, 2, 10);
    String scope = TestUtil.randomSimpleString(r, 2, 10);
    LFUCache lfuCache = new LFUCache();
    LFUCache newLFUCache = new LFUCache();
    LFUCache noWarmLFUCache = new LFUCache();
    lfuCache.initializeMetrics(metricManager, registry, scope + ".lfuCache");
    newLFUCache.initializeMetrics(metricManager, registry, scope + ".newLFUCache");
    noWarmLFUCache.initializeMetrics(metricManager, registry, scope + ".noWarmLFUCache");
    try {
        Map params = new HashMap();
        params.put("size", "100");
        params.put("initialSize", "10");
        params.put("autowarmCount", "25");
        NoOpRegenerator regenerator = new NoOpRegenerator();
        Object initObj = lfuCache.init(params, null, regenerator);
        lfuCache.setState(SolrCache.State.LIVE);
        for (int i = 0; i < 101; i++) {
            lfuCache.put(i + 1, "" + (i + 1));
        }
        assertEquals("15", lfuCache.get(15));
        assertEquals("75", lfuCache.get(75));
        assertEquals(null, lfuCache.get(110));
        Map<String, Object> nl = lfuCache.getMetricsMap().getValue();
        assertEquals(3L, nl.get("lookups"));
        assertEquals(2L, nl.get("hits"));
        assertEquals(101L, nl.get("inserts"));
        // first item put in should be the first out
        assertEquals(null, lfuCache.get(1));
        // Test autowarming
        newLFUCache.init(params, initObj, regenerator);
        newLFUCache.warm(null, lfuCache);
        newLFUCache.setState(SolrCache.State.LIVE);
        newLFUCache.put(103, "103");
        assertEquals("15", newLFUCache.get(15));
        assertEquals("75", newLFUCache.get(75));
        assertEquals(null, newLFUCache.get(50));
        nl = newLFUCache.getMetricsMap().getValue();
        assertEquals(3L, nl.get("lookups"));
        assertEquals(2L, nl.get("hits"));
        assertEquals(1L, nl.get("inserts"));
        assertEquals(0L, nl.get("evictions"));
        assertEquals(7L, nl.get("cumulative_lookups"));
        assertEquals(4L, nl.get("cumulative_hits"));
        assertEquals(102L, nl.get("cumulative_inserts"));
        newLFUCache.close();
        // Test no autowarming
        params.put("autowarmCount", "0");
        noWarmLFUCache.init(params, initObj, regenerator);
        noWarmLFUCache.warm(null, lfuCache);
        noWarmLFUCache.setState(SolrCache.State.LIVE);
        noWarmLFUCache.put(103, "103");
        assertNull(noWarmLFUCache.get(15));
        assertNull(noWarmLFUCache.get(75));
        assertEquals("103", noWarmLFUCache.get(103));
    } finally {
        if (newLFUCache != null)
            newLFUCache.close();
        if (noWarmLFUCache != null)
            noWarmLFUCache.close();
        if (lfuCache != null)
            lfuCache.close();
    }
}
Also used : ConcurrentLFUCache(org.apache.solr.util.ConcurrentLFUCache) Random(java.util.Random) HashMap(java.util.HashMap) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 25 with SolrMetricManager

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

the class TestJmxIntegration method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    // Make sure that at least one MBeanServer is available
    // prior to initializing the core
    //
    // (test configs are setup to use existing server if any, 
    // otherwise skip JMX)
    MBeanServer platformServer = ManagementFactory.getPlatformMBeanServer();
    initCore("solrconfig.xml", "schema.xml");
    // we should be able to see that the core has JmxIntegration enabled
    registryName = h.getCore().getCoreMetricManager().getRegistryName();
    SolrMetricManager manager = h.getCoreContainer().getMetricManager();
    Map<String, SolrMetricReporter> reporters = manager.getReporters(registryName);
    assertEquals(1, reporters.size());
    SolrMetricReporter reporter = reporters.values().iterator().next();
    assertTrue(reporter instanceof SolrJmxReporter);
    SolrJmxReporter jmx = (SolrJmxReporter) reporter;
    assertTrue("JMX not enabled", jmx.isActive());
    // and we should be able to see that the reporter
    // refers to the JMX server we started
    mbeanServer = jmx.getMBeanServer();
    assertNotNull("No JMX server found in the reporter", mbeanServer);
    // NOTE: we can't guarantee that "mbeanServer == platformServer"
    // the JVM may have multiple MBean servers running when the test started
    // and the contract of not specifying one when configuring solr.xml without
    // agetnId or serviceUrl is that it will use whatever the "first" MBean server
    // returned by the JVM is.
    nameFactory = new JmxObjectNameFactory("default", registryName);
}
Also used : JmxObjectNameFactory(org.apache.solr.metrics.reporters.JmxObjectNameFactory) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) MBeanServer(javax.management.MBeanServer) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) SolrJmxReporter(org.apache.solr.metrics.reporters.SolrJmxReporter) BeforeClass(org.junit.BeforeClass)

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