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);
}
}
}
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);
}
}
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();
}
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) {
}
}
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();
}
Aggregations