Search in sources :

Example 1 with RichGauge

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

the class PublicMetricsAutoConfigurationTests method richGaugePublicMetrics.

@Test
public void richGaugePublicMetrics() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, PublicMetricsAutoConfiguration.class);
    RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class);
    assertThat(richGaugeReader).isNotNull();
    given(richGaugeReader.findAll()).willReturn(Collections.singletonList(new RichGauge("bar", 3.7d)));
    RichGaugeReaderPublicMetrics publicMetrics = context.getBean(RichGaugeReaderPublicMetrics.class);
    assertThat(publicMetrics).isNotNull();
    Collection<Metric<?>> metrics = publicMetrics.metrics();
    assertThat(metrics).isNotNull();
    assertThat(6).isEqualTo(metrics.size());
    assertHasMetric(metrics, new Metric<>("bar.val", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.avg", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.min", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.max", 3.7d));
    assertHasMetric(metrics, new Metric<>("bar.alpha", -1.d));
    assertHasMetric(metrics, new Metric<>("bar.count", 1L));
    context.close();
}
Also used : RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RichGauge(org.springframework.boot.actuate.metrics.rich.RichGauge) RichGaugeReader(org.springframework.boot.actuate.metrics.rich.RichGaugeReader) Metric(org.springframework.boot.actuate.metrics.Metric) Test(org.junit.Test)

Example 2 with RichGauge

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

the class RichGaugeExporter method next.

@Override
protected Iterable<Metric<?>> next(String group) {
    RichGauge rich = this.reader.findOne(group);
    Collection<Metric<?>> metrics = new ArrayList<>();
    metrics.add(new Metric<Number>(group + MIN, rich.getMin()));
    metrics.add(new Metric<Number>(group + MAX, rich.getMax()));
    metrics.add(new Metric<Number>(group + COUNT, rich.getCount()));
    metrics.add(new Metric<Number>(group + VALUE, rich.getValue()));
    metrics.add(new Metric<Number>(group + AVG, rich.getAverage()));
    metrics.add(new Metric<Number>(group + ALPHA, rich.getAlpha()));
    return metrics;
}
Also used : RichGauge(org.springframework.boot.actuate.metrics.rich.RichGauge) ArrayList(java.util.ArrayList) Metric(org.springframework.boot.actuate.metrics.Metric)

Aggregations

Metric (org.springframework.boot.actuate.metrics.Metric)2 RichGauge (org.springframework.boot.actuate.metrics.rich.RichGauge)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 RichGaugeReaderPublicMetrics (org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics)1 RichGaugeReader (org.springframework.boot.actuate.metrics.rich.RichGaugeReader)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1