private void flush(GaugeWriter writer) { if (writer instanceof CompositeMetricWriter) { for (MetricWriter child : (CompositeMetricWriter) writer) { flush(child); } } try { if (ClassUtils.isPresent("java.io.Flushable", null)) { if (writer instanceof Flushable) { ((Flushable) writer).flush(); return; } } Method method = ReflectionUtils.findMethod(writer.getClass(), "flush"); if (method != null) { ReflectionUtils.invokeMethod(method, writer); } } catch (Exception ex) { logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": " + ex.getMessage()); } }
@Test public void provideAdditionalWriter() { this.context = new AnnotationConfigApplicationContext(WriterConfig.class, MetricRepositoryAutoConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(GaugeService.class); assertThat(gaugeService).isNotNull(); gaugeService.submit("foo", 2.7); MetricExporters exporters = this.context.getBean(MetricExporters.class); MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters() .get("writer"); exporter.setIgnoreTimestamps(true); exporter.export(); MetricWriter writer = this.context.getBean("writer", MetricWriter.class); Mockito.verify(writer, Mockito.atLeastOnce()).set(Matchers.any(Metric.class)); }
private void flush(MetricWriter writer) { if (writer instanceof CompositeMetricWriter) { for (MetricWriter child : (CompositeMetricWriter) writer) { flush(child); } } try { if (ClassUtils.isPresent("java.io.Flushable", null)) { if (writer instanceof Flushable) { ((Flushable) writer).flush(); return; } } Method method = ReflectionUtils.findMethod(writer.getClass(), "flush"); if (method != null) { ReflectionUtils.invokeMethod(method, writer); } } catch (Exception ex) { logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": " + ex.getMessage()); } }
@Test public void provideAdditionalWriter() { this.context = new AnnotationConfigApplicationContext(WriterConfig.class, MetricRepositoryAutoConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(GaugeService.class); assertNotNull(gaugeService); gaugeService.submit("foo", 2.7); MetricExporters exporters = this.context.getBean(MetricExporters.class); MetricCopyExporter exporter = (MetricCopyExporter) exporters.getExporters() .get("writer"); exporter.setIgnoreTimestamps(true); exporter.export(); MetricWriter writer = this.context.getBean("writer", MetricWriter.class); Mockito.verify(writer, Mockito.atLeastOnce()).set(Matchers.any(Metric.class)); }
@Test public void metricsFlushAutomatically() throws Exception { this.context = new AnnotationConfigApplicationContext(WriterConfig.class, MetricRepositoryAutoConfiguration.class, MetricExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(GaugeService.class); assertThat(gaugeService).isNotNull(); gaugeService.submit("foo", 2.7); MetricExporters flusher = this.context.getBean(MetricExporters.class); flusher.close(); // this will be called by Spring on shutdown MetricWriter writer = this.context.getBean("writer", MetricWriter.class); Mockito.verify(writer, Mockito.atLeastOnce()).set(Matchers.any(Metric.class)); }
private MetricCopyExporter getExporter(MetricWriter writer, TriggerProperties trigger) { MetricCopyExporter exporter = new MetricCopyExporter(this.reader, writer); exporter.setIncludes(trigger.getIncludes()); exporter.setExcludes(trigger.getExcludes()); exporter.setSendLatest(trigger.isSendLatest()); return exporter; }
@Bean @ConfigurationProperties("metrics.export") @ExportMetricWriter public MetricWriter openTsdbMetricWriter() { OpenTsdbMetricWriter writer = new OpenTsdbMetricWriter(); writer.setNamingStrategy(namingStrategy()); return writer; }
@Bean @Primary @ConditionalOnMissingClass("org.springframework.messaging.MessageChannel") @ConditionalOnMissingBean(name = "primaryMetricWriter") public MetricWriter primaryMetricWriter(List<MetricWriter> writers) { return new CompositeMetricWriter(writers); }
@Bean(name = "primaryMetricWriter") @Primary static public MetricWriter primaryMetricWriter(List<MetricWriter> writers) { // Normally the Metrics are written asynchronously to Spring Boot's repository. In tests we need to do it synchronously to be able to verify // the correct output. MetricWriter compositeMetricWriter = new CompositeMetricWriter(writers); return compositeMetricWriter; }
@Bean @ExportMetricWriter /* * Prometheus is not capable to scrape json metrics so we need to expose the actuator metrics to jmx. Every * counter and gauge metrics are exposed too. */ public MetricWriter metricWriter(MBeanExporter exporter) { return new JmxMetricWriter(exporter); }
@Bean @ConditionalOnProperty("jhipster.logging.spectator-metrics.enabled") @ExportMetricWriter MetricWriter metricWriter() { return new SpectatorLogMetricWriter(); }
/** * Exports actuator metrics to JMX. */ @Bean @ExportMetricWriter public MetricWriter metricWriter(MBeanExporter exporter) { return new JmxMetricWriter(exporter); }
/** * Export a new {@link StatfulMetricWriter} metrics writer. * @return {@link MetricWriter} */ @Bean @ExportMetricWriter MetricWriter metricWriter() { return new StatfulMetricWriter(); }
@Bean @ExportMetricWriter public MetricWriter metricWriter(MetricExportProperties export) { return new RedisMetricRepository(redisConnectionFactory, export.getRedis().getPrefix(), export.getRedis().getKey()); }
LegacyMetricServicesConfiguration(@ActuatorMetricWriter MetricWriter writer) { this.writer = writer; }
@Bean @ExportMetricWriter public MetricWriter writer() { return Mockito.mock(MetricWriter.class); }