private void parseProgressSpec(String interval) { String[] parts = interval.split(":"); switch (parts.length) { case 2: intervalMillis = Unit.msFor(parts[1]).orElseThrow( () -> new RuntimeException("Unable to parse progress indicator indicatorSpec '" + parts[1] +"'") ); case 1: try { indicatorMode = IndicatorMode.valueOf(parts[0]); } catch (IllegalArgumentException ie) { throw new RuntimeException( "No such IndicatorMode exists for --progress: choose one of console or logonly." + " If you need to specify an interval such as 10m, then you must use --progress logonly:10m or --progress console:10m"); } break; default: throw new RuntimeException("This should never happen."); } }
/** * 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 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 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); }