use of org.apache.solr.metrics.SolrMetricManager in project lucene-solr by apache.
the class Metrics method initializeMetrics.
@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
registry = manager.registry(registryName);
metricsMap = new MetricsMap((detailed, map) -> {
long now = System.nanoTime();
long delta = Math.max(now - previous, 1);
double seconds = delta / 1000000000.0;
long hits_total = blockCacheHit.get();
long hits_delta = hits_total - blockCacheHit_last.get();
blockCacheHit_last.set(hits_total);
long miss_total = blockCacheMiss.get();
long miss_delta = miss_total - blockCacheMiss_last.get();
blockCacheMiss_last.set(miss_total);
long evict_total = blockCacheEviction.get();
long evict_delta = evict_total - blockCacheEviction_last.get();
blockCacheEviction_last.set(evict_total);
long storeFail_total = blockCacheStoreFail.get();
long storeFail_delta = storeFail_total - blockCacheStoreFail_last.get();
blockCacheStoreFail_last.set(storeFail_total);
long lookups_delta = hits_delta + miss_delta;
long lookups_total = hits_total + miss_total;
map.put("size", blockCacheSize.get());
map.put("lookups", lookups_total);
map.put("hits", hits_total);
map.put("evictions", evict_total);
map.put("storeFails", storeFail_total);
// hit ratio since the last call
map.put("hitratio_current", calcHitRatio(lookups_delta, hits_delta));
// lookups per second since the last call
map.put("lookups_persec", getPerSecond(lookups_delta, seconds));
// hits per second since the last call
map.put("hits_persec", getPerSecond(hits_delta, seconds));
// evictions per second since the last call
map.put("evictions_persec", getPerSecond(evict_delta, seconds));
// evictions per second since the last call
map.put("storeFails_persec", getPerSecond(storeFail_delta, seconds));
// seconds since last call
map.put("time_delta", seconds);
// TODO: these aren't really related to the BlockCache
map.put("buffercache.allocations", getPerSecond(shardBuffercacheAllocate.getAndSet(0), seconds));
map.put("buffercache.lost", getPerSecond(shardBuffercacheLost.getAndSet(0), seconds));
previous = now;
});
manager.registerGauge(this, registryName, metricsMap, true, getName(), getCategory().toString(), scope);
}
use of org.apache.solr.metrics.SolrMetricManager in project lucene-solr by apache.
the class SolrInfoBeanTest method testCallMBeanInfo.
/**
* Gets a list of everything we can find in the classpath and makes sure it has
* a name, description, etc...
*/
public void testCallMBeanInfo() throws Exception {
List<Class> classes = new ArrayList<>();
classes.addAll(getClassesForPackage(StandardRequestHandler.class.getPackage().getName()));
classes.addAll(getClassesForPackage(SearchComponent.class.getPackage().getName()));
classes.addAll(getClassesForPackage(LukeRequestHandler.class.getPackage().getName()));
classes.addAll(getClassesForPackage(DefaultSolrHighlighter.class.getPackage().getName()));
classes.addAll(getClassesForPackage(LRUCache.class.getPackage().getName()));
// System.out.println(classes);
int checked = 0;
SolrMetricManager metricManager = h.getCoreContainer().getMetricManager();
String registry = h.getCore().getCoreMetricManager().getRegistryName();
String scope = TestUtil.randomSimpleString(random(), 2, 10);
for (Class clazz : classes) {
if (SolrInfoBean.class.isAssignableFrom(clazz)) {
try {
SolrInfoBean info = (SolrInfoBean) clazz.newInstance();
if (info instanceof SolrMetricProducer) {
((SolrMetricProducer) info).initializeMetrics(metricManager, registry, scope);
}
//System.out.println( info.getClass() );
assertNotNull(info.getName());
assertNotNull(info.getDescription());
assertNotNull(info.getCategory());
if (info instanceof LRUCache) {
continue;
}
assertNotNull(info.toString());
checked++;
} catch (InstantiationException ex) {
// expected...
//System.out.println( "unable to initialize: "+clazz );
}
}
}
assertTrue("there are at least 10 SolrInfoBean that should be found in the classpath, found " + checked, checked > 10);
}
use of org.apache.solr.metrics.SolrMetricManager in project lucene-solr by apache.
the class FastLRUCache method initializeMetrics.
@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
registry = manager.registry(registryName);
cacheMap = new MetricsMap((detailed, map) -> {
if (cache != null) {
ConcurrentLRUCache.Stats stats = cache.getStats();
long lookups = stats.getCumulativeLookups();
long hits = stats.getCumulativeHits();
long inserts = stats.getCumulativePuts();
long evictions = stats.getCumulativeEvictions();
long size = stats.getCurrentSize();
long clookups = 0;
long chits = 0;
long cinserts = 0;
long cevictions = 0;
// NOTE: It is safe to iterate on a CopyOnWriteArrayList
for (ConcurrentLRUCache.Stats statistiscs : statsList) {
clookups += statistiscs.getCumulativeLookups();
chits += statistiscs.getCumulativeHits();
cinserts += statistiscs.getCumulativePuts();
cevictions += statistiscs.getCumulativeEvictions();
}
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("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.getLatestAccessedItems(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());
}
use of org.apache.solr.metrics.SolrMetricManager in project lucene-solr by apache.
the class BufferStoreTest method setup.
@Before
public void setup() {
metrics = new Metrics();
SolrMetricManager metricManager = new SolrMetricManager();
String registry = TestUtil.randomSimpleString(random(), 2, 10);
String scope = TestUtil.randomSimpleString(random(), 2, 10);
metrics.initializeMetrics(metricManager, registry, scope);
metricsMap = (MetricsMap) metricManager.registry(registry).getMetrics().get("CACHE." + scope + ".hdfsBlockCache");
BufferStore.initNewBuffer(blockSize, blockSize, metrics);
store = BufferStore.instance(blockSize);
}
use of org.apache.solr.metrics.SolrMetricManager 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);
}
Aggregations