Search in sources :

Example 1 with GaugeService

use of org.springframework.boot.actuate.metrics.GaugeService in project spring-boot by spring-projects.

the class MetricRepositoryAutoConfigurationTests method dropwizardInstalledIfPresent.

@Test
public void dropwizardInstalledIfPresent() {
    this.context = new AnnotationConfigApplicationContext(MetricsDropwizardAutoConfiguration.class, MetricRepositoryAutoConfiguration.class, AopAutoConfiguration.class);
    GaugeService gaugeService = this.context.getBean(GaugeService.class);
    assertThat(gaugeService).isNotNull();
    gaugeService.submit("foo", 2.7);
    DropwizardMetricServices exporter = this.context.getBean(DropwizardMetricServices.class);
    assertThat(exporter).isEqualTo(gaugeService);
    MetricRegistry registry = this.context.getBean(MetricRegistry.class);
    @SuppressWarnings("unchecked") Gauge<Double> gauge = (Gauge<Double>) registry.getMetrics().get("gauge.foo");
    assertThat(gauge.getValue()).isEqualTo(new Double(2.7));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) BufferGaugeService(org.springframework.boot.actuate.metrics.buffer.BufferGaugeService) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) MetricRegistry(com.codahale.metrics.MetricRegistry) AopAutoConfiguration(org.springframework.boot.autoconfigure.aop.AopAutoConfiguration) DropwizardMetricServices(org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices) Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Example 2 with GaugeService

use of org.springframework.boot.actuate.metrics.GaugeService in project spring-boot by spring-projects.

the class MetricExportAutoConfigurationTests method provideAdditionalWriter.

@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(any(Metric.class));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MetricCopyExporter(org.springframework.boot.actuate.metrics.export.MetricCopyExporter) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) StatsdMetricWriter(org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter) MetricWriter(org.springframework.boot.actuate.metrics.writer.MetricWriter) Metric(org.springframework.boot.actuate.metrics.Metric) MetricExporters(org.springframework.boot.actuate.metrics.export.MetricExporters) Test(org.junit.Test)

Example 3 with GaugeService

use of org.springframework.boot.actuate.metrics.GaugeService in project spring-boot by spring-projects.

the class MetricExportAutoConfigurationTests method metricsFlushAutomatically.

@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);
    // this will be called by Spring on shutdown
    flusher.close();
    MetricWriter writer = this.context.getBean("writer", MetricWriter.class);
    verify(writer, atLeastOnce()).set(any(Metric.class));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) StatsdMetricWriter(org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter) MetricWriter(org.springframework.boot.actuate.metrics.writer.MetricWriter) Metric(org.springframework.boot.actuate.metrics.Metric) MetricExporters(org.springframework.boot.actuate.metrics.export.MetricExporters) Test(org.junit.Test)

Example 4 with GaugeService

use of org.springframework.boot.actuate.metrics.GaugeService in project spring-boot by spring-projects.

the class MetricFilterAutoConfigurationTests method gaugeServiceThatThrows.

@Test
public void gaugeServiceThatThrows() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
    GaugeService gaugeService = context.getBean(GaugeService.class);
    willThrow(new IllegalStateException()).given(gaugeService).submit(anyString(), anyDouble());
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
    verify(context.getBean(CounterService.class)).increment("status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class)).submit(eq("response.templateVarTest.someVariable"), anyDouble());
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) Filter(javax.servlet.Filter) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 5 with GaugeService

use of org.springframework.boot.actuate.metrics.GaugeService in project spring-boot by spring-projects.

the class MetricRepositoryAutoConfigurationTests method createServices.

@Test
public void createServices() throws Exception {
    this.context = new AnnotationConfigApplicationContext(MetricRepositoryAutoConfiguration.class);
    GaugeService gaugeService = this.context.getBean(BufferGaugeService.class);
    assertThat(gaugeService).isNotNull();
    assertThat(this.context.getBean(BufferCounterService.class)).isNotNull();
    assertThat(this.context.getBean(PrefixMetricReader.class)).isNotNull();
    gaugeService.submit("foo", 2.7);
    MetricReader bean = this.context.getBean(MetricReader.class);
    assertThat(bean.findOne("gauge.foo").getValue()).isEqualTo(2.7);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) BufferGaugeService(org.springframework.boot.actuate.metrics.buffer.BufferGaugeService) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) MetricReader(org.springframework.boot.actuate.metrics.reader.MetricReader) PrefixMetricReader(org.springframework.boot.actuate.metrics.reader.PrefixMetricReader) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 GaugeService (org.springframework.boot.actuate.metrics.GaugeService)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 Metric (org.springframework.boot.actuate.metrics.Metric)2 BufferGaugeService (org.springframework.boot.actuate.metrics.buffer.BufferGaugeService)2 MetricExporters (org.springframework.boot.actuate.metrics.export.MetricExporters)2 StatsdMetricWriter (org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter)2 MetricWriter (org.springframework.boot.actuate.metrics.writer.MetricWriter)2 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)2 Gauge (com.codahale.metrics.Gauge)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Filter (javax.servlet.Filter)1 DropwizardMetricServices (org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices)1 MetricCopyExporter (org.springframework.boot.actuate.metrics.export.MetricCopyExporter)1 MetricReader (org.springframework.boot.actuate.metrics.reader.MetricReader)1 PrefixMetricReader (org.springframework.boot.actuate.metrics.reader.PrefixMetricReader)1 AopAutoConfiguration (org.springframework.boot.autoconfigure.aop.AopAutoConfiguration)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)1