Search in sources :

Example 1 with MetricsReporter

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();
}
Also used : MetricsReporter(org.apache.knox.gateway.services.metrics.MetricsReporter) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) Test(org.junit.Test)

Example 2 with MetricsReporter

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);
        }
    }
}
Also used : MetricsReporter(org.apache.knox.gateway.services.metrics.MetricsReporter) MetricsReporterException(org.apache.knox.gateway.services.metrics.MetricsReporterException)

Aggregations

MetricsReporter (org.apache.knox.gateway.services.metrics.MetricsReporter)2 GatewayConfigImpl (org.apache.knox.gateway.config.impl.GatewayConfigImpl)1 MetricsReporterException (org.apache.knox.gateway.services.metrics.MetricsReporterException)1 Test (org.junit.Test)1