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());
}
});
}
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."));
}
}
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"));
}
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();
}
}
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);
}
Aggregations