@Override public void afterJob(JobExecution jobExecution) { long jobDuration = jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime(); gaugeService.submit(TIMER_PREFIX + jobExecution.getJobInstance().getJobName() + ".duration", jobDuration); // What the f*** is that Thread.sleep doing here? ;-) // Metrics are written asynchronously to Spring Boot's repository. In our tests we experienced // that sometimes batch execution was so fast that this listener couldn't export the metrics // because they hadn't been written. It all happened in the same millisecond. So we added // a Thread.sleep of 100 milliseconds which gives us enough safety and doesn't hurt anyone. try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } // Export Metrics to Console or Remote Systems LOGGER.info(metricsOutputFormatter.format(exportBatchRichGauges(), exportBatchMetrics())); // Codahale if (exporters != null) { for (Exporter exporter : exporters) { if (exporter != null) { LOGGER.info("Exporting Metrics with " + exporter.getClass().getName()); exporter.export(); } } } }
public MetricExportAutoConfiguration(MetricExportProperties properties, ObjectProvider<MetricsEndpointMetricReader> endpointReaderProvider, @ExportMetricReader ObjectProvider<List<MetricReader>> readersProvider, @ExportMetricWriter ObjectProvider<Map<String, GaugeWriter>> writersProvider, ObjectProvider<Map<String, Exporter>> exportersProvider) { this.properties = properties; this.endpointReader = endpointReaderProvider.getIfAvailable(); this.readers = readersProvider.getIfAvailable(); this.writers = writersProvider.getIfAvailable(); this.exporters = exportersProvider.getIfAvailable(); }
public MetricsListener(GaugeService gaugeService, RichGaugeReader richGaugeReader, MetricReader metricReader, List<Exporter> exporters) { this.gaugeService = gaugeService; this.richGaugeReader = richGaugeReader; this.metricReader = metricReader; this.exporters = exporters; }
@Bean @ConditionalOnMissingBean(Exporter.class) public AtlasExporter exporter(AtlasMetricObserver observer, MetricPoller poller, AtlasProperties properties) { return new AtlasExporter(observer, poller, properties.getPublishDelay()); }
@Bean Exporter exporter() { return Mockito.mock(Exporter.class); }