Search in sources :

Example 16 with Metric

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

the class PublicMetricsAutoConfigurationTests method autoDataSource.

@Test
public void autoDataSource() {
    load(DataSourceAutoConfiguration.class);
    PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
    Collection<Metric<?>> metrics = bean.metrics();
    assertMetrics(metrics, "datasource.primary.active", "datasource.primary.usage");
}
Also used : Metric(org.springframework.boot.actuate.metrics.Metric) RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) MetricReaderPublicMetrics(org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics) CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) DataSourcePublicMetrics(org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics) TomcatPublicMetrics(org.springframework.boot.actuate.endpoint.TomcatPublicMetrics) PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) SystemPublicMetrics(org.springframework.boot.actuate.endpoint.SystemPublicMetrics) Test(org.junit.Test)

Example 17 with Metric

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

the class PublicMetricsAutoConfigurationTests method customPrefix.

@Test
public void customPrefix() {
    load(MultipleDataSourcesWithPrimaryConfig.class, CustomDataSourcePublicMetrics.class);
    PublicMetrics bean = this.context.getBean(DataSourcePublicMetrics.class);
    Collection<Metric<?>> metrics = bean.metrics();
    assertMetrics(metrics, "ds.first.active", "ds.first.usage", "ds.second.active", "ds.second.usage");
}
Also used : Metric(org.springframework.boot.actuate.metrics.Metric) RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) MetricReaderPublicMetrics(org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics) CachePublicMetrics(org.springframework.boot.actuate.endpoint.CachePublicMetrics) DataSourcePublicMetrics(org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics) TomcatPublicMetrics(org.springframework.boot.actuate.endpoint.TomcatPublicMetrics) PublicMetrics(org.springframework.boot.actuate.endpoint.PublicMetrics) SystemPublicMetrics(org.springframework.boot.actuate.endpoint.SystemPublicMetrics) Test(org.junit.Test)

Example 18 with Metric

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

the class DefaultCounterServiceSpeedTests method counters.

@Theory
public void counters(String input) throws Exception {
    watch.start("counters" + count++);
    ExecutorService pool = Executors.newFixedThreadPool(threadCount);
    Runnable task = new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < number; i++) {
                String name = sample[i % sample.length];
                DefaultCounterServiceSpeedTests.this.counterService.increment(name);
            }
        }
    };
    Collection<Future<?>> futures = new HashSet<>();
    for (int i = 0; i < threadCount; i++) {
        futures.add(pool.submit(task));
    }
    for (Future<?> future : futures) {
        future.get();
    }
    watch.stop();
    double rate = number / watch.getLastTaskTimeMillis() * 1000;
    System.err.println("Counters rate(" + count + ")=" + rate + ", " + watch);
    watch.start("read" + count);
    this.reader.findAll().forEach(new Consumer<Metric<?>>() {

        @Override
        public void accept(Metric<?> metric) {
            err.println(metric);
        }
    });
    final LongAdder total = new LongAdder();
    this.reader.findAll().forEach(new Consumer<Metric<?>>() {

        @Override
        public void accept(Metric<?> value) {
            total.add(value.getValue().intValue());
        }
    });
    watch.stop();
    System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
    assertThat(total.longValue()).isEqualTo(number * threadCount);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Metric(org.springframework.boot.actuate.metrics.Metric) HashSet(java.util.HashSet) Theory(org.junit.experimental.theories.Theory)

Example 19 with Metric

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

the class MetricReaderPublicMetricsTests method exposesMetrics.

@Test
public void exposesMetrics() {
    List<Metric<?>> metrics = new ArrayList<>();
    metrics.add(mock(Metric.class));
    metrics.add(mock(Metric.class));
    MetricReader reader = mock(MetricReader.class);
    given(reader.findAll()).willReturn(metrics);
    MetricReaderPublicMetrics publicMetrics = new MetricReaderPublicMetrics(reader);
    assertThat(publicMetrics.metrics()).isEqualTo(metrics);
}
Also used : ArrayList(java.util.ArrayList) Metric(org.springframework.boot.actuate.metrics.Metric) MetricReader(org.springframework.boot.actuate.metrics.reader.MetricReader) Test(org.junit.Test)

Example 20 with Metric

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

the class TomcatPublicMetricsTests method tomcatMetrics.

@Test
public void tomcatMetrics() throws Exception {
    AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(Config.class);
    try {
        TomcatPublicMetrics tomcatMetrics = context.getBean(TomcatPublicMetrics.class);
        Iterator<Metric<?>> metrics = tomcatMetrics.metrics().iterator();
        assertThat(metrics.next().getName()).isEqualTo("httpsessions.max");
        assertThat(metrics.next().getName()).isEqualTo("httpsessions.active");
        assertThat(metrics.hasNext()).isFalse();
    } finally {
        context.close();
    }
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Metric(org.springframework.boot.actuate.metrics.Metric) Test(org.junit.Test)

Aggregations

Metric (org.springframework.boot.actuate.metrics.Metric)24 Test (org.junit.Test)11 CachePublicMetrics (org.springframework.boot.actuate.endpoint.CachePublicMetrics)7 RichGaugeReaderPublicMetrics (org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics)6 LongAdder (java.util.concurrent.atomic.LongAdder)5 Theory (org.junit.experimental.theories.Theory)5 DataSourcePublicMetrics (org.springframework.boot.actuate.endpoint.DataSourcePublicMetrics)5 MetricReaderPublicMetrics (org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics)5 PublicMetrics (org.springframework.boot.actuate.endpoint.PublicMetrics)5 SystemPublicMetrics (org.springframework.boot.actuate.endpoint.SystemPublicMetrics)5 TomcatPublicMetrics (org.springframework.boot.actuate.endpoint.TomcatPublicMetrics)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 HashSet (java.util.HashSet)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 HashMap (java.util.HashMap)2 DataSource (javax.sql.DataSource)2 RichGauge (org.springframework.boot.actuate.metrics.rich.RichGauge)2 Counter (com.codahale.metrics.Counter)1