Search in sources :

Example 16 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project micrometer by micrometer-metrics.

the class NullGaugeSample method main.

public static void main(String[] args) throws InterruptedException {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    AtomicInteger n = new AtomicInteger(100);
    registry.gauge("my.null.gauge", (Object) null, o -> 1.0);
    registry.gauge("my.nonnull.gauge", n);
    for (; ; ) {
        Thread.sleep(100);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 17 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project micrometer by micrometer-metrics.

the class TimerMaximumThroughputSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    Timer timer = Timer.builder("timer").publishPercentileHistogram().sla(Duration.ofMillis(275), Duration.ofMillis(300), Duration.ofMillis(500)).distributionStatisticExpiry(Duration.ofSeconds(10)).distributionStatisticBufferLength(3).register(registry);
    RandomEngine r = new MersenneTwister64(0);
    Normal duration = new Normal(250, 50, r);
    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1)).doOnEach(d -> latencyForThisSecond.set(duration.nextInt())).subscribe();
    Stream<Integer> infiniteStream = Stream.iterate(0, i -> (i + 1) % 1000);
    Flux.fromStream(infiniteStream).parallel(4).runOn(Schedulers.parallel()).doOnEach(d -> timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS)).subscribe();
    Flux.never().blockLast();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) Timer(io.micrometer.core.instrument.Timer) Stream(java.util.stream.Stream) RandomEngine(cern.jet.random.engine.RandomEngine) SampleConfig(io.micrometer.core.samples.utils.SampleConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Normal(cern.jet.random.Normal) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Duration(java.time.Duration) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) Schedulers(reactor.core.scheduler.Schedulers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Timer(io.micrometer.core.instrument.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) RandomEngine(cern.jet.random.engine.RandomEngine) Normal(cern.jet.random.Normal) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 18 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project micrometer by micrometer-metrics.

the class TimerSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    Timer timer = Timer.builder("timer").publishPercentileHistogram().publishPercentiles(0.5, 0.95, 0.99).sla(Duration.ofMillis(275), Duration.ofMillis(300), Duration.ofMillis(500)).distributionStatisticExpiry(Duration.ofSeconds(10)).distributionStatisticBufferLength(3).register(registry);
    FunctionTimer.builder("ftimer", timer, Timer::count, t -> t.totalTime(TimeUnit.SECONDS), TimeUnit.SECONDS).register(registry);
    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal duration = new Normal(250, 50, r);
    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1)).doOnEach(d -> latencyForThisSecond.set(duration.nextInt())).subscribe();
    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofMillis(10)).doOnEach(d -> {
        if (incomingRequests.nextDouble() + 0.4 > 0) {
            // pretend the request took some amount of time, such that the time is
            // distributed normally with a mean of 250ms
            timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
        }
    }).blockLast();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) Timer(io.micrometer.core.instrument.Timer) RandomEngine(cern.jet.random.engine.RandomEngine) SampleConfig(io.micrometer.core.samples.utils.SampleConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Normal(cern.jet.random.Normal) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Duration(java.time.Duration) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) FunctionTimer(io.micrometer.core.instrument.FunctionTimer) Timer(io.micrometer.core.instrument.Timer) FunctionTimer(io.micrometer.core.instrument.FunctionTimer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) RandomEngine(cern.jet.random.engine.RandomEngine) Normal(cern.jet.random.Normal) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 19 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project micrometer by micrometer-metrics.

the class TimerTest method recordThrowable.

@DisplayName("record throwables")
@Test
default void recordThrowable() {
    MeterRegistry registry = new SimpleMeterRegistry();
    Supplier<String> timed = () -> registry.timer("timer").record(() -> "");
    timed.get();
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 20 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project micrometer by micrometer-metrics.

the class FunctionTimerSample method main.

// For Atlas: http://localhost:7101/api/v1/graph?q=name,ftimer,:eq,:dist-avg,name,timer,:eq,:dist-avg,1,:axis&s=e-5m&l=0
public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    Timer timer = Timer.builder("timer").publishPercentiles(0.5, 0.95).register(registry);
    Object placeholder = new Object();
    AtomicLong totalTimeNanos = new AtomicLong(0);
    AtomicLong totalCount = new AtomicLong(0);
    FunctionTimer.builder("ftimer", placeholder, p -> totalCount.get(), p -> totalTimeNanos.get(), TimeUnit.NANOSECONDS).register(registry);
    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal duration = new Normal(250, 50, r);
    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1)).doOnEach(d -> latencyForThisSecond.set(duration.nextInt())).subscribe();
    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofMillis(10)).doOnEach(d -> {
        if (incomingRequests.nextDouble() + 0.4 > 0) {
            // pretend the request took some amount of time, such that the time is
            // distributed normally with a mean of 250ms
            timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
            totalCount.incrementAndGet();
            totalTimeNanos.addAndGet((long) TimeUtils.millisToUnit(latencyForThisSecond.get(), TimeUnit.NANOSECONDS));
        }
    }).blockLast();
}
Also used : SampleConfig(io.micrometer.core.samples.utils.SampleConfig) Normal(cern.jet.random.Normal) FunctionTimer(io.micrometer.core.instrument.FunctionTimer) TimeUtils(io.micrometer.core.instrument.util.TimeUtils) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) Timer(io.micrometer.core.instrument.Timer) RandomEngine(cern.jet.random.engine.RandomEngine) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Duration(java.time.Duration) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) AtomicLong(java.util.concurrent.atomic.AtomicLong) FunctionTimer(io.micrometer.core.instrument.FunctionTimer) Timer(io.micrometer.core.instrument.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) RandomEngine(cern.jet.random.engine.RandomEngine) Normal(cern.jet.random.Normal) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Aggregations

MeterRegistry (io.micrometer.core.instrument.MeterRegistry)42 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)21 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)10 Timer (io.micrometer.core.instrument.Timer)9 Duration (java.time.Duration)9 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)8 Match (io.vertx.micrometer.Match)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Normal (cern.jet.random.Normal)6 MersenneTwister64 (cern.jet.random.engine.MersenneTwister64)6 RandomEngine (cern.jet.random.engine.RandomEngine)6 Gauge (io.micrometer.core.instrument.Gauge)6 Flux (reactor.core.publisher.Flux)6 Counter (io.micrometer.core.instrument.Counter)5 MetricUtils.getName (io.github.resilience4j.micrometer.MetricUtils.getName)4 MeterBinder (io.micrometer.core.instrument.binder.MeterBinder)4 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 TimeUnit (java.util.concurrent.TimeUnit)4