Metric2Registry registry = new Metric2Registry(); MetricRegistryListener listener = Mockito.mock(MetricRegistryListener.class); registry.getMetricRegistry().addListener(listener);
/** * Starts the reporter. */ public void start() { registry.addListener(listener); }
/** * Starts the reporter. */ public void start() { registry.addListener(listener); }
/** * Starts the reporter. */ public void start() { registry.addListener(listener); }
/** * Starts the reporter. */ public void start() { registry.addListener(listener); }
public MetricsRegistryMount(MetricRegistry owningRegistry, MetricRegistry mountedRegistry, String mountedPrefix) { this.owningRegistry = owningRegistry; this.mountedRegistry = mountedRegistry; this.mountedPrefix = mountedPrefix; mountedRegistry.addListener(this); }
/** * Adds a {@link MetricRegistryListener} to a collection of listeners that will be notified on * metric creation. Listeners will be notified in the order in which they are added. * <p/> * <b>N.B.:</b> The listener will be notified of all existing metrics when it first registers. * * @param listener the listener that will be notified */ public void addListener(MetricRegistryListener listener) { metrics.addListener(listener); }
/** * Starts the reporter. */ public void start() { registry.addListener(listener); }
@Override public void addListener(MetricRegistryListener listener) { this.metricRegistry.addListener(listener); }
public MetricRegistryBindings(MetricRegistry registry) { this.registry = registry; registry.addListener(this); }
@Override public void addListener(MetricRegistryListener listener) { this.metricRegistry.addListener(listener); }
public static MetricRegistry adaptingMetricRegistry( SemanticMetricRegistry target, SemanticMetricIdAdapter metricIdBuilder ) { MetricRegistry metricRegistry = new MetricRegistry(); metricRegistry.addListener(new SemanticMetricRegistryAdapter(target, metricIdBuilder)); return metricRegistry; }
public static MetricRegistry adaptingMetricRegistry( SemanticMetricRegistry target, SemanticMetricIdAdapter metricIdBuilder ) { MetricRegistry metricRegistry = new MetricRegistry(); metricRegistry.addListener(new SemanticMetricRegistryAdapter(target, metricIdBuilder)); return metricRegistry; }
@Inject public ScheduledReporterCollector(AppProperties appProperties, ReporterProperties reporterProperties, MetricRegistry metricRegistry, Map<String, ScheduledReporter> allReporters) throws Exception { LOGGER.debug("Configuring metrics"); Integer period = appProperties.reportInterval; this.reportIntervalInSeconds = period > 0 ? period : DEFAULT_REPORT_INTERVAL_IN_SECONDS; reporters = selectReporters(reporterProperties, allReporters); //This is the singleton metric registry shared across the board this.metricRegistry = metricRegistry; // Install the logging listener (probably a configuration item) this.metricRegistry.addListener(new LoggingMetricListener()); LOGGER.info("Reporters have been configured"); }
/** * Add a histogram stats logger to matching metrics in this JVM instance. * @param sessionName The name for the session to be annotated in the histogram log * @param pattern A regular expression pattern to filter out metric names for logging * @param filename A file to log the histogram data in * @param interval How many seconds to wait between writing each interval histogram */ public static void addStatsLogger(String sessionName, String pattern, String filename, String interval) { if (filename.contains("_SESSION_")) { filename = filename.replace("_SESSION_",sessionName); } Pattern compiledPattern = Pattern.compile(pattern); File logfile = new File(filename); long intervalMillis = Unit.msFor(interval).orElseThrow(() -> new RuntimeException("Unable to parse interval spec:" + interval + "'")); HistoStatsLogger histoStatsLogger = new HistoStatsLogger(sessionName, logfile, compiledPattern, intervalMillis, TimeUnit.NANOSECONDS); logger.debug("attaching " + histoStatsLogger + " to the metrics registry."); get().addListener(histoStatsLogger); metricsCloseables.add(histoStatsLogger); }
/** * Add a histogram interval logger to matching metrics in this JVM instance. * @param sessionName The name for the session to be annotated in the histogram log * @param pattern A regular expression pattern to filter out metric names for logging * @param filename A file to log the histogram data in * @param interval How many seconds to wait between writing each interval histogram */ public static void addHistoLogger(String sessionName, String pattern, String filename, String interval) { if (filename.contains("_SESSION_")) { filename = filename.replace("_SESSION_",sessionName); } Pattern compiledPattern = Pattern.compile(pattern); File logfile = new File(filename); long intervalMillis = Unit.msFor(interval).orElseThrow(()->new RuntimeException("Unable to parse interval spec:'" + interval + "'")); HistoIntervalLogger histoIntervalLogger = new HistoIntervalLogger(sessionName, logfile, compiledPattern, intervalMillis); logger.debug("attaching " + histoIntervalLogger + " to the metrics registry."); get().addListener(histoIntervalLogger); metricsCloseables.add(histoIntervalLogger); }
/** * Add a classic histogram in addition to the default implementation in this runtime. This is a way to * get a view to both the enhanced histogram implementation as well as the classic implementation in the * same scenario. * @param sessionName The name of the session to be annotated in the classic histogram * @param pattern A regular expression pattern to filter out metric names for inclusion * @param prefix The name prefix to add to the classic histograms so that they fit into the existing metrics namespace * @param interval How frequently to update the histogram */ public static void addClassicHistos(String sessionName, String pattern, String prefix, String interval) { Pattern compiledPattern = Pattern.compile(pattern); long intervalMillis = Unit.msFor(interval).orElseThrow(() -> new RuntimeException("Unable to parse interval spec:" + interval + "'")); ClassicHistoListener classicHistoListener = new ClassicHistoListener(get(),sessionName, prefix, compiledPattern, interval, TimeUnit.NANOSECONDS); logger.debug("attaching histo listener " + classicHistoListener + " to the metrics registry."); get().addListener(classicHistoListener); ClassicTimerListener classicTimerListener = new ClassicTimerListener(get(),sessionName, prefix, compiledPattern, interval, TimeUnit.NANOSECONDS); logger.debug("attaching timer listener " + classicTimerListener + " to the metrics registry."); get().addListener(classicTimerListener); }
@Override public void configureAndStartReportFor(MetricRegistry registry) { final MetricRegistryListener defaultListener = wrapListenerAndFilter(); registry.addListener( defaultListener ); final DefaultScheduledReporter reporter = new DefaultScheduledReporter( registry, configuration.metricStore(), healthCheck, configuration.metricFilter(), MILLISECONDS, MILLISECONDS ); reporter.start( configuration.reportInterval(), MILLISECONDS ); }
@Override public void configureReporters(MetricRegistry metricRegistry) { metricRegistry.addListener(metricsListener);
@Test public void testDoesntCrash() { MetricsFactory factory = MetricsFactory.getInstance(); factory.getRegistry().addListener(new LoggingMetricListener()); assertNotNull(factory.getCounter(LoggingMetricListenerTest.class, "a")); assertNotNull(factory.getHistogram(LoggingMetricListenerTest.class, "b")); assertNotNull(factory.getMeter(LoggingMetricListenerTest.class, "c")); assertNotNull(factory.getTimer(LoggingMetricListenerTest.class, "d")); factory.removeAll(); }