Search in sources :

Example 21 with MeterRegistry

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

the class LongTaskTimerSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    LongTaskTimer timer = registry.more().longTaskTimer("longTaskTimer");
    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal duration = new Normal(30, 50, r);
    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1)).doOnEach(d -> latencyForThisSecond.set(duration.nextInt())).subscribe();
    final Map<LongTaskTimer.Sample, CountDownLatch> tasks = new ConcurrentHashMap<>();
    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofSeconds(1)).doOnEach(d -> {
        if (incomingRequests.nextDouble() + 0.4 > 0 && tasks.isEmpty()) {
            int taskDur;
            while ((taskDur = duration.nextInt()) < 0) ;
            synchronized (tasks) {
                tasks.put(timer.start(), new CountDownLatch(taskDur));
            }
        }
        synchronized (tasks) {
            for (Map.Entry<LongTaskTimer.Sample, CountDownLatch> e : tasks.entrySet()) {
                e.getValue().countDown();
                if (e.getValue().getCount() == 0) {
                    e.getKey().stop();
                    tasks.remove(e.getKey());
                }
            }
        }
    }).blockLast();
}
Also used : LongTaskTimer(io.micrometer.core.instrument.LongTaskTimer) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) 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) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MersenneTwister64(cern.jet.random.engine.MersenneTwister64) RandomEngine(cern.jet.random.engine.RandomEngine) LongTaskTimer(io.micrometer.core.instrument.LongTaskTimer) Normal(cern.jet.random.Normal) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 22 with MeterRegistry

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

the class SimulatedEndpointInstrumentation method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    Timer e1Success = Timer.builder("http.server.requests").tags("uri", "/api/bar").tags("response", "200").publishPercentiles(0.5, 0.95).register(registry);
    Timer e2Success = Timer.builder("http.server.requests").tags("uri", "/api/foo").tags("response", "200").publishPercentiles(0.5, 0.95).register(registry);
    Timer e1Fail = Timer.builder("http.server.requests").tags("uri", "/api/bar").tags("response", "500").publishPercentiles(0.5, 0.95).register(registry);
    Timer e2Fail = Timer.builder("http.server.requests").tags("uri", "/api/foo").tags("response", "500").publishPercentiles(0.5, 0.95).register(registry);
    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal successOrFail = new Normal(0, 1, r);
    Normal duration = new Normal(250, 50, r);
    Normal duration2 = new Normal(250, 50, r);
    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1)).doOnEach(d -> latencyForThisSecond.set(duration.nextInt())).subscribe();
    AtomicInteger latencyForThisSecond2 = new AtomicInteger(duration2.nextInt());
    Flux.interval(Duration.ofSeconds(1)).doOnEach(d -> latencyForThisSecond2.set(duration2.nextInt())).subscribe();
    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofMillis(10)).doOnEach(d -> {
        // are we going to receive a request for /api/foo?
        if (incomingRequests.nextDouble() + 0.4 > 0) {
            if (successOrFail.nextDouble() + 0.8 > 0) {
                // pretend the request took some amount of time, such that the time is
                // distributed normally with a mean of 250ms
                e1Success.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
            } else {
                e1Fail.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
            }
        }
    }).subscribe();
    // the potential for an "incoming request" every 1 ms
    Flux.interval(Duration.ofMillis(1)).doOnEach(d -> {
        // are we going to receive a request for /api/bar?
        if (incomingRequests.nextDouble() + 0.4 > 0) {
            if (successOrFail.nextDouble() + 0.8 > 0) {
                // pretend the request took some amount of time, such that the time is
                // distributed normally with a mean of 250ms
                e2Success.record(latencyForThisSecond2.get(), TimeUnit.MILLISECONDS);
            } else {
                e2Fail.record(latencyForThisSecond2.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) 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 23 with MeterRegistry

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

the class UptimeMetricsSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    registry.config().commonTags("instance", "sample-host");
    new UptimeMetrics().bindTo(registry);
}
Also used : UptimeMetrics(io.micrometer.core.instrument.binder.system.UptimeMetrics) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 24 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-cloud-netflix by spring-cloud.

the class DefaultCounterFactoryTests method shouldIncrement.

@Test
public void shouldIncrement() throws Exception {
    MeterRegistry meterRegistry = mock(MeterRegistry.class);
    CounterFactory factory = new DefaultCounterFactory(meterRegistry);
    Counter counter = mock(Counter.class);
    when(meterRegistry.counter(NAME)).thenReturn(counter);
    factory.increment(NAME);
    verify(counter).increment();
}
Also used : Counter(io.micrometer.core.instrument.Counter) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) CounterFactory(com.netflix.zuul.monitoring.CounterFactory) Test(org.junit.Test)

Example 25 with MeterRegistry

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

the class ProcessorMetricsTest method openJ9CpuMetrics.

@Test
void openJ9CpuMetrics() {
    assumeTrue(classExists("com.ibm.lang.management.OperatingSystemMXBean"));
    MeterRegistry registry = new SimpleMeterRegistry();
    new ProcessorMetrics().bindTo(registry);
    /*
         * We can't assert on values because these methods are documented to return "-1"
         * on the first call and a positive value - if supported - on subsequent calls.
         * This holds true for "system.cpu.usage" but not for "process.cpu.usage". The latter
         * needs some milliseconds of sleep before it actually returns a positive value
         * on a supported system. Thread.sleep() is flaky, though.
         */
    registry.get("system.cpu.usage").gauge();
    registry.get("process.cpu.usage").gauge();
}
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)

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