Search in sources :

Example 1 with SolrMetricReporter

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

the class SolrCloudReportersTest method testExplicitConfiguration.

@Test
public void testExplicitConfiguration() throws Exception {
    String solrXml = IOUtils.toString(SolrCloudReportersTest.class.getResourceAsStream("/solr/solr-solrreporter.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));
    Thread.sleep(15000);
    cluster.getJettySolrRunners().forEach(jetty -> {
        CoreContainer cc = jetty.getCoreContainer();
        for (String name : cc.getLoadedCoreNames()) {
            SolrCore core = cc.getCore(name);
            try {
                String registryName = core.getCoreMetricManager().getRegistryName();
                String leaderRegistryName = core.getCoreMetricManager().getLeaderRegistryName();
                String coreName = core.getName();
                String collectionName = core.getCoreDescriptor().getCollectionName();
                String coreNodeName = core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName();
                String replicaName = coreName.substring(coreName.indexOf("_replica_") + 1);
                String shardId = core.getCoreDescriptor().getCloudDescriptor().getShardId();
                assertEquals("solr.core." + collectionName + "." + shardId + "." + replicaName, registryName);
                assertEquals("solr.collection." + collectionName + "." + shardId + ".leader", leaderRegistryName);
            } finally {
                if (core != null) {
                    core.close();
                }
            }
        }
        SolrMetricManager metricManager = cc.getMetricManager();
        Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.cluster");
        assertEquals(reporters.toString(), 1, reporters.size());
        SolrMetricReporter reporter = reporters.get("test");
        assertNotNull(reporter);
        assertTrue(reporter.toString(), reporter instanceof SolrClusterReporter);
        SolrClusterReporter sor = (SolrClusterReporter) reporter;
        assertEquals(5, sor.getPeriod());
        for (String registryName : metricManager.registryNames(".*\\.shard[0-9]\\.replica.*")) {
            reporters = metricManager.getReporters(registryName);
            assertEquals(reporters.toString(), 1 + jmxReporter, reporters.size());
            reporter = null;
            for (String name : reporters.keySet()) {
                if (name.startsWith("test")) {
                    reporter = reporters.get(name);
                }
            }
            assertNotNull(reporter);
            assertTrue(reporter.toString(), reporter instanceof SolrShardReporter);
            SolrShardReporter srr = (SolrShardReporter) reporter;
            assertEquals(5, srr.getPeriod());
        }
        for (String registryName : metricManager.registryNames(".*\\.leader")) {
            leaderRegistries++;
            reporters = metricManager.getReporters(registryName);
            assertEquals(reporters.toString(), 0, reporters.size());
            Map<String, Metric> metrics = metricManager.registry(registryName).getMetrics();
            String key = "QUERY./select.requests";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
            key = "UPDATE./update/json.requests";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
        }
        if (metricManager.registryNames().contains("solr.cluster")) {
            clusterRegistries++;
            Map<String, Metric> metrics = metricManager.registry("solr.cluster").getMetrics();
            String key = "jvm.memory.heap.init";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
            key = "leader.test_collection.shard1.UPDATE./update/json.requests.max";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
        }
    });
    assertEquals("leaderRegistries", 2, leaderRegistries);
    assertEquals("clusterRegistries", 1, clusterRegistries);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric) AggregateMetric(org.apache.solr.metrics.AggregateMetric) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 2 with SolrMetricReporter

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

the class SolrGraphiteReporterTest method testReporter.

@Test
public void testReporter() throws Exception {
    int jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1 : 0;
    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");
    MockGraphite mock = new MockGraphite();
    try {
        mock.start();
        Thread.sleep(1000);
        // define the port where MockGraphite is running
        System.setProperty("mock-graphite-port", String.valueOf(mock.port));
        String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-graphitereporter.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");
        assertEquals(1 + jmxReporter, reporters.size());
        SolrMetricReporter reporter = reporters.get("test");
        assertNotNull(reporter);
        assertTrue(reporter instanceof SolrGraphiteReporter);
        Thread.sleep(5000);
        assertTrue(mock.lines.size() >= 3);
        String[] frozenLines = (String[]) mock.lines.toArray(new String[mock.lines.size()]);
        for (String line : frozenLines) {
            assertTrue(line, line.startsWith("test.solr.node.CONTAINER.cores."));
        }
    } finally {
        mock.close();
    }
}
Also used : Path(java.nio.file.Path) 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)

Example 3 with SolrMetricReporter

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

the class SolrJmxReporterTest method testEnabled.

@Test
public void testEnabled() throws Exception {
    String root1 = TestUtil.randomSimpleString(random(), 5, 10);
    PluginInfo pluginInfo1 = createReporterPluginInfo(root1, true);
    metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo1, coreMetricManager.getTag());
    String root2 = TestUtil.randomSimpleString(random(), 5, 10);
    assertFalse(root2.equals(root1));
    PluginInfo pluginInfo2 = createReporterPluginInfo(root2, false);
    metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo2, coreMetricManager.getTag());
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
    assertTrue(reporters.containsKey(pluginInfo1.name + "@" + coreMetricManager.getTag()));
    assertTrue(reporters.containsKey(pluginInfo2.name + "@" + coreMetricManager.getTag()));
    String scope = SolrMetricTestUtils.getRandomScope(random(), true);
    SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random(), true);
    Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random(), true);
    SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
    coreMetricManager.registerMetricProducer(scope, producer);
    Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
    assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root1.equals(o.getObjectName().getDomain())).count());
    assertEquals(0, objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root2.equals(o.getObjectName().getDomain())).count());
}
Also used : Counter(com.codahale.metrics.Counter) SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) PluginInfo(org.apache.solr.core.PluginInfo) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 4 with SolrMetricReporter

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

