Search in sources :

Example 26 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class SolrMetricManager method registerAll.

/**
   * Register all metrics in the provided {@link MetricSet}, optionally skipping those that
   * already exist.
   * @param registry registry name
   * @param metrics metric set to register
   * @param force if true then already existing metrics with the same name will be replaced.
   *                     When false and a metric with the same name already exists an exception
   *                     will be thrown.
   * @param metricPath (optional) additional top-most metric name path elements
   * @throws Exception if a metric with this name already exists.
   */
public void registerAll(String registry, MetricSet metrics, boolean force, String... metricPath) throws Exception {
    MetricRegistry metricRegistry = registry(registry);
    synchronized (metricRegistry) {
        Map<String, Metric> existingMetrics = metricRegistry.getMetrics();
        for (Map.Entry<String, Metric> entry : metrics.getMetrics().entrySet()) {
            String fullName = mkName(entry.getKey(), metricPath);
            if (force && existingMetrics.containsKey(fullName)) {
                metricRegistry.remove(fullName);
            }
            metricRegistry.register(fullName, entry.getValue());
        }
    }
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 27 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class MetricsHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    if (container == null) {
        throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "Core container instance not initialized");
    }
    boolean compact = req.getParams().getBool(COMPACT_PARAM, true);
    MetricFilter mustMatchFilter = parseMustMatchFilter(req);
    MetricUtils.PropertyFilter propertyFilter = parsePropertyFilter(req);
    List<MetricType> metricTypes = parseMetricTypes(req);
    List<MetricFilter> metricFilters = metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
    Set<String> requestedRegistries = parseRegistries(req);
    NamedList response = new SimpleOrderedMap();
    for (String registryName : requestedRegistries) {
        MetricRegistry registry = metricManager.registry(registryName);
        SimpleOrderedMap result = new SimpleOrderedMap();
        MetricUtils.toMaps(registry, metricFilters, mustMatchFilter, propertyFilter, false, false, compact, false, (k, v) -> result.add(k, v));
        if (result.size() > 0) {
            response.add(registryName, result);
        }
    }
    rsp.getValues().add("metrics", response);
}
Also used : NamedList(org.apache.solr.common.util.NamedList) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricUtils(org.apache.solr.util.stats.MetricUtils) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) MetricFilter(com.codahale.metrics.MetricFilter) SolrException(org.apache.solr.common.SolrException)

Example 28 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class MetricUtils method toMaps.

/**
   * Convert selected metrics to maps or to flattened objects.
   * @param registry source of metrics
   * @param shouldMatchFilters metrics must match any of these filters
   * @param mustMatchFilter metrics must match this filter
   * @param propertyFilter limit what properties of a metric are returned
   * @param skipHistograms discard any {@link Histogram}-s and histogram parts of {@link Timer}-s.
   * @param skipAggregateValues discard internal values of {@link AggregateMetric}-s.
   * @param compact use compact representation for counters and gauges.
   * @param simple use simplified representation for complex metrics - instead of a (name, map)
   *             only the selected (name "." key, value) pairs will be produced.
   * @param consumer consumer that accepts produced objects
   */
public static void toMaps(MetricRegistry registry, List<MetricFilter> shouldMatchFilters, MetricFilter mustMatchFilter, PropertyFilter propertyFilter, boolean skipHistograms, boolean skipAggregateValues, boolean compact, boolean simple, BiConsumer<String, Object> consumer) {
    final Map<String, Metric> metrics = registry.getMetrics();
    final SortedSet<String> names = registry.getNames();
    names.stream().filter(s -> shouldMatchFilters.stream().anyMatch(metricFilter -> metricFilter.matches(s, metrics.get(s)))).filter(s -> mustMatchFilter.matches(s, metrics.get(s))).forEach(n -> {
        Metric metric = metrics.get(n);
        convertMetric(n, metric, propertyFilter, skipHistograms, skipAggregateValues, compact, simple, consumer);
    });
}
Also used : Histogram(com.codahale.metrics.Histogram) SortedSet(java.util.SortedSet) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Meter(com.codahale.metrics.Meter) InstrumentedExecutorService(com.codahale.metrics.InstrumentedExecutorService) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Counter(com.codahale.metrics.Counter) PlatformManagedObject(java.lang.management.PlatformManagedObject) MetricFilter(com.codahale.metrics.MetricFilter) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) ExecutorService(java.util.concurrent.ExecutorService) AggregateMetric(org.apache.solr.metrics.AggregateMetric) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Metric(com.codahale.metrics.Metric) Snapshot(com.codahale.metrics.Snapshot) NamedList(org.apache.solr.common.util.NamedList) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) PropertyDescriptor(java.beans.PropertyDescriptor) SolrInfoBean(org.apache.solr.core.SolrInfoBean) Timer(com.codahale.metrics.Timer) Gauge(com.codahale.metrics.Gauge) Collections(java.util.Collections) SolrInputDocument(org.apache.solr.common.SolrInputDocument) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric)

