use of org.apache.flink.metrics.MetricGroup 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() {
Configuration config = new Configuration();
config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "test");
config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter1.class.getName());
MetricRegistry registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
MetricGroup root = new TaskManagerMetricGroup(registry, "host", "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();
}
use of org.apache.flink.metrics.MetricGroup in project flink by apache.
the class MetricUtils method instantiateNetworkMetrics.
public static void instantiateNetworkMetrics(MetricGroup metrics, final NetworkEnvironment network) {
MetricGroup status = metrics.addGroup(METRIC_GROUP_STATUS_NAME);
MetricGroup networkGroup = status.addGroup("Network");
networkGroup.gauge("TotalMemorySegments", new Gauge<Integer>() {
@Override
public Integer getValue() {
return network.getNetworkBufferPool().getTotalNumberOfMemorySegments();
}
});
networkGroup.gauge("AvailableMemorySegments", new Gauge<Integer>() {
@Override
public Integer getValue() {
return network.getNetworkBufferPool().getNumberOfAvailableMemorySegments();
}
});
}
use of org.apache.flink.metrics.MetricGroup in project flink by apache.
the class TaskExecutorMetricsInitializer method instantiateStatusMetrics.
public static void instantiateStatusMetrics(MetricGroup taskManagerMetricGroup, NetworkEnvironment network) {
MetricGroup status = taskManagerMetricGroup.addGroup("Status");
instantiateNetworkMetrics(status.addGroup("Network"), network);
MetricGroup jvm = status.addGroup("JVM");
instantiateClassLoaderMetrics(jvm.addGroup("ClassLoader"));
instantiateGarbageCollectorMetrics(jvm.addGroup("GarbageCollector"));
instantiateMemoryMetrics(jvm.addGroup("Memory"));
instantiateThreadMetrics(jvm.addGroup("Threads"));
instantiateCPUMetrics(jvm.addGroup("CPU"));
}
Aggregations