Search in sources :

Example 6 with GMetric

use of info.ganglia.gmetric4j.gmetric.GMetric 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)

Aggregations

GMetric (info.ganglia.gmetric4j.gmetric.GMetric)6 GMetricType (info.ganglia.gmetric4j.gmetric.GMetricType)2 IOException (java.io.IOException)2 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)2 MetricFilter (com.codahale.metrics.MetricFilter)1 GangliaReporter (com.codahale.metrics.ganglia.GangliaReporter)1 Result (com.googlecode.jmxtrans.model.Result)1 GMetricPublisher (info.ganglia.gmetric4j.gmetric.GMetricPublisher)1 GMetricSlope (info.ganglia.gmetric4j.gmetric.GMetricSlope)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Start (ninja.lifecycle.Start)1 CoreContainer (org.apache.solr.core.CoreContainer)1 NodeConfig (org.apache.solr.core.NodeConfig)1 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)1 SolrMetricReporter (org.apache.solr.metrics.SolrMetricReporter)1 TestHarness (org.apache.solr.util.TestHarness)1 Test (org.junit.Test)1