Search in sources :

Example 1 with TestMeter

use of org.apache.flink.metrics.util.TestMeter in project flink by apache.

the class JMXReporterTest method testMeterReporting.

/**
	 * Tests that meters are properly reported via the JMXReporter.
	 */
@Test
public void testMeterReporting() throws Exception {
    MetricRegistry registry = null;
    String meterName = "meter";
    try {
        Configuration config = new Configuration();
        config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "jmx_test");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "jmx_test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
        registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
        TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
        TestMeter meter = new TestMeter();
        metricGroup.meter(meterName, meter);
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + meterName, JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
        MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
        MBeanAttributeInfo[] attributeInfos = info.getAttributes();
        assertEquals(2, attributeInfos.length);
        assertEquals(meter.getRate(), mBeanServer.getAttribute(objectName, "Rate"));
        assertEquals(meter.getCount(), mBeanServer.getAttribute(objectName, "Count"));
    } finally {
        if (registry != null) {
            registry.shutdown();
        }
    }
}
Also used : TestMeter(org.apache.flink.metrics.util.TestMeter) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MBeanInfo(javax.management.MBeanInfo) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 2 with TestMeter

use of org.apache.flink.metrics.util.TestMeter in project flink by apache.

the class FlinkMeterWrapperTest method testWrapper.

@Test
public void testWrapper() {
    Meter meter = new TestMeter();
    FlinkMeterWrapper wrapper = new FlinkMeterWrapper(meter);
    assertEquals(0, wrapper.getMeanRate(), DELTA);
    assertEquals(5, wrapper.getOneMinuteRate(), DELTA);
    assertEquals(0, wrapper.getFiveMinuteRate(), DELTA);
    assertEquals(0, wrapper.getFifteenMinuteRate(), DELTA);
    assertEquals(100L, wrapper.getCount());
}
Also used : TestMeter(org.apache.flink.metrics.util.TestMeter) Meter(org.apache.flink.metrics.Meter) TestMeter(org.apache.flink.metrics.util.TestMeter) Test(org.junit.Test)

Example 3 with TestMeter

use of org.apache.flink.metrics.util.TestMeter in project flink by apache.

the class StatsDReporterTest method testStatsDMetersReporting.

/**
	 * Tests that meters are properly reported via the StatsD reporter
	 */
@Test
public void testStatsDMetersReporting() throws Exception {
    MetricRegistry registry = null;
    DatagramSocketReceiver receiver = null;
    Thread receiverThread = null;
    long timeout = 5000;
    long joinTimeout = 30000;
    String meterName = "meter";
    try {
        receiver = new DatagramSocketReceiver();
        receiverThread = new Thread(receiver);
        receiverThread.start();
        int port = receiver.getPort();
        Configuration config = new Configuration();
        config.setString(ConfigConstants.METRICS_REPORTERS_LIST, "test");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, StatsDReporter.class.getName());
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, "1 SECONDS");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test.host", "localhost");
        config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test.port", "" + port);
        registry = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(config));
        TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
        TestMeter meter = new TestMeter();
        metricGroup.meter(meterName, meter);
        String prefix = metricGroup.getMetricIdentifier(meterName);
        Set<String> expectedLines = new HashSet<>();
        expectedLines.add(prefix + ".rate:5.0|g");
        expectedLines.add(prefix + ".count:100|g");
        receiver.waitUntilNumLines(expectedLines.size(), timeout);
        Set<String> lines = receiver.getLines();
        assertEquals(expectedLines, lines);
    } finally {
        if (registry != null) {
            registry.shutdown();
        }
        if (receiver != null) {
            receiver.stop();
        }
        if (receiverThread != null) {
            receiverThread.join(joinTimeout);
        }
    }
}
Also used : TestMeter(org.apache.flink.metrics.util.TestMeter) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TestMeter (org.apache.flink.metrics.util.TestMeter)3 Test (org.junit.Test)3 Configuration (org.apache.flink.configuration.Configuration)2 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)2 MetricRegistryConfiguration (org.apache.flink.runtime.metrics.MetricRegistryConfiguration)2 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)2 HashSet (java.util.HashSet)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 Meter (org.apache.flink.metrics.Meter)1