use of org.apache.solr.metrics.SolrMetricManager in project lucene-solr by apache.
the class LFUCache method initializeMetrics.
@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
registry = manager.registry(registryName);
cacheMap = new MetricsMap((detailed, map) -> {
if (cache != null) {
ConcurrentLFUCache.Stats stats = cache.getStats();
long lookups = stats.getCumulativeLookups();
long hits = stats.getCumulativeHits();
long inserts = stats.getCumulativePuts();
long evictions = stats.getCumulativeEvictions();
long size = stats.getCurrentSize();
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("timeDecay", timeDecay);
long clookups = 0;
long chits = 0;
long cinserts = 0;
long cevictions = 0;
// NOTE: It is safe to iterate on a CopyOnWriteArrayList
for (ConcurrentLFUCache.Stats statistics : statsList) {
clookups += statistics.getCumulativeLookups();
chits += statistics.getCumulativeHits();
cinserts += statistics.getCumulativePuts();
cevictions += statistics.getCumulativeEvictions();
}
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.getMostUsedItems(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 BasicFunctionalityTest method testSomeStuff.
@Test
public void testSomeStuff() throws Exception {
clearIndex();
SolrCore core = h.getCore();
// test that we got the expected config, not just hardcoded defaults
assertNotNull(core.getRequestHandler("mock"));
// test stats call
SolrMetricManager manager = core.getCoreContainer().getMetricManager();
String registry = core.getCoreMetricManager().getRegistryName();
Map<String, Metric> metrics = manager.registry(registry).getMetrics();
assertTrue(metrics.containsKey("CORE.coreName"));
assertTrue(metrics.containsKey("CORE.refCount"));
Gauge<Number> g = (Gauge<Number>) metrics.get("CORE.refCount");
assertTrue(g.getValue().intValue() > 0);
lrf.args.put(CommonParams.VERSION, "2.2");
assertQ("test query on empty index", req("qlkciyopsbgzyvkylsjhchghjrdf"), "//result[@numFound='0']");
// test escaping of ";"
assertU("deleting 42 for no reason at all", delI("42"));
assertU("adding doc#42", adoc("id", "42", "val_s", "aa;bb"));
assertU("does commit work?", commit());
assertQ("backslash escaping semicolon", req("id:42 AND val_s:aa\\;bb"), "//*[@numFound='1']", "//int[@name='id'][.='42']");
assertQ("quote escaping semicolon", req("id:42 AND val_s:\"aa;bb\""), "//*[@numFound='1']", "//int[@name='id'][.='42']");
assertQ("no escaping semicolon", req("id:42 AND val_s:aa"), "//*[@numFound='0']");
assertU(delI("42"));
assertU(commit());
assertQ(req("id:42"), "//*[@numFound='0']");
// test overwrite default of true
assertU(adoc("id", "42", "val_s", "AAA"));
assertU(adoc("id", "42", "val_s", "BBB"));
assertU(commit());
assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='BBB']");
assertU(adoc("id", "42", "val_s", "CCC"));
assertU(adoc("id", "42", "val_s", "DDD"));
assertU(commit());
assertQ(req("id:42"), "//*[@numFound='1']", "//str[.='DDD']");
// test deletes
String[] adds = new String[] { add(doc("id", "101"), "overwrite", "true"), add(doc("id", "101"), "overwrite", "true"), add(doc("id", "105"), "overwrite", "false"), add(doc("id", "102"), "overwrite", "true"), add(doc("id", "103"), "overwrite", "false"), add(doc("id", "101"), "overwrite", "true") };
for (String a : adds) {
assertU(a, a);
}
assertU(commit());
// test maxint
assertQ(req("q", "id:[100 TO 110]", "rows", "2147483647"), "//*[@numFound='4']");
// test big limit
assertQ(req("q", "id:[100 TO 111]", "rows", "1147483647"), "//*[@numFound='4']");
assertQ(req("id:[100 TO 110]"), "//*[@numFound='4']");
assertU(delI("102"));
assertU(commit());
assertQ(req("id:[100 TO 110]"), "//*[@numFound='3']");
assertU(delI("105"));
assertU(commit());
assertQ(req("id:[100 TO 110]"), "//*[@numFound='2']");
assertU(delQ("id:[100 TO 110]"));
assertU(commit());
assertQ(req("id:[100 TO 110]"), "//*[@numFound='0']");
assertU(h.simpleTag("rollback"));
assertU(commit());
}
use of org.apache.solr.metrics.SolrMetricManager in project lucene-solr by apache.
the class SolrIndexSearcher method register.
/**
* Register sub-objects such as caches and our own metrics
*/
public void register() {
final Map<String, SolrInfoBean> infoRegistry = core.getInfoRegistry();
// register self
infoRegistry.put(STATISTICS_KEY, this);
infoRegistry.put(name, this);
for (SolrCache cache : cacheList) {
cache.setState(SolrCache.State.LIVE);
infoRegistry.put(cache.name(), cache);
}
SolrMetricManager manager = core.getCoreContainer().getMetricManager();
String registry = core.getCoreMetricManager().getRegistryName();
for (SolrCache cache : cacheList) {
cache.initializeMetrics(manager, registry, SolrMetricManager.mkName(cache.name(), STATISTICS_KEY));
}
initializeMetrics(manager, registry, STATISTICS_KEY);
registerTime = new Date();
}
use of org.apache.solr.metrics.SolrMetricManager in project lucene-solr by apache.
the class SolrDispatchFilter method setupJvmMetrics.
private void setupJvmMetrics(CoreContainer coresInit) {
SolrMetricManager metricManager = coresInit.getMetricManager();
final Set<String> hiddenSysProps = coresInit.getConfig().getMetricsConfig().getHiddenSysProps();
try {
String registry = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
metricManager.registerAll(registry, new AltBufferPoolMetricSet(), true, "buffers");
metricManager.registerAll(registry, new ClassLoadingGaugeSet(), true, "classes");
metricManager.registerAll(registry, new OperatingSystemMetricSet(), true, "os");
metricManager.registerAll(registry, new GarbageCollectorMetricSet(), true, "gc");
metricManager.registerAll(registry, new MemoryUsageGaugeSet(), true, "memory");
// todo should we use CachedThreadStatesGaugeSet instead?
metricManager.registerAll(registry, new ThreadStatesGaugeSet(), true, "threads");
MetricsMap sysprops = new MetricsMap((detailed, map) -> {
System.getProperties().forEach((k, v) -> {
if (!hiddenSysProps.contains(k)) {
map.put(String.valueOf(k), v);
}
});
});
metricManager.registerGauge(null, registry, sysprops, true, "properties", "system");
} catch (Exception e) {
log.warn("Error registering JVM metrics", e);
}
}
Aggregations