the class SolrJmxReporterTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    initCore("solrconfig-basic.xml", "schema.xml");
    final SolrCore core = h.getCore();
    domain = core.getName();
    rootName = TestUtil.randomSimpleString(random(), 5, 10);
    coreMetricManager = core.getCoreMetricManager();
    metricManager = core.getCoreContainer().getMetricManager();
    PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
    metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, coreMetricManager.getTag());
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
    assertTrue("reporters.size should be > 0, but was + " + reporters.size(), reporters.size() > 0);
    reporterName = pluginInfo.name;
    String taggedName = reporterName + "@" + coreMetricManager.getTag();
    assertNotNull("reporter " + taggedName + " not present among " + reporters, reporters.get(taggedName));
    assertTrue("wrong reporter class: " + reporters.get(taggedName), reporters.get(taggedName) instanceof SolrJmxReporter);
    reporter = (SolrJmxReporter) reporters.get(taggedName);
    mBeanServer = reporter.getMBeanServer();
    assertNotNull("MBean server not found.", mBeanServer);
}
Also used : SolrCore(org.apache.solr.core.SolrCore) PluginInfo(org.apache.solr.core.PluginInfo) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Before(org.junit.Before)

Example 5 with SolrMetricReporter

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

SolrMetricReporter (org.apache.solr.metrics.SolrMetricReporter)8 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)6 Test (org.junit.Test)6 CoreContainer (org.apache.solr.core.CoreContainer)5 Path (java.nio.file.Path)3 NodeConfig (org.apache.solr.core.NodeConfig)3 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)3 TestHarness (org.apache.solr.util.TestHarness)3 PluginInfo (org.apache.solr.core.PluginInfo)2 SolrCore (org.apache.solr.core.SolrCore)2 Counter (com.codahale.metrics.Counter)1 Metric (com.codahale.metrics.Metric)1 GMetric (info.ganglia.gmetric4j.gmetric.GMetric)1 GMetricSlope (info.ganglia.gmetric4j.gmetric.GMetricSlope)1 GMetricType (info.ganglia.gmetric4j.gmetric.GMetricType)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 MBeanServer (javax.management.MBeanServer)1 ObjectInstance (javax.management.ObjectInstance)1