io.micrometer.core.instrument.FunctionTimer Java Examples
The following examples show how to use
io.micrometer.core.instrument.FunctionTimer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateQueryMetricsTest.java From micrometer with Apache License 2.0 | 6 votes |
@Test void metricsEventHandlerRegistersMetrics() { String query = "Select generatedAlias0 from Table as generatedAlias0 where generatedAlias0.param0 :val0"; HibernateQueryMetrics.MetricsEventHandler eventHandler = hibernateQueryMetrics.new MetricsEventHandler(registry); Statistics statistics = createQueryStatisticsMock(query); eventHandler.registerQueryMetric(statistics); assertThat(registry.get("hibernate.query.cache.requests").tags("result", "hit", "query", query).functionCounter().count()).isEqualTo(43.0d); assertThat(registry.get("hibernate.query.cache.requests").tags("result", "miss", "query", query).functionCounter().count()).isEqualTo(43.0d); assertThat(registry.get("hibernate.query.cache.puts").tags("query", query).functionCounter().count()).isEqualTo(43.0d); FunctionTimer timer = registry.get("hibernate.query.execution.total").tags("query", query).functionTimer(); assertThat(timer.count()).isEqualTo(43.0d); assertThat(timer.totalTime(TimeUnit.MILLISECONDS)).isEqualTo(43.0d); assertThat(registry.get("hibernate.query.execution.max").tags("query", query).timeGauge().value(TimeUnit.MILLISECONDS)).isEqualTo(43.0d); assertThat(registry.get("hibernate.query.execution.min").tags("query", query).timeGauge().value(TimeUnit.MILLISECONDS)).isEqualTo(43.0d); assertThat(registry.get("hibernate.query.execution.rows").tags("query", query).functionCounter().count()).isEqualTo(43.0); }
Example #2
Source File: CompositeFunctionTimer.java From micrometer with Apache License 2.0 | 5 votes |
@Override FunctionTimer registerNewMeter(MeterRegistry registry) { final T obj = ref.get(); if (obj == null) { return null; } return FunctionTimer.builder(getId().getName(), obj, countFunction, totalTimeFunction, totalTimeFunctionUnit) .tags(getId().getTagsAsIterable()) .description(getId().getDescription()) .register(registry); }
Example #3
Source File: SimpleMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void newFunctionTimerWhenCountingModeIsCumulativeShouldReturnCumulativeFunctionTimer() { SimpleMeterRegistry registry = createRegistry(CountingMode.CUMULATIVE); Meter.Id id = new Meter.Id("some.timer", Tags.empty(), null, null, Meter.Type.TIMER); FunctionTimer functionTimer = registry.newFunctionTimer(id, null, (o) -> 0L, (o) -> 0d, TimeUnit.SECONDS); assertThat(functionTimer).isInstanceOf(CumulativeFunctionTimer.class); }
Example #4
Source File: SimpleMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test void newFunctionTimerWhenCountingModeIsStepShouldReturnStepFunctionTimer() { SimpleMeterRegistry registry = createRegistry(CountingMode.STEP); Meter.Id id = new Meter.Id("some.timer", Tags.empty(), null, null, Meter.Type.TIMER); FunctionTimer functionTimer = registry.newFunctionTimer(id, null, (o) -> 0L, (o) -> 0d, TimeUnit.SECONDS); assertThat(functionTimer).isInstanceOf(StepFunctionTimer.class); }
Example #5
Source File: TimerSample.java From micrometer with Apache License 2.0 | 5 votes |
public static void main(String[] args) { MeterRegistry registry = SampleConfig.myMonitoringSystem(); Timer timer = Timer.builder("timer") .publishPercentileHistogram() .publishPercentiles(0.5, 0.95, 0.99) .serviceLevelObjectives(Duration.ofMillis(275), Duration.ofMillis(300), Duration.ofMillis(500)) .distributionStatisticExpiry(Duration.ofSeconds(10)) .distributionStatisticBufferLength(3) .register(registry); AtomicLong totalCount = new AtomicLong(); AtomicLong totalTime = new AtomicLong(); FunctionTimer.builder("ftimer", totalCount, t -> totalCount.get(), t -> totalTime.get(), TimeUnit.MILLISECONDS) .register(registry); RandomEngine r = new MersenneTwister64(0); Normal incomingRequests = new Normal(0, 1, r); Normal duration = new Normal(250, 50, r); AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt()); Flux.interval(Duration.ofSeconds(1)) .doOnEach(d -> latencyForThisSecond.set(duration.nextInt())) .subscribe(); // the potential for an "incoming request" every 10 ms Flux.interval(Duration.ofMillis(10)) .doOnEach(d -> { if (incomingRequests.nextDouble() + 0.4 > 0) { // pretend the request took some amount of time, such that the time is // distributed normally with a mean of 250ms int latency = latencyForThisSecond.get(); timer.record(latency, TimeUnit.MILLISECONDS); totalTime.addAndGet(latency); totalCount.incrementAndGet(); } }) .blockLast(); }
Example #6
Source File: FunctionTimerSample.java From micrometer with Apache License 2.0 | 5 votes |
public static void main(String[] args) { MeterRegistry registry = SampleConfig.myMonitoringSystem(); Timer timer = Timer.builder("timer") .publishPercentiles(0.5, 0.95) .register(registry); Object placeholder = new Object(); AtomicLong totalTimeNanos = new AtomicLong(0); AtomicLong totalCount = new AtomicLong(0); FunctionTimer.builder("ftimer", placeholder, p -> totalCount.get(), p -> totalTimeNanos.get(), TimeUnit.NANOSECONDS) .register(registry); RandomEngine r = new MersenneTwister64(0); Normal incomingRequests = new Normal(0, 1, r); Normal duration = new Normal(250, 50, r); AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt()); Flux.interval(Duration.ofSeconds(1)) .doOnEach(d -> latencyForThisSecond.set(duration.nextInt())) .subscribe(); // the potential for an "incoming request" every 10 ms Flux.interval(Duration.ofMillis(10)) .doOnEach(d -> { if (incomingRequests.nextDouble() + 0.4 > 0) { // pretend the request took some amount of time, such that the time is // distributed normally with a mean of 250ms timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS); totalCount.incrementAndGet(); totalTimeNanos.addAndGet((long) TimeUtils.millisToUnit(latencyForThisSecond.get(), TimeUnit.NANOSECONDS)); } }) .blockLast(); }
Example #7
Source File: SkywalkingMeterRegistry.java From skywalking with Apache License 2.0 | 5 votes |
@Override protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit) { final MeterId meterId = convertId(id); FunctionTimer ft = new CumulativeFunctionTimer<>(id, obj, countFunction, totalTimeFunction, totalTimeFunctionUnit, getBaseTimeUnit()); final String baseName = meterId.getName(); MeterFactory.gauge( meterId.copyTo(baseName + "_count", MeterId.MeterType.GAUGE), () -> ft.count()).build(); MeterFactory.gauge( meterId.copyTo(baseName + "_sum", MeterId.MeterType.GAUGE), () -> ft.totalTime(TimeUnit.MILLISECONDS)).build(); return ft; }
Example #8
Source File: DefaultDestinationPublishingMeterRegistry.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Override protected <T> FunctionTimer newFunctionTimer(Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits) { return new StepFunctionTimer<T>(id, this.clock, this.metricsPublisherConfig.step().toMillis(), obj, countFunction, totalTimeFunction, totalTimeFunctionUnits, getBaseTimeUnit()); }
Example #9
Source File: CompositeFunctionTimer.java From micrometer with Apache License 2.0 | 4 votes |
@Override FunctionTimer newNoopMeter() { return new NoopFunctionTimer(getId()); }
Example #10
Source File: HazelcastCacheMetricsTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test void reportMetrics() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); metrics.bindTo(meterRegistry); verifyCommonCacheMetrics(meterRegistry, metrics); LocalMapStats localMapStats = cache.getLocalMapStats(); Gauge backupEntries = fetch(meterRegistry, "cache.entries", Tags.of("ownership", "backup")).gauge(); assertThat(backupEntries.value()).isEqualTo(localMapStats.getBackupEntryCount()); Gauge ownedEntries = fetch(meterRegistry, "cache.entries", Tags.of("ownership", "owned")).gauge(); assertThat(ownedEntries.value()).isEqualTo(localMapStats.getOwnedEntryCount()); Gauge backupEntryMemory = fetch(meterRegistry, "cache.entry.memory", Tags.of("ownership", "backup")).gauge(); assertThat(backupEntryMemory.value()).isEqualTo(localMapStats.getBackupEntryMemoryCost()); Gauge ownedEntryMemory = fetch(meterRegistry, "cache.entry.memory", Tags.of("ownership", "owned")).gauge(); assertThat(ownedEntryMemory.value()).isEqualTo(localMapStats.getOwnedEntryMemoryCost()); FunctionCounter partitionGets = fetch(meterRegistry, "cache.partition.gets").functionCounter(); assertThat(partitionGets.count()).isEqualTo(localMapStats.getGetOperationCount()); // near cache stats NearCacheStats nearCacheStats = localMapStats.getNearCacheStats(); Gauge hitCacheRequests = fetch(meterRegistry, "cache.near.requests", Tags.of("result", "hit")).gauge(); assertThat(hitCacheRequests.value()).isEqualTo(nearCacheStats.getHits()); Gauge missCacheRequests = fetch(meterRegistry, "cache.near.requests", Tags.of("result", "miss")).gauge(); assertThat(missCacheRequests.value()).isEqualTo(nearCacheStats.getMisses()); Gauge nearPersistance = fetch(meterRegistry, "cache.near.persistences").gauge(); assertThat(nearPersistance.value()).isEqualTo(nearCacheStats.getPersistenceCount()); Gauge nearEvictions = fetch(meterRegistry, "cache.near.evictions").gauge(); assertThat(nearEvictions.value()).isEqualTo(nearCacheStats.getEvictions()); // timings TimeUnit timeUnit = TimeUnit.MILLISECONDS; FunctionTimer getsLatency = fetch(meterRegistry, "cache.gets.latency").functionTimer(); assertThat(getsLatency.count()).isEqualTo(localMapStats.getGetOperationCount()); assertThat(getsLatency.totalTime(timeUnit)).isEqualTo(localMapStats.getTotalGetLatency()); FunctionTimer putsLatency = fetch(meterRegistry, "cache.puts.latency").functionTimer(); assertThat(putsLatency.count()).isEqualTo(localMapStats.getPutOperationCount()); assertThat(putsLatency.totalTime(timeUnit)).isEqualTo(localMapStats.getTotalPutLatency()); FunctionTimer removeLatency = fetch(meterRegistry, "cache.removals.latency").functionTimer(); assertThat(removeLatency.count()).isEqualTo(localMapStats.getRemoveOperationCount()); assertThat(removeLatency.totalTime(timeUnit)).isEqualTo(localMapStats.getTotalRemoveLatency()); }
Example #11
Source File: FunctionTimerMetricsConverter.java From cf-java-logging-support with Apache License 2.0 | 4 votes |
@Override public Stream<Metric> getMetrics(FunctionTimer meter) { return Stream.of(toMetric(withStatistic(meter, "count"), meter.count()), toMetric(withStatistic(meter, "mean"), meter.mean(getBaseTimeUnit())), toMetric(withStatistic(meter, "totalTime"), meter.totalTime(getBaseTimeUnit()))); }
Example #12
Source File: NoopMeterRegistry.java From dolphin-platform with Apache License 2.0 | 4 votes |
@Override protected <T> FunctionTimer newFunctionTimer(final Meter.Id id, final T obj, final ToLongFunction<T> countFunction, final ToDoubleFunction<T> totalTimeFunction, final TimeUnit totalTimeFunctionUnits) { return new NoopFunctionTimer(id); }
Example #13
Source File: NoopMeterRegistry.java From armeria with Apache License 2.0 | 4 votes |
@Override protected <T> FunctionTimer newFunctionTimer(Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnits) { return new NoopFunctionTimer(id); }
Example #14
Source File: NewRelicClientProvider.java From micrometer with Apache License 2.0 | votes |
Object writeFunctionTimer(FunctionTimer timer);