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