Search in sources :

Example 66 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project OpenGrok by OpenGrok.

the class StatisticsFilter method measure.

private void measure(HttpServletResponse httpResponse, HttpServletRequest httpReq, Duration duration, PageConfig config) {
    String category;
    category = getCategory(httpReq, config);
    Timer categoryTimer = Timer.builder("requests.latency").tags("category", category, "code", String.valueOf(httpResponse.getStatus())).register(Metrics.getPrometheusRegistry());
    categoryTimer.record(duration);
    SearchHelper helper = (SearchHelper) config.getRequestAttribute(SearchHelper.REQUEST_ATTR);
    MeterRegistry registry = Metrics.getRegistry();
    if (helper != null && registry != null) {
        if (helper.getHits() == null || helper.getHits().length == 0) {
            Timer.builder("search.latency").tags("category", "ui", "outcome", "empty").register(registry).record(duration);
        } else {
            Timer.builder("search.latency").tags("category", "ui", "outcome", "success").register(registry).record(duration);
        }
    }
}
Also used : Timer(io.micrometer.core.instrument.Timer) SearchHelper(org.opengrok.indexer.web.SearchHelper) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 67 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project OpenGrok by OpenGrok.

the class FileHistoryCache method initialize.

@Override
public void initialize() {
    MeterRegistry meterRegistry = Metrics.getRegistry();
    if (meterRegistry != null) {
        fileHistoryCacheHits = Counter.builder("filehistorycache.history.get").description("file history cache hits").tag("what", "hits").register(meterRegistry);
        fileHistoryCacheMisses = Counter.builder("filehistorycache.history.get").description("file history cache misses").tag("what", "miss").register(meterRegistry);
    }
}
Also used : MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 68 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)

Example 69 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 70 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)

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