forked from micrometer-metrics/micrometer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c839f96
commit f47c83b
Showing
4 changed files
with
64 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
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
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()); | ||
} | ||
|
||
} |