Search in sources :

Example 16 with Histogram

use of org.apache.flink.metrics.Histogram in project flink by apache.

the class MetricQueryServiceTest method testCreateDump.

@Test
public void testCreateDump() throws Exception {
    MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
    queryService.start();
    final Counter c = new SimpleCounter();
    final Gauge<String> g = () -> "Hello";
    final Histogram h = new TestHistogram();
    final Meter m = new TestMeter();
    final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();
    queryService.addMetric("counter", c, tm);
    queryService.addMetric("gauge", g, tm);
    queryService.addMetric("histogram", h, tm);
    queryService.addMetric("meter", m, tm);
    MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();
    assertTrue(dump.serializedCounters.length > 0);
    assertTrue(dump.serializedGauges.length > 0);
    assertTrue(dump.serializedHistograms.length > 0);
    assertTrue(dump.serializedMeters.length > 0);
    queryService.removeMetric(c);
    queryService.removeMetric(g);
    queryService.removeMetric(h);
    queryService.removeMetric(m);
    MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();
    assertEquals(0, emptyDump.serializedCounters.length);
    assertEquals(0, emptyDump.serializedGauges.length);
    assertEquals(0, emptyDump.serializedHistograms.length);
    assertEquals(0, emptyDump.serializedMeters.length);
}
Also used : TestMeter(org.apache.flink.metrics.util.TestMeter) Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestMeter(org.apache.flink.metrics.util.TestMeter) Meter(org.apache.flink.metrics.Meter) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.Test)

Example 17 with Histogram

use of org.apache.flink.metrics.Histogram in project flink by apache.

the class MetricGroupRegistrationTest method testMetricInstantiation.

/**
 * Verifies that group methods instantiate the correct metric with the given name.
 */
@Test
public void testMetricInstantiation() throws Exception {
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Collections.singletonList(ReporterSetup.forReporter("test", new TestReporter1())));
    MetricGroup root = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "host", new ResourceID("id"));
    Counter counter = root.counter("counter");
    assertEquals(counter, TestReporter1.lastPassedMetric);
    assertEquals("counter", TestReporter1.lastPassedName);
    Gauge<Object> gauge = root.gauge("gauge", new Gauge<Object>() {

        @Override
        public Object getValue() {
            return null;
        }
    });
    Assert.assertEquals(gauge, TestReporter1.lastPassedMetric);
    assertEquals("gauge", TestReporter1.lastPassedName);
    Histogram histogram = root.histogram("histogram", new Histogram() {

        @Override
        public void update(long value) {
        }

        @Override
        public long getCount() {
            return 0;
        }

        @Override
        public HistogramStatistics getStatistics() {
            return null;
        }
    });
    Assert.assertEquals(histogram, TestReporter1.lastPassedMetric);
    assertEquals("histogram", TestReporter1.lastPassedName);
    registry.shutdown().get();
}
Also used : Histogram(org.apache.flink.metrics.Histogram) Counter(org.apache.flink.metrics.Counter) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricGroup(org.apache.flink.metrics.MetricGroup) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) HistogramStatistics(org.apache.flink.metrics.HistogramStatistics) Test(org.junit.Test)

Example 18 with Histogram

use of org.apache.flink.metrics.Histogram in project flink by apache.

the class MetricFetcherTest method createRequestDumpAnswer.

private static MetricDumpSerialization.MetricSerializationResult createRequestDumpAnswer(ResourceID tmRID, JobID jobID) {
    Map<Counter, Tuple2<QueryScopeInfo, String>> counters = new HashMap<>();
    Map<Gauge<?>, Tuple2<QueryScopeInfo, String>> gauges = new HashMap<>();
    Map<Histogram, Tuple2<QueryScopeInfo, String>> histograms = new HashMap<>();
    Map<Meter, Tuple2<QueryScopeInfo, String>> meters = new HashMap<>();
    SimpleCounter c1 = new SimpleCounter();
    SimpleCounter c2 = new SimpleCounter();
    c1.inc(1);
    c2.inc(2);
    counters.put(c1, new Tuple2<>(new QueryScopeInfo.OperatorQueryScopeInfo(jobID.toString(), "taskid", 2, "opname", "abc"), "oc"));
    counters.put(c2, new Tuple2<>(new QueryScopeInfo.TaskQueryScopeInfo(jobID.toString(), "taskid", 2, "abc"), "tc"));
    meters.put(new Meter() {

        @Override
        public void markEvent() {
        }

        @Override
        public void markEvent(long n) {
        }

        @Override
        public double getRate() {
            return 5;
        }

        @Override
        public long getCount() {
            return 10;
        }
    }, new Tuple2<>(new QueryScopeInfo.JobQueryScopeInfo(jobID.toString(), "abc"), "jc"));
    gauges.put(new Gauge<String>() {

        @Override
        public String getValue() {
            return "x";
        }
    }, new Tuple2<>(new QueryScopeInfo.TaskManagerQueryScopeInfo(tmRID.toString(), "abc"), "gauge"));
    histograms.put(new TestHistogram(), new Tuple2<>(new QueryScopeInfo.JobManagerQueryScopeInfo("abc"), "hist"));
    MetricDumpSerialization.MetricDumpSerializer serializer = new MetricDumpSerialization.MetricDumpSerializer();
    MetricDumpSerialization.MetricSerializationResult dump = serializer.serialize(counters, gauges, histograms, meters);
    serializer.close();
    return dump;
}
Also used : Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) HashMap(java.util.HashMap) Meter(org.apache.flink.metrics.Meter) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) MetricDumpSerialization(org.apache.flink.runtime.metrics.dump.MetricDumpSerialization) Tuple2(org.apache.flink.api.java.tuple.Tuple2)

