Search in sources :

Example 21 with MetricGroup

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();
}
Also used : Histogram(org.apache.flink.metrics.Histogram) Counter(org.apache.flink.metrics.Counter) Configuration(org.apache.flink.configuration.Configuration) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) MetricGroup(org.apache.flink.metrics.MetricGroup) HistogramStatistics(org.apache.flink.metrics.HistogramStatistics) Test(org.junit.Test)

Example 22 with MetricGroup

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();
        }
    });
}
Also used : MetricGroup(org.apache.flink.metrics.MetricGroup)

Example 23 with MetricGroup

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"));
}
Also used : MetricGroup(org.apache.flink.metrics.MetricGroup)

Aggregations

MetricGroup (org.apache.flink.metrics.MetricGroup)23 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 Gauge (org.apache.flink.metrics.Gauge)5 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)5 List (java.util.List)4 Map (java.util.Map)4 TaskInfo (org.apache.flink.api.common.TaskInfo)4 RuntimeUDFContext (org.apache.flink.api.common.functions.util.RuntimeUDFContext)4 Configuration (org.apache.flink.configuration.Configuration)4 HashMap (java.util.HashMap)3 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)3 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)3 MetricRegistryConfiguration (org.apache.flink.runtime.metrics.MetricRegistryConfiguration)3 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)2 MemoryMXBean (java.lang.management.MemoryMXBean)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)2 Counter (org.apache.flink.metrics.Counter)2 Histogram (org.apache.flink.metrics.Histogram)2