本文整理了Java中com.netflix.spectator.api.Registry.timers
方法的一些代码示例,展示了Registry.timers
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry.timers
方法的具体详情如下:
包路径:com.netflix.spectator.api.Registry
类名称:Registry
方法名:timers
[英]Returns a stream of all registered timers. This operation is mainly used for testing as a convenient way to get an aggregated value. For example, to generate a summary of the counts and total amounts for all timers with name "foo":
LongSummaryStatistics countSummary = r.timers()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Timer::count));
LongSummaryStatistics totalSummary = r.timers()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Timer::totalTime));
double avgTime = (double) totalSummary.getSum() / countSummary.getSum();
[中]返回所有已注册计时器的流。此操作主要用于测试,作为获取聚合值的方便方法。例如,要为所有名为“foo”的计时器生成计数和总金额的摘要:
代码示例来源:origin: Netflix/servo
@Test
public void testUnregisteredBasicTimer() {
BasicTimer t = new BasicTimer(CONFIG);
assertEquals(0, registry.timers().count());
}
代码示例来源:origin: Netflix/servo
@Test
public void testUnregisteredBasicTimerIncrement() {
BasicTimer t = new BasicTimer(CONFIG);
t.record(42, TimeUnit.MILLISECONDS);
Id id = registry.createId("test")
.withTag("unit", "MILLISECONDS");
assertEquals(3, registry.counters().count());
assertEquals(0, registry.timers().count());
assertEquals(1, registry.gauges().count());
assertEquals(0, registry.distributionSummaries().count());
assertEquals(1, registry.counter(id.withTag(Statistic.count)).count());
assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).count());
assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).count());
assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value());
}
代码示例来源:origin: org.springframework.metrics/spring-metrics
@Override
public Stream<Timer> timers() {
return composite.timers();
}
代码示例来源:origin: Netflix/spectator
private long sum(Registry r, String name) {
return r.timers().filter(Functions.nameEquals(name)).mapToLong(Timer::count).sum();
}
代码示例来源:origin: Netflix/spectator
@Test
public void testMetricCollection() {
execRequest("http://foo", 200);
//then
List<Meter> allMetrics = new ArrayList<>();
registry.iterator().forEachRemaining(allMetrics::add);
assertEquals(2, allMetrics.size());
Optional<Timer> expectedTimer = registry.timers().findFirst();
assertTrue(expectedTimer.isPresent());
Timer timer = expectedTimer.get();
assertEquals(1, timer.count());
assertEquals(100000, timer.totalTime());
Optional<Counter> expectedCounter = registry.counters().findFirst();
assertTrue(expectedCounter.isPresent());
assertEquals(12345L, expectedCounter.get().count());
}
代码示例来源:origin: Netflix/spectator
@Test
public void testMetricCollection() {
execRequest("http://foo", 200);
//then
List<Meter> allMetrics = new ArrayList<>();
registry.iterator().forEachRemaining(allMetrics::add);
assertEquals(2, allMetrics.size());
Optional<Timer> expectedTimer = registry.timers().findFirst();
assertTrue(expectedTimer.isPresent());
Timer timer = expectedTimer.get();
assertEquals(1, timer.count());
assertEquals(100000, timer.totalTime());
Optional<Counter> expectedCounter = registry.counters().findFirst();
assertTrue(expectedCounter.isPresent());
assertEquals(12345L, expectedCounter.get().count());
}
代码示例来源:origin: Netflix/spectator
@Test
public void correctTypeForTimersStream() {
Registry r = newRegistry(5, false);
r.timer("a").record(1, TimeUnit.MICROSECONDS);
r.timer("b").record(1, TimeUnit.MICROSECONDS);
Assertions.assertEquals(2, r.timers().count());
Assertions.assertEquals(2, r.stream().filter(m -> m instanceof Timer).count());
}
代码示例来源:origin: Netflix/spectator
@Test
public void basic() {
Registry r = new DefaultRegistry();
BucketTimer t = BucketTimer.get(
r, r.createId("test"), BucketFunctions.latency(4, TimeUnit.SECONDS));
t.record(3750, TimeUnit.MILLISECONDS);
Assertions.assertEquals(1, r.timers().count());
Assertions.assertEquals(1, sum(r, "test"));
t.record(4221, TimeUnit.MILLISECONDS);
Assertions.assertEquals(2, r.timers().count());
Assertions.assertEquals(2, sum(r, "test"));
t.record(4221, TimeUnit.MILLISECONDS);
Assertions.assertEquals(2, r.timers().count());
Assertions.assertEquals(3, sum(r, "test"));
}
代码示例来源:origin: Netflix/spectator
@Test
public void timers() {
Registry r = newRegistry(true, 10000);
r.timer("foo").record(1L, TimeUnit.NANOSECONDS);
r.timer("foo", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS);
r.timer("foo", "a", "1", "b", "3").record(13L, TimeUnit.NANOSECONDS);
r.timer("foo", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS);
r.timer("bar", "a", "1", "b", "2").record(1L, TimeUnit.NANOSECONDS);
Assertions.assertEquals(4, r.timers().count());
final LongSummaryStatistics countSummary = r.timers()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Timer::count));
Assertions.assertEquals(3L, countSummary.getCount());
Assertions.assertEquals(4L, countSummary.getSum());
Assertions.assertEquals(2L, countSummary.getMax());
final LongSummaryStatistics totalSummary = r.timers()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Timer::totalTime));
Assertions.assertEquals(3L, totalSummary.getCount());
Assertions.assertEquals(16L, totalSummary.getSum());
Assertions.assertEquals(13L, totalSummary.getMax());
}
内容来源于网络,如有侵权,请联系作者删除!