Example 19 with Histogram

use of org.apache.flink.metrics.Histogram in project flink by apache.

the class MetricListenerTest method testRegisterMetrics.

@Test
public void testRegisterMetrics() {
    MetricListener metricListener = new MetricListener();
    final MetricGroup metricGroup = metricListener.getMetricGroup();
    // Counter
    final Counter counter = metricGroup.counter(COUNTER_NAME);
    counter.inc(15213);
    final Optional<Counter> registeredCounter = metricListener.getCounter(COUNTER_NAME);
    assertTrue(registeredCounter.isPresent());
    assertEquals(15213L, registeredCounter.get().getCount());
    // Gauge
    metricGroup.gauge(GAUGE_NAME, () -> 15213);
    final Optional<Gauge<Integer>> registeredGauge = metricListener.getGauge(GAUGE_NAME);
    assertTrue(registeredGauge.isPresent());
    assertEquals(Integer.valueOf(15213), registeredGauge.get().getValue());
    // Meter
    metricGroup.meter(METER_NAME, new Meter() {

        @Override
        public void markEvent() {
        }

        @Override
        public void markEvent(long n) {
        }

        @Override
        public double getRate() {
            return 15213.0;
        }

        @Override
        public long getCount() {
            return 18213L;
        }
    });
    final Optional<Meter> registeredMeter = metricListener.getMeter(METER_NAME);
    assertTrue(registeredMeter.isPresent());
    assertEquals(15213.0, registeredMeter.get().getRate(), 0.1);
    assertEquals(18213L, registeredMeter.get().getCount());
    // Histogram
    metricGroup.histogram(HISTOGRAM_NAME, new Histogram() {

        @Override
        public void update(long value) {
        }

        @Override
        public long getCount() {
            return 15213L;
        }

        @Override
        public HistogramStatistics getStatistics() {
            return null;
        }
    });
    final Optional<Histogram> registeredHistogram = metricListener.getHistogram(HISTOGRAM_NAME);
    assertTrue(registeredHistogram.isPresent());
    assertEquals(15213L, registeredHistogram.get().getCount());
}
Also used : Histogram(org.apache.flink.metrics.Histogram) Meter(org.apache.flink.metrics.Meter) MetricGroup(org.apache.flink.metrics.MetricGroup) MetricListener(org.apache.flink.metrics.testutils.MetricListener) Gauge(org.apache.flink.metrics.Gauge) Counter(org.apache.flink.metrics.Counter) HistogramStatistics(org.apache.flink.metrics.HistogramStatistics) Test(org.junit.Test)

Aggregations

Histogram (org.apache.flink.metrics.Histogram)19 Counter (org.apache.flink.metrics.Counter)14 Meter (org.apache.flink.metrics.Meter)13 Gauge (org.apache.flink.metrics.Gauge)11 TestHistogram (org.apache.flink.metrics.util.TestHistogram)9 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 SimpleCounter (org.apache.flink.metrics.SimpleCounter)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)5 MetricGroup (org.apache.flink.metrics.MetricGroup)4 HashMap (java.util.HashMap)3 HistogramStatistics (org.apache.flink.metrics.HistogramStatistics)3 TestMeter (org.apache.flink.metrics.util.TestMeter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 MetricDumpSerialization (org.apache.flink.runtime.metrics.dump.MetricDumpSerialization)2 AbstractMetricGroup (org.apache.flink.runtime.metrics.groups.AbstractMetricGroup)2 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)2