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);
}
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();
}
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;
}
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());
}
Aggregations