Java Code Examples for org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup#close()

The following examples show how to use org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricRegistryImplTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigurableDelimiterForReportersInGroup() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B");

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
	List<MetricReporter> reporters = registry.getReporters();
	((TestReporter8) reporters.get(0)).expectedDelimiter = '_'; //test1  reporter
	((TestReporter8) reporters.get(1)).expectedDelimiter = '-'; //test2 reporter
	((TestReporter8) reporters.get(2)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //test3 reporter, because 'AA' - not correct delimiter
	((TestReporter8) reporters.get(3)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //for test4 reporter use global delimiter

	TaskManagerMetricGroup group = new TaskManagerMetricGroup(registry, "host", "id");
	group.counter("C");
	group.close();
	registry.shutdown().get();
	assertEquals(4, TestReporter8.numCorrectDelimitersForRegister);
	assertEquals(4, TestReporter8.numCorrectDelimitersForUnregister);
}
 
Example 2
Source File: MetricRegistryImplTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that reporters are notified of added/removed metrics.
 */
@Test
public void testReporterNotifications() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter6.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter7.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));

	TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");
	root.counter("rootCounter");

	assertTrue(TestReporter6.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.addedMetricName);

	assertTrue(TestReporter7.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.addedMetricName);

	root.close();

	assertTrue(TestReporter6.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.removedMetricName);

	assertTrue(TestReporter7.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.removedMetricName);

	registry.shutdown().get();
}
 
Example 3
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that reporters are notified of added/removed metrics.
 */
@Test
public void testReporterNotifications() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter6.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter7.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", new TestReporter6()),
			ReporterSetup.forReporter("test2", new TestReporter7())));

	TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");
	root.counter("rootCounter");

	assertTrue(TestReporter6.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.addedMetricName);

	assertTrue(TestReporter7.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.addedMetricName);

	root.close();

	assertTrue(TestReporter6.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.removedMetricName);

	assertTrue(TestReporter7.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.removedMetricName);

	registry.shutdown().get();
}
 
Example 4
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that reporters are notified of added/removed metrics.
 */
@Test
public void testReporterNotifications() throws Exception {
	Configuration config = new Configuration();
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter6.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter7.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", new TestReporter6()),
			ReporterSetup.forReporter("test2", new TestReporter7())));

	TaskManagerMetricGroup root = new TaskManagerMetricGroup(registry, "host", "id");
	root.counter("rootCounter");

	assertTrue(TestReporter6.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.addedMetricName);

	assertTrue(TestReporter7.addedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.addedMetricName);

	root.close();

	assertTrue(TestReporter6.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter6.removedMetricName);

	assertTrue(TestReporter7.removedMetric instanceof Counter);
	assertEquals("rootCounter", TestReporter7.removedMetricName);

	registry.shutdown().get();
}
 
Example 5
Source File: JMXReporterTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that multiple JMXReporters can be started on the same machine and register metrics at the MBeanServer.
 *
 * @throws Exception if the attribute/mbean could not be found or the test is broken
 */
@Test
public void testPortConflictHandling() throws Exception {
	Configuration cfg = new Configuration();

	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1.port", "9020-9035");

	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2.port", "9020-9035");

	MetricRegistryImpl reg = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");

	List<MetricReporter> reporters = reg.getReporters();

	assertTrue(reporters.size() == 2);

	MetricReporter rep1 = reporters.get(0);
	MetricReporter rep2 = reporters.get(1);

	Gauge<Integer> g1 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 1;
		}
	};
	Gauge<Integer> g2 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 2;
		}
	};

	rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));
	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));

	MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

	ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
	ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));

	assertEquals(1, mBeanServer.getAttribute(objectName1, "Value"));
	assertEquals(2, mBeanServer.getAttribute(objectName2, "Value"));

	rep1.notifyOfRemovedMetric(g1, "rep1", null);
	rep1.notifyOfRemovedMetric(g2, "rep2", null);

	mg.close();
	reg.shutdown().get();
}
 
Example 6
Source File: JMXReporterTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that we can connect to multiple JMXReporters running on the same machine.
 *
 * @throws Exception
 */
@Test
public void testJMXAvailability() throws Exception {
	Configuration cfg = new Configuration();
	cfg.setString(ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());

	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1.port", "9040-9055");

	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
	cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2.port", "9040-9055");

	MetricRegistryImpl reg = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(cfg));

	TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");

	List<MetricReporter> reporters = reg.getReporters();

	assertTrue(reporters.size() == 2);

	MetricReporter rep1 = reporters.get(0);
	MetricReporter rep2 = reporters.get(1);

	Gauge<Integer> g1 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 1;
		}
	};
	Gauge<Integer> g2 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 2;
		}
	};

	rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));

	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(1, new TaskManagerMetricGroup(reg, "host", "tm")));

	ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
	ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));

	JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep1).getPort() + "/jndi/rmi://localhost:" + ((JMXReporter) rep1).getPort() + "/jmxrmi");
	JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
	MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();

	assertEquals(1, mCon1.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon1.getAttribute(objectName2, "Value"));

	jmxCon1.close();

	JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep2).getPort() + "/jndi/rmi://localhost:" + ((JMXReporter) rep2).getPort() + "/jmxrmi");
	JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
	MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();

	assertEquals(1, mCon2.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon2.getAttribute(objectName2, "Value"));

	rep1.notifyOfRemovedMetric(g1, "rep1", null);
	rep1.notifyOfRemovedMetric(g2, "rep2", null);

	jmxCon2.close();

	rep1.close();
	rep2.close();
	mg.close();
	reg.shutdown().get();
}
 