Example 29 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class TestRecovery method getMetrics.

private Map<String, Metric> getMetrics() {
    SolrMetricManager manager = h.getCoreContainer().getMetricManager();
    MetricRegistry registry = manager.registry(h.getCore().getCoreMetricManager().getRegistryName());
    return registry.getMetrics();
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Example 30 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class TestCoreAdmin method testCoreSwap.

@Test
public void testCoreSwap() throws Exception {
    // index marker docs to core0
    SolrClient cli0 = getSolrCore0();
    SolrInputDocument d = new SolrInputDocument("id", "core0-0");
    cli0.add(d);
    d = new SolrInputDocument("id", "core0-1");
    cli0.add(d);
    cli0.commit();
    // index a marker doc to core1
    SolrClient cli1 = getSolrCore1();
    d = new SolrInputDocument("id", "core1-0");
    cli1.add(d);
    cli1.commit();
    // initial state assertions
    SolrQuery q = new SolrQuery("*:*");
    QueryResponse rsp = cli0.query(q);
    SolrDocumentList docs = rsp.getResults();
    assertEquals(2, docs.size());
    docs.forEach(doc -> {
        assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core0-"));
    });
    rsp = cli1.query(q);
    docs = rsp.getResults();
    assertEquals(1, docs.size());
    docs.forEach(doc -> {
        assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core1-"));
    });
    // assert initial metrics
    SolrMetricManager metricManager = cores.getMetricManager();
    String core0RegistryName = SolrCoreMetricManager.createRegistryName(false, null, null, null, "core0");
    String core1RegistryName = SolrCoreMetricManager.createRegistryName(false, null, null, null, "core1");
    MetricRegistry core0Registry = metricManager.registry(core0RegistryName);
    MetricRegistry core1Registry = metricManager.registry(core1RegistryName);
    // 2 docs + 1 commit
    assertEquals(3, core0Registry.counter("UPDATE./update.requests").getCount());
    // 1 doc + 1 commit
    assertEquals(2, core1Registry.counter("UPDATE./update.requests").getCount());
    // swap
    CoreAdminRequest.swapCore("core0", "core1", getSolrAdmin());
    // assert state after swap
    cli0 = getSolrCore0();
    cli1 = getSolrCore1();
    rsp = cli0.query(q);
    docs = rsp.getResults();
    assertEquals(1, docs.size());
    docs.forEach(doc -> {
        assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core1-"));
    });
    rsp = cli1.query(q);
    docs = rsp.getResults();
    assertEquals(2, docs.size());
    docs.forEach(doc -> {
        assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core0-"));
    });
    core0Registry = metricManager.registry(core0RegistryName);
    core1Registry = metricManager.registry(core1RegistryName);
    assertEquals(2, core0Registry.counter("UPDATE./update.requests").getCount());
    assertEquals(3, core1Registry.counter("UPDATE./update.requests").getCount());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) MetricRegistry(com.codahale.metrics.MetricRegistry) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)505 Test (org.junit.Test)177 Before (org.junit.Before)61 Test (org.junit.jupiter.api.Test)45 VerifiableProperties (com.github.ambry.config.VerifiableProperties)42 ArrayList (java.util.ArrayList)33 Counter (com.codahale.metrics.Counter)30 File (java.io.File)29 Properties (java.util.Properties)28 List (java.util.List)23 Metric (com.codahale.metrics.Metric)22 Map (java.util.Map)22 IOException (java.io.IOException)21 HashMap (java.util.HashMap)20 Size (com.github.joschi.jadconfig.util.Size)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 TimeUnit (java.util.concurrent.TimeUnit)17 Timer (com.codahale.metrics.Timer)15 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)15