use of org.apache.knox.gateway.services.metrics.MetricsReporter in project knox by apache.
the class DefaultMetricsServiceTest method reportersLoading.
@Test
public void reportersLoading() throws Exception {
DefaultMetricsService service = new DefaultMetricsService();
GatewayConfigImpl config = new GatewayConfigImpl();
config.set(GatewayConfigImpl.METRICS_ENABLED, "true");
config.set(GatewayConfigImpl.JMX_METRICS_REPORTING_ENABLED, "false");
service.init(config, null);
List<MetricsReporter> reporters = service.getMetricsReporters();
Assert.assertTrue(reporters.size() >= 2);
for (MetricsReporter reporter : reporters) {
Assert.assertFalse(reporter.isEnabled());
}
config.set(GatewayConfigImpl.JMX_METRICS_REPORTING_ENABLED, "true");
config.set(GatewayConfigImpl.GRAPHITE_METRICS_REPORTING_ENABLED, "true");
service.init(config, null);
reporters = service.getMetricsReporters();
for (MetricsReporter reporter : reporters) {
Assert.assertTrue(reporter.isEnabled());
}
service.start();
service.stop();
}
use of org.apache.knox.gateway.services.metrics.MetricsReporter in project knox by apache.
the class DefaultMetricsService method loadAndInitReporters.
private void loadAndInitReporters(GatewayConfig config) {
ServiceLoader<MetricsReporter> reporters = ServiceLoader.load(MetricsReporter.class);
Iterator<MetricsReporter> reportersIterator = reporters.iterator();
while (reportersIterator.hasNext()) {
MetricsReporter metricsReporter = reportersIterator.next();
try {
metricsReporter.init(config);
metricsReporters.add(metricsReporter);
} catch (MetricsReporterException e) {
LOG.failedToInitializeReporter(metricsReporter.getName(), e);
}
}
}
Aggregations