Example 7
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigurableDelimiterForReportersInGroup() throws Exception {
	MetricConfig config1 = new MetricConfig();
	config1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");

	MetricConfig config2 = new MetricConfig();
	config2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig config3 = new MetricConfig();
	config3.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");

	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B");

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter8()),
			ReporterSetup.forReporter("test2", config2, new TestReporter8()),
			ReporterSetup.forReporter("test3", config3, new TestReporter8()),
			ReporterSetup.forReporter("test4", new TestReporter8())));

	List<MetricReporter> reporters = registry.getReporters();
	((TestReporter8) reporters.get(0)).expectedDelimiter = '_'; //test1  reporter
	((TestReporter8) reporters.get(1)).expectedDelimiter = '-'; //test2 reporter
	((TestReporter8) reporters.get(2)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //test3 reporter, because 'AA' - not correct delimiter
	((TestReporter8) reporters.get(3)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //for test4 reporter use global delimiter

	TaskManagerMetricGroup group = new TaskManagerMetricGroup(registry, "host", "id");
	group.counter("C");
	group.close();
	registry.shutdown().get();
	assertEquals(4, TestReporter8.numCorrectDelimitersForRegister);
	assertEquals(4, TestReporter8.numCorrectDelimitersForUnregister);
}
 
Example 8
Source File: JMXReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that multiple JMXReporters can be started on the same machine and register metrics at the MBeanServer.
 *
 * @throws Exception if the attribute/mbean could not be found or the test is broken
 */
@Test
public void testPortConflictHandling() throws Exception {
	ReporterSetup reporterSetup1 = ReporterSetup.forReporter("test1", new JMXReporter("9020-9035"));
	ReporterSetup reporterSetup2 = ReporterSetup.forReporter("test2", new JMXReporter("9020-9035"));

	MetricRegistryImpl reg = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(reporterSetup1, reporterSetup2));

	TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");

	List<MetricReporter> reporters = reg.getReporters();

	assertTrue(reporters.size() == 2);

	MetricReporter rep1 = reporters.get(0);
	MetricReporter rep2 = reporters.get(1);

	Gauge<Integer> g1 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 1;
		}
	};
	Gauge<Integer> g2 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 2;
		}
	};

	rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));
	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));

	MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

	ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
	ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));

	assertEquals(1, mBeanServer.getAttribute(objectName1, "Value"));
	assertEquals(2, mBeanServer.getAttribute(objectName2, "Value"));

	rep1.notifyOfRemovedMetric(g1, "rep1", null);
	rep1.notifyOfRemovedMetric(g2, "rep2", null);

	mg.close();
	reg.shutdown().get();
}
 
Example 9
Source File: JMXReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that we can connect to multiple JMXReporters running on the same machine.
 *
 * @throws Exception
 */
@Test
public void testJMXAvailability() throws Exception {
	ReporterSetup reporterSetup1 = ReporterSetup.forReporter("test1", new JMXReporter("9040-9055"));
	ReporterSetup reporterSetup2 = ReporterSetup.forReporter("test2", new JMXReporter("9040-9055"));

	MetricRegistryImpl reg = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(reporterSetup1, reporterSetup2));

	TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");

	List<MetricReporter> reporters = reg.getReporters();

	assertTrue(reporters.size() == 2);

	MetricReporter rep1 = reporters.get(0);
	MetricReporter rep2 = reporters.get(1);

	Gauge<Integer> g1 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 1;
		}
	};
	Gauge<Integer> g2 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 2;
		}
	};

	rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));

	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(1, new TaskManagerMetricGroup(reg, "host", "tm")));

	ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
	ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));

	JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep1).getPort().get() + "/jndi/rmi://localhost:" + ((JMXReporter) rep1).getPort().get() + "/jmxrmi");
	JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
	MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();

	assertEquals(1, mCon1.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon1.getAttribute(objectName2, "Value"));

	jmxCon1.close();

	JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep2).getPort().get() + "/jndi/rmi://localhost:" + ((JMXReporter) rep2).getPort().get() + "/jmxrmi");
	JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
	MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();

	assertEquals(1, mCon2.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon2.getAttribute(objectName2, "Value"));

	rep1.notifyOfRemovedMetric(g1, "rep1", null);
	rep1.notifyOfRemovedMetric(g2, "rep2", null);

	jmxCon2.close();

	rep1.close();
	rep2.close();
	mg.close();
	reg.shutdown().get();
}
 
