Search in sources :

Example 16 with Histogram

use of com.codahale.metrics.Histogram in project graylog2-server by Graylog2.

the class SearchesTest method histogramRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void histogramRecordsMetrics() throws Exception {
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    HistogramResult h = searches.histogram("*", Searches.DateHistogramInterval.MINUTE, range);
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 17 with Histogram

use of com.codahale.metrics.Histogram in project graylog2-server by Graylog2.

the class SearchesTest method termsStatsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void termsStatsRecordsMetrics() throws Exception {
    TermsStatsResult r = searches.termsStats("message", "n", Searches.TermsStatsOrder.COUNT, 25, "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) TermsStatsResult(org.graylog2.indexer.results.TermsStatsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 18 with Histogram

use of com.codahale.metrics.Histogram in project chassis by Kixeye.

the class MetricsCloudWatchReporter method addHistograms.

private void addHistograms(SortedMap<String, Histogram> histograms, LinkedList<PutMetricDataRequest> requests, Date timestamp) {
    logger.debug("Adding Histograms...");
    for (String name : histograms.keySet()) {
        Histogram histogram = histograms.get(name);
        Snapshot snapshot = histogram.getSnapshot();
        checkAndAddDatum(MetricFilter.Stat.COUNT, name, histogram.getCount(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MIN, name, snapshot.getMin(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MAX, name, snapshot.getMax(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.MEAN, name, snapshot.getMean(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.STDDEV, name, snapshot.getStdDev(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_75, name, snapshot.get75thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_95, name, snapshot.get95thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_98, name, snapshot.get98thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_99, name, snapshot.get99thPercentile(), requests, timestamp);
        checkAndAddDatum(MetricFilter.Stat.PERCENTILE_999, name, snapshot.get999thPercentile(), requests, timestamp);
    }
}
Also used : Snapshot(com.codahale.metrics.Snapshot) Histogram(com.codahale.metrics.Histogram)

Example 19 with Histogram

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

the class MetricUtilsTest method testMetrics.

@Test
public void testMetrics() throws Exception {
    MetricRegistry registry = new MetricRegistry();
    Counter counter = registry.counter("counter");
    counter.inc();
    Timer timer = registry.timer("timer");
    Timer.Context ctx = timer.time();
    Thread.sleep(150);
    ctx.stop();
    Meter meter = registry.meter("meter");
    meter.mark();
    Histogram histogram = registry.histogram("histogram");
    histogram.update(10);
    AggregateMetric am = new AggregateMetric();
    registry.register("aggregate", am);
    am.set("foo", 10);
    am.set("bar", 1);
    am.set("bar", 2);
    Gauge<String> gauge = () -> "foobar";
    registry.register("gauge", gauge);
    Gauge<Long> error = () -> {
        throw new InternalError("Memory Pool not found error");
    };
    registry.register("memory.expected.error", error);
    MetricUtils.toMaps(registry, Collections.singletonList(MetricFilter.ALL), MetricFilter.ALL, MetricUtils.PropertyFilter.ALL, false, false, false, false, (k, o) -> {
        Map v = (Map) o;
        if (k.startsWith("counter")) {
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("gauge")) {
            assertEquals("foobar", v.get("value"));
        } else if (k.startsWith("timer")) {
            assertEquals(1L, v.get("count"));
            assertTrue(((Number) v.get("min_ms")).intValue() > 100);
        } else if (k.startsWith("meter")) {
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("histogram")) {
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("aggregate")) {
            assertEquals(2, v.get("count"));
            Map<String, Object> values = (Map<String, Object>) v.get("values");
            assertNotNull(values);
            assertEquals(2, values.size());
            Map<String, Object> update = (Map<String, Object>) values.get("foo");
            assertEquals(10, update.get("value"));
            assertEquals(1, update.get("updateCount"));
            update = (Map<String, Object>) values.get("bar");
            assertEquals(2, update.get("value"));
            assertEquals(2, update.get("updateCount"));
        } else if (k.startsWith("memory.expected.error")) {
            assertNull(v);
        }
    });
    // test compact format
    MetricUtils.toMaps(registry, Collections.singletonList(MetricFilter.ALL), MetricFilter.ALL, MetricUtils.PropertyFilter.ALL, false, false, true, false, (k, o) -> {
        if (k.startsWith("counter")) {
            assertTrue(o instanceof Long);
            assertEquals(1L, o);
        } else if (k.startsWith("gauge")) {
            assertTrue(o instanceof String);
            assertEquals("foobar", o);
        } else if (k.startsWith("timer")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
            assertTrue(((Number) v.get("min_ms")).intValue() > 100);
        } else if (k.startsWith("meter")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("histogram")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("aggregate")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(2, v.get("count"));
            Map<String, Object> values = (Map<String, Object>) v.get("values");
            assertNotNull(values);
            assertEquals(2, values.size());
            Map<String, Object> update = (Map<String, Object>) values.get("foo");
            assertEquals(10, update.get("value"));
            assertEquals(1, update.get("updateCount"));
            update = (Map<String, Object>) values.get("bar");
            assertEquals(2, update.get("value"));
            assertEquals(2, update.get("updateCount"));
        } else if (k.startsWith("memory.expected.error")) {
            assertNull(o);
        } else {
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
        }
    });
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 20 with Histogram

use of com.codahale.metrics.Histogram 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)

Aggregations

Histogram (com.codahale.metrics.Histogram)40 Test (org.junit.Test)18 Timer (com.codahale.metrics.Timer)17 Meter (com.codahale.metrics.Meter)13 Counter (com.codahale.metrics.Counter)11 Snapshot (com.codahale.metrics.Snapshot)8 Gauge (com.codahale.metrics.Gauge)7 MetricRegistry (com.codahale.metrics.MetricRegistry)7 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 ZonedDateTime (java.time.ZonedDateTime)5 Map (java.util.Map)5 DateTime (org.joda.time.DateTime)5 Metric (com.codahale.metrics.Metric)4 UniformReservoir (com.codahale.metrics.UniformReservoir)3 SortedMap (java.util.SortedMap)3 AggregateMetric (org.apache.solr.metrics.AggregateMetric)3 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 MetricFilter (com.codahale.metrics.MetricFilter)2 Reservoir (com.codahale.metrics.Reservoir)2