Search in sources :

Example 71 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 72 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 73 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)

Example 74 with MeterRegistry

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

the class UptimeMetricsTest method uptimeMetricsMock.

@Test
void uptimeMetricsMock() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    RuntimeMXBean runtimeMXBean = mock(RuntimeMXBean.class);
    when(runtimeMXBean.getUptime()).thenReturn(1337L);
    when(runtimeMXBean.getStartTime()).thenReturn(4711L);
    new UptimeMetrics(runtimeMXBean, emptyList()).bindTo(registry);
    assertThat(registry.get("process.uptime").timeGauge().value()).isEqualTo(1.337);
    assertThat(registry.get("process.start.time").timeGauge().value()).isEqualTo(4.711);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) RuntimeMXBean(java.lang.management.RuntimeMXBean) MockClock(io.micrometer.core.instrument.MockClock) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 75 with MeterRegistry

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

the class UptimeMetricsTest method uptimeMetricsRuntime.

@Test
void uptimeMetricsRuntime() {
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    new UptimeMetrics().bindTo(registry);
    registry.get("process.uptime").timeGauge();
    registry.get("process.start.time").timeGauge();
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MockClock(io.micrometer.core.instrument.MockClock) 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)136 Test (org.junit.jupiter.api.Test)83 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)60 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)17 Timer (io.micrometer.core.instrument.Timer)15 Test (org.junit.Test)15 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)12 Duration (java.time.Duration)11 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)10 HikariDataSource (com.zaxxer.hikari.HikariDataSource)9 DataSource (javax.sql.DataSource)9 DelegatingDataSource (org.springframework.jdbc.datasource.DelegatingDataSource)9 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)8 Match (io.vertx.micrometer.Match)8 FunctionCounter (io.micrometer.core.instrument.FunctionCounter)7 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