Example 10
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigurableDelimiterForReportersInGroup() throws Exception {
	MetricConfig config1 = new MetricConfig();
	config1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");

	MetricConfig config2 = new MetricConfig();
	config2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig config3 = new MetricConfig();
	config3.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");

	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B");

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test3." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test4." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter8.class.getName());

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter8()),
			ReporterSetup.forReporter("test2", config2, new TestReporter8()),
			ReporterSetup.forReporter("test3", config3, new TestReporter8()),
			ReporterSetup.forReporter("test4", new TestReporter8())));

	List<MetricReporter> reporters = registry.getReporters();
	((TestReporter8) reporters.get(0)).expectedDelimiter = '_'; //test1  reporter
	((TestReporter8) reporters.get(1)).expectedDelimiter = '-'; //test2 reporter
	((TestReporter8) reporters.get(2)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //test3 reporter, because 'AA' - not correct delimiter
	((TestReporter8) reporters.get(3)).expectedDelimiter = GLOBAL_DEFAULT_DELIMITER; //for test4 reporter use global delimiter

	TaskManagerMetricGroup group = new TaskManagerMetricGroup(registry, "host", "id");
	group.counter("C");
	group.close();
	registry.shutdown().get();
	assertEquals(4, TestReporter8.numCorrectDelimitersForRegister);
	assertEquals(4, TestReporter8.numCorrectDelimitersForUnregister);
}
 
Example 11
Source File: JMXReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that multiple JMXReporters can be started on the same machine and register metrics at the MBeanServer.
 *
 * @throws Exception if the attribute/mbean could not be found or the test is broken
 */
@Test
public void testPortConflictHandling() throws Exception {
	ReporterSetup reporterSetup1 = ReporterSetup.forReporter("test1", new JMXReporter("9020-9035"));
	ReporterSetup reporterSetup2 = ReporterSetup.forReporter("test2", new JMXReporter("9020-9035"));

	MetricRegistryImpl reg = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(reporterSetup1, reporterSetup2));

	TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");

	List<MetricReporter> reporters = reg.getReporters();

	assertTrue(reporters.size() == 2);

	MetricReporter rep1 = reporters.get(0);
	MetricReporter rep2 = reporters.get(1);

	Gauge<Integer> g1 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 1;
		}
	};
	Gauge<Integer> g2 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 2;
		}
	};

	rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(createReporterScopedSettings(0), mg));
	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(createReporterScopedSettings(0), mg));

	MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

	ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
	ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));

	assertEquals(1, mBeanServer.getAttribute(objectName1, "Value"));
	assertEquals(2, mBeanServer.getAttribute(objectName2, "Value"));

	rep1.notifyOfRemovedMetric(g1, "rep1", null);
	rep1.notifyOfRemovedMetric(g2, "rep2", null);

	mg.close();
	reg.shutdown().get();
}
 
Example 12
Source File: JMXReporterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that we can connect to multiple JMXReporters running on the same machine.
 *
 * @throws Exception
 */
@Test
public void testJMXAvailability() throws Exception {
	ReporterSetup reporterSetup1 = ReporterSetup.forReporter("test1", new JMXReporter("9040-9055"));
	ReporterSetup reporterSetup2 = ReporterSetup.forReporter("test2", new JMXReporter("9040-9055"));

	MetricRegistryImpl reg = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(reporterSetup1, reporterSetup2));

	TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");

	List<MetricReporter> reporters = reg.getReporters();

	assertTrue(reporters.size() == 2);

	MetricReporter rep1 = reporters.get(0);
	MetricReporter rep2 = reporters.get(1);

	Gauge<Integer> g1 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 1;
		}
	};
	Gauge<Integer> g2 = new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return 2;
		}
	};

	rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(createReporterScopedSettings(0), mg));

	rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(createReporterScopedSettings(1), mg));

	ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
	ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));

	JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep1).getPort().get() + "/jndi/rmi://localhost:" + ((JMXReporter) rep1).getPort().get() + "/jmxrmi");
	JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
	MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();

	assertEquals(1, mCon1.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon1.getAttribute(objectName2, "Value"));

	jmxCon1.close();

	JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep2).getPort().get() + "/jndi/rmi://localhost:" + ((JMXReporter) rep2).getPort().get() + "/jmxrmi");
	JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
	MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();

	assertEquals(1, mCon2.getAttribute(objectName1, "Value"));
	assertEquals(2, mCon2.getAttribute(objectName2, "Value"));

	rep1.notifyOfRemovedMetric(g1, "rep1", null);
	rep1.notifyOfRemovedMetric(g2, "rep2", null);

	jmxCon2.close();

	rep1.close();
	rep2.close();
	mg.close();
	reg.shutdown().get();
}