Search in sources :

Example 26 with MeterRegistry

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

the class ExecutorServiceSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
    new ExecutorServiceMetrics(es, "executor.sample", emptyList()).bindTo(registry);
    es.scheduleWithFixedDelay(() -> Mono.delay(Duration.ofMillis(20)).block(), 0, 10, TimeUnit.MILLISECONDS);
    while (true) {
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorServiceMetrics(io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 27 with MeterRegistry

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

the class TimerMemory method main.

public static void main(String[] args) throws InterruptedException {
    MeterRegistry registry = SampleRegistries.wavefront();
    Timer t = null;
    for (Integer i = 0; i < 80; i++) {
        t = Timer.builder("my.timer").tag("index", i.toString()).sla(Stream.of(1, 150, 300, 500, 900, 1000, 1200, 1500, 2000, 3000, 4000).map(Duration::ofMillis).toArray(Duration[]::new)).publishPercentiles(0.95).percentilePrecision(1).register(registry);
    }
    // Breakpoint somewhere after the first couple outputs to test pause detection
    // for (int i = 0; ; i = (i + 1) % 2000) {
    // Thread.sleep(2);
    // t.record(1, TimeUnit.MILLISECONDS);
    // if (i == 1000) {
    // t.takeSnapshot().outputSummary(System.out, 1e6);
    // }
    // }
    Flux.never().blockLast();
}
Also used : Timer(io.micrometer.core.instrument.Timer) Duration(java.time.Duration) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 28 with MeterRegistry

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

the class FunctionCounterSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    AtomicInteger n = new AtomicInteger(0);
    FunctionCounter.builder("my.fcounter", n, AtomicInteger::get).baseUnit("happiness").description("A counter derived from a monotonically increasing value").register(registry);
    Counter counter = Counter.builder("my.counter").baseUnit("happiness").description("A normal counter").register(registry);
    Flux.interval(Duration.ofMillis(10)).doOnEach(i -> {
        n.incrementAndGet();
        counter.increment();
    }).blockLast();
}
Also used : Counter(io.micrometer.core.instrument.Counter) Flux(reactor.core.publisher.Flux) SampleConfig(io.micrometer.core.samples.utils.SampleConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Duration(java.time.Duration) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) Counter(io.micrometer.core.instrument.Counter) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 29 with MeterRegistry

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

the class CacheSample method main.

public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    GuavaCacheMetrics.monitor(registry, guavaCache, "book.guava");
    // read all of Frankenstein
    HttpClient.create("www.gutenberg.org").get("/cache/epub/84/pg84.txt").flatMapMany(res -> res.addHandler(wordDecoder()).receive().asString()).delayElements(// one word per 10 ms
    Duration.ofMillis(10)).filter(word -> !word.isEmpty()).doOnNext(word -> {
        if (guavaCache.getIfPresent(word) == null)
            guavaCache.put(word, 1);
    }).blockLast();
}
Also used : IntStream(java.util.stream.IntStream) SampleConfig(io.micrometer.core.samples.utils.SampleConfig) ByteBuf(io.netty.buffer.ByteBuf) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Duration(java.time.Duration) HttpClient(reactor.ipc.netty.http.client.HttpClient) CacheBuilder(com.google.common.cache.CacheBuilder) Unpooled.wrappedBuffer(io.netty.buffer.Unpooled.wrappedBuffer) Cache(com.google.common.cache.Cache) DelimiterBasedFrameDecoder(io.netty.handler.codec.DelimiterBasedFrameDecoder) GuavaCacheMetrics(io.micrometer.core.instrument.binder.cache.GuavaCacheMetrics) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 30 with MeterRegistry

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

the class ClassLoaderMetricsTest method classLoadingMetrics.

@Test
void classLoadingMetrics() {
    MeterRegistry registry = new SimpleMeterRegistry();
    new ClassLoaderMetrics().bindTo(registry);
    assertThat(registry.get("jvm.classes.loaded").gauge().value()).isGreaterThan(0);
}
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