Search in sources :

Example 1 with Metric

use of org.springframework.boot.actuate.metrics.Metric 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)

Example 2 with Metric

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

the class InMemoryMetricRepository method increment.

@Override
public void increment(Delta<?> delta) {
    final String metricName = delta.getName();
    final int amount = delta.getValue().intValue();
    final Date timestamp = delta.getTimestamp();
    this.metrics.update(metricName, new Callback<Metric<?>>() {

        @Override
        public Metric<?> modify(Metric<?> current) {
            if (current != null) {
                return new Metric<>(metricName, current.increment(amount).getValue(), timestamp);
            }
            return new Metric<>(metricName, (long) amount, timestamp);
        }
    });
}
Also used : Metric(org.springframework.boot.actuate.metrics.Metric) Date(java.util.Date)

Example 3 with Metric

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

the class BufferGaugeServiceSpeedTests method reader.

@Theory
public void reader(String input) throws Exception {
    iterate("writeReader");
    double rate = number / watch.getLastTaskTimeMillis() * 1000;
    System.err.println("Rate(" + count + ")=" + rate + ", " + watch);
    watch.start("readReader" + 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(0 < total.longValue()).isTrue();
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) Metric(org.springframework.boot.actuate.metrics.Metric) Theory(org.junit.experimental.theories.Theory)

Example 4 with Metric

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

the class CounterServiceSpeedTests method reader.

@Theory
public void reader(String input) throws Exception {
    iterate("writeReader");
    double rate = number / watch.getLastTaskTimeMillis() * 1000;
    System.err.println("Rate(" + count + ")=" + rate + ", " + watch);
    watch.start("readReader" + 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) Metric(org.springframework.boot.actuate.metrics.Metric) Theory(org.junit.experimental.theories.Theory)

Example 5 with Metric

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

the class DefaultGaugeServiceSpeedTests method gauges.

@Theory
public void gauges(String input) throws Exception {
    watch.start("gauges" + 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];
                DefaultGaugeServiceSpeedTests.this.gaugeService.submit(name, count + i);
            }
        }
    };
    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("Gauges 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(0 < total.longValue()).isTrue();
}
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)

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