com.netflix.spectator.api.Registry.distributionSummaries()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中com.netflix.spectator.api.Registry.distributionSummaries方法的一些代码示例,展示了Registry.distributionSummaries的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry.distributionSummaries方法的具体详情如下:
包路径:com.netflix.spectator.api.Registry
类名称:Registry
方法名:distributionSummaries

Registry.distributionSummaries介绍

[英]Returns a stream of all registered distribution summaries. 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 distribution summaries with name "foo":

LongSummaryStatistics countSummary = r.distributionSummaries() 
.filter(Functions.nameEquals("foo")) 
.collect(Collectors.summarizingLong(DistributionSummary::count)); 
LongSummaryStatistics totalSummary = r.distributionSummaries() 
.filter(Functions.nameEquals("foo")) 
.collect(Collectors.summarizingLong(DistributionSummary::totalAmount)); 
double avgAmount = (double) totalSummary.getSum() / countSummary.getSum();

[中]返回所有已注册分发摘要的流。此操作主要用于测试,作为获取聚合值的方便方法。例如,要为所有名为“foo”的分销汇总生成计数和总金额的汇总,请执行以下操作:

LongSummaryStatistics countSummary = r.distributionSummaries() 
.filter(Functions.nameEquals("foo")) 
.collect(Collectors.summarizingLong(DistributionSummary::count)); 
LongSummaryStatistics totalSummary = r.distributionSummaries() 
.filter(Functions.nameEquals("foo")) 
.collect(Collectors.summarizingLong(DistributionSummary::totalAmount)); 
double avgAmount = (double) totalSummary.getSum() / countSummary.getSum();

代码示例

代码示例来源: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<DistributionSummary> distributionSummaries() {
  return composite.distributionSummaries();
}

代码示例来源:origin: Netflix/spectator

private long sum(Registry r, String name) {
 return r.distributionSummaries()
   .filter(Functions.nameEquals(name))
   .mapToLong(DistributionSummary::count)
   .sum();
}

代码示例来源:origin: Netflix/spectator

@Test
public void basic() {
 Registry r = new DefaultRegistry();
 BucketDistributionSummary c = BucketDistributionSummary.get(
   r, r.createId("test"), BucketFunctions.latency(4, TimeUnit.SECONDS));
 c.record(TimeUnit.MILLISECONDS.toNanos(3750));
 Assertions.assertEquals(1, r.distributionSummaries().count());
 Assertions.assertEquals(1, sum(r, "test"));
 c.record(TimeUnit.MILLISECONDS.toNanos(4221));
 Assertions.assertEquals(2, r.distributionSummaries().count());
 Assertions.assertEquals(2, sum(r, "test"));
 c.record(TimeUnit.MILLISECONDS.toNanos(4221));
 Assertions.assertEquals(2, r.distributionSummaries().count());
 Assertions.assertEquals(3, sum(r, "test"));
}

代码示例来源:origin: Netflix/spectator

@Test
public void correctTypeForDistSummariesStream() {
 Registry r = newRegistry(5, false);
 r.distributionSummary("a").record(1);
 r.distributionSummary("b").record(1);
 Assertions.assertEquals(2, r.distributionSummaries().count());
 Assertions.assertEquals(2, r.stream().filter(m -> m instanceof DistributionSummary).count());
}

代码示例来源:origin: Netflix/spectator

@Test
public void distributionSummaries() {
 Registry r = newRegistry(true, 10000);
 r.distributionSummary("foo").record(1L);
 r.distributionSummary("foo", "a", "1", "b", "2").record(1L);
 r.distributionSummary("foo", "a", "1", "b", "3").record(13L);
 r.distributionSummary("foo", "a", "1", "b", "2").record(1L);
 r.distributionSummary("bar", "a", "1", "b", "2").record(1L);
 Assertions.assertEquals(4, r.distributionSummaries().count());
 final LongSummaryStatistics countSummary = r.distributionSummaries()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingLong(DistributionSummary::count));
 Assertions.assertEquals(3L, countSummary.getCount());
 Assertions.assertEquals(4L, countSummary.getSum());
 Assertions.assertEquals(2L, countSummary.getMax());
 final LongSummaryStatistics totalSummary = r.distributionSummaries()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingLong(DistributionSummary::totalAmount));
 Assertions.assertEquals(3L, totalSummary.getCount());
 Assertions.assertEquals(16L, totalSummary.getSum());
 Assertions.assertEquals(13L, totalSummary.getMax());
}

相关文章