/** * Create a new console reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createConsoleReporter( MetricRegistry metricRegistry, Map<String, Object> config) { return ConsoleReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .build(); }
switch (type.toLowerCase()) { case "log": reporter = ReporterUtils.createSlf4jReporter(metricRegistry, config); break; case "csv": reporter = ReporterUtils.createCsvReporter(metricRegistry, config); break; case "console": reporter = ReporterUtils.createConsoleReporter(metricRegistry, config); break; case "elasticsearch": reporter = ReporterUtils.createElasticSearchReporter(metricRegistry, config); break; case "none":
@Test public void testCreateCsvReporterBadLocation() throws BaleenException { Map<String, Object> config = new HashMap<>(); config.put("directory", "ABC:\\null\u0000\\test"); try { ReporterUtils.createCsvReporter(registry, config); fail("Expected exception not thrown"); } catch (BaleenException be) { // Expected exception } }
@Test public void testCreateElasticSearchReporter() throws BaleenException { // NOTE: At the time of writing, although this supposedly throws an IO // exception it doesn't even it the server doesn't exist! ScheduledReporter reporter = ReporterUtils.createElasticSearchReporter(registry, new HashMap<String, Object>()); assertNotNull(reporter); } }
@Test public void testCreatetConsoleReporter() { ScheduledReporter reporter = ReporterUtils.createConsoleReporter(registry, new HashMap<String, Object>()); assertNotNull(reporter); }
@Test public void testCreateSlf4jReporter() { ScheduledReporter reporter = ReporterUtils.createSlf4jReporter(registry, new HashMap<String, Object>()); assertNotNull(reporter); }
switch (type.toLowerCase()) { case "log": reporter = ReporterUtils.createSlf4jReporter(metricRegistry, config); break; case "csv": reporter = ReporterUtils.createCsvReporter(metricRegistry, config); break; case "console": reporter = ReporterUtils.createConsoleReporter(metricRegistry, config); break; case "elasticsearch": reporter = ReporterUtils.createElasticSearchReporter(metricRegistry, config); break; case "none":
@Test public void testCreateCsvReporter() throws BaleenException { ScheduledReporter reporter = ReporterUtils.createCsvReporter(registry, new HashMap<String, Object>()); assertNotNull(reporter); }
/** * Create a new console reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createConsoleReporter( MetricRegistry metricRegistry, Map<String, Object> config) { return ConsoleReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .build(); }
/** * Create a new CSV reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createCsvReporter( MetricRegistry metricRegistry, Map<String, Object> config) throws BaleenException { String directoryPath = (String) config.getOrDefault("directory", "metrics"); File directory = new File(directoryPath); if (!directory.exists() && !directory.mkdirs()) { throw new BaleenException("Unable to create directories for CSV Reporter"); } return CsvReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .build(directory); }
/** * Create a new CSV reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createCsvReporter( MetricRegistry metricRegistry, Map<String, Object> config) throws BaleenException { String directoryPath = (String) config.getOrDefault("directory", "metrics"); File directory = new File(directoryPath); if (!directory.exists() && !directory.mkdirs()) { throw new BaleenException("Unable to create directories for CSV Reporter"); } return CsvReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .build(directory); }
/** * Create a new CSV reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createSlf4jReporter( MetricRegistry metricRegistry, Map<String, Object> config) { String loggerName = (String) config.getOrDefault("logger", "metrics:reporter"); return Slf4jReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .outputTo(LoggerFactory.getLogger(loggerName)) .build(); }
/** * Create a new CSV reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createSlf4jReporter( MetricRegistry metricRegistry, Map<String, Object> config) { String loggerName = (String) config.getOrDefault("logger", "metrics:reporter"); return Slf4jReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .outputTo(LoggerFactory.getLogger(loggerName)) .build(); }
/** * Create a new ElasticSearch reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createElasticSearchReporter( MetricRegistry metricRegistry, Map<String, Object> config) throws BaleenException { try { String server = (String) config.getOrDefault("server", "localhost:9200"); String index = (String) config.getOrDefault("index", "metrics"); int timeout = (int) config.getOrDefault("timeout", 1000); int bulkSize = (int) config.getOrDefault("bulkSize", 2500); return ElasticsearchReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .bulkSize(bulkSize) .hosts(server) .index(index) .timeout(timeout) .build(); } catch (IOException e) { throw new BaleenException("Unable to create ElasticSearch reporter", e); } }
/** * Create a new ElasticSearch reporter. * * @param metricRegistry the registry to report on * @param config the configuration map (see {@link MetricsFactory}) * @return the reporter instance */ public static ScheduledReporter createElasticSearchReporter( MetricRegistry metricRegistry, Map<String, Object> config) throws BaleenException { try { String server = (String) config.getOrDefault("server", "localhost:9200"); String index = (String) config.getOrDefault("index", "metrics"); int timeout = (int) config.getOrDefault("timeout", 1000); int bulkSize = (int) config.getOrDefault("bulkSize", 2500); return ElasticsearchReporter.forRegistry(metricRegistry) .convertRatesTo(getRatesUnit(config)) .convertDurationsTo(getDurationUnit(config)) .bulkSize(bulkSize) .hosts(server) .index(index) .timeout(timeout) .build(); } catch (IOException e) { throw new BaleenException("Unable to create ElasticSearch reporter", e); } }