@Bean @ConditionalOnMissingBean public MetricsEndpoint metricsEndpoint() { List<PublicMetrics> publicMetrics = new ArrayList<PublicMetrics>(); if (this.publicMetrics != null) { publicMetrics.addAll(this.publicMetrics); } Collections.sort(publicMetrics, AnnotationAwareOrderComparator.INSTANCE); return new MetricsEndpoint(publicMetrics); }
@Test public void endpoints() throws Exception { load(EndpointAutoConfiguration.class); assertThat(this.context.getBean(BeansEndpoint.class)).isNotNull(); assertThat(this.context.getBean(DumpEndpoint.class)).isNotNull(); assertThat(this.context.getBean(EnvironmentEndpoint.class)).isNotNull(); assertThat(this.context.getBean(HealthEndpoint.class)).isNotNull(); assertThat(this.context.getBean(InfoEndpoint.class)).isNotNull(); assertThat(this.context.getBean(MetricsEndpoint.class)).isNotNull(); assertThat(this.context.getBean(ShutdownEndpoint.class)).isNotNull(); assertThat(this.context.getBean(TraceEndpoint.class)).isNotNull(); assertThat(this.context.getBean(RequestMappingEndpoint.class)).isNotNull(); }
@Test public void metricEndpointsHasSystemMetricsByDefault() { load(PublicMetricsAutoConfiguration.class, EndpointAutoConfiguration.class); MetricsEndpoint endpoint = this.context.getBean(MetricsEndpoint.class); Map<String, Object> metrics = endpoint.invoke(); assertThat(metrics.containsKey("mem")).isTrue(); assertThat(metrics.containsKey("heap.used")).isTrue(); }
@Test public void metricEndpointCustomPublicMetrics() { load(CustomPublicMetricsConfig.class, PublicMetricsAutoConfiguration.class, EndpointAutoConfiguration.class); MetricsEndpoint endpoint = this.context.getBean(MetricsEndpoint.class); Map<String, Object> metrics = endpoint.invoke(); // Custom metrics assertThat(metrics.containsKey("foo")).isTrue(); // System metrics still available assertThat(metrics.containsKey("mem")).isTrue(); assertThat(metrics.containsKey("heap.used")).isTrue(); }
@Test public void endpoints() throws Exception { load(EndpointAutoConfiguration.class); assertNotNull(this.context.getBean(BeansEndpoint.class)); assertNotNull(this.context.getBean(DumpEndpoint.class)); assertNotNull(this.context.getBean(EnvironmentEndpoint.class)); assertNotNull(this.context.getBean(HealthEndpoint.class)); assertNotNull(this.context.getBean(InfoEndpoint.class)); assertNotNull(this.context.getBean(MetricsEndpoint.class)); assertNotNull(this.context.getBean(ShutdownEndpoint.class)); assertNotNull(this.context.getBean(TraceEndpoint.class)); assertNotNull(this.context.getBean(RequestMappingEndpoint.class)); }
@Test public void metricEndpointsHasSystemMetricsByDefault() { load(PublicMetricsAutoConfiguration.class, EndpointAutoConfiguration.class); MetricsEndpoint endpoint = this.context.getBean(MetricsEndpoint.class); Map<String, Object> metrics = endpoint.invoke(); assertTrue(metrics.containsKey("mem")); assertTrue(metrics.containsKey("heap.used")); }
@Test public void metricEndpointCustomPublicMetrics() { load(CustomPublicMetricsConfig.class, PublicMetricsAutoConfiguration.class, EndpointAutoConfiguration.class); MetricsEndpoint endpoint = this.context.getBean(MetricsEndpoint.class); Map<String, Object> metrics = endpoint.invoke(); // Custom metrics assertTrue(metrics.containsKey("foo")); // System metrics still available assertTrue(metrics.containsKey("mem")); assertTrue(metrics.containsKey("heap.used")); }
/** * Enable a metrics reader. * @param metricsEndpoint {@link MetricsEndpoint} * @return {@link MetricsEndpointMetricReader} */ @Bean @ConditionalOnProperty(value = "statful.client.springboot.metrics.enabled", havingValue = "true") public MetricsEndpointMetricReader metricsEndpointMetricReader(final MetricsEndpoint metricsEndpoint) { return new MetricsEndpointMetricReader(metricsEndpoint); }
@Bean @ConditionalOnBean(MetricsEndpoint.class) @ConditionalOnEnabledEndpoint("metrics") public MetricsMvcEndpoint metricsMvcEndpoint(MetricsEndpoint delegate) { return new MetricsMvcEndpoint(delegate); }
public MetricsMvcEndpoint(MetricsEndpoint delegate) { super(delegate); this.delegate = delegate; }
@Before public void setUp() { this.context.getBean(MetricsEndpoint.class).setEnabled(true); this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); }
@Test public void homeWhenDisabled() throws Exception { this.context.getBean(MetricsEndpoint.class).setEnabled(false); this.mvc.perform(get("/metrics")).andExpect(status().isNotFound()); }
@Test public void specificMetricWhenDisabled() throws Exception { this.context.getBean(MetricsEndpoint.class).setEnabled(false); this.mvc.perform(get("/metrics/foo")).andExpect(status().isNotFound()); }
public ApplicationMetricsExporter(MetricsEndpoint endpoint, MessageChannel source, ApplicationMetricsProperties properties) { this.source = source; this.properties = properties; this.metricsReader = new MetricsEndpointMetricReader(endpoint); }