forked from micrometer-metrics/micrometer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hack Timer UX without copying the Builder
- Loading branch information
1 parent
80c20e1
commit 228b2b0
Showing
2 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/Demo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.micrometer.core.samples; | ||
|
||
import io.micrometer.core.instrument.Tags; | ||
import io.micrometer.core.instrument.Timer; | ||
import io.micrometer.prometheus.PrometheusConfig; | ||
import io.micrometer.prometheus.PrometheusMeterRegistry; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Function; | ||
|
||
public class Demo { | ||
|
||
private static final PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); | ||
|
||
private static final Function<Tags, Timer> timerFactory = Timer.builder("cache.initialization.latency") | ||
.description("Time initialize cache from database") | ||
.tag("static", "abc") | ||
.publishPercentiles(0.99, 0.999) | ||
.publishPercentileHistogram() | ||
.minimumExpectedValue(Duration.ofSeconds(10)) | ||
.maximumExpectedValue(Duration.ofSeconds(600)) | ||
.with(registry); | ||
|
||
public static void main(String[] args) { | ||
doSomething("test"); | ||
} | ||
|
||
private static void doSomething(String cacheName) { | ||
timerFactory.apply(Tags.of("cacheName", cacheName)).record(Duration.ofMillis(100)); | ||
System.out.println(registry.scrape()); | ||
} | ||
|
||
} |