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

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

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

Registry.gauges介绍

[英]Returns a stream of all registered gauges. This operation is mainly used for testing as a convenient way to get an aggregated value. For example, to generate a summary of the values for all gauges with name "foo":

DoubleSummaryStatistics valueSummary = r.gauges() 
.filter(Functions.nameEquals("foo")) 
.collect(Collectors.summarizingDouble(Gauge::value)); 
double sum = (double) valueSummary.getSum();

[中]返回所有注册仪表的流。此操作主要用于测试,作为获取聚合值的方便方法。例如,要生成名为“foo”的所有仪表值的摘要,请执行以下操作:

DoubleSummaryStatistics valueSummary = r.gauges() 
.filter(Functions.nameEquals("foo")) 
.collect(Collectors.summarizingDouble(Gauge::value)); 
double sum = (double) valueSummary.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<Gauge> gauges() {
  return composite.gauges();
}

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

@Test
 public void correctTypeForGaugesStream() {
  Registry r = newRegistry(5, false);
  r.gauge(r.createId("a")).set(1.0);
  r.gauge(r.createId("b")).set(2.0);
  Assertions.assertEquals(2, r.gauges().count());
  Assertions.assertEquals(2, r.stream().filter(m -> m instanceof Gauge).count());
 }
}

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

@Test
public void gauges() {
 Registry r = newRegistry(true, 10000);
 r.gauge(r.createId("foo", "a", "1")).set(1.0);
 r.gauge(r.createId("foo", "a", "2")).set(2.0);
 r.gauge(r.createId("bar")).set(7.0);
 Assertions.assertEquals(3, r.gauges().count());
 final DoubleSummaryStatistics valueSummary = r.gauges()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingDouble(Gauge::value));
 Assertions.assertEquals(2, valueSummary.getCount());
 Assertions.assertEquals(3.0, valueSummary.getSum(), 1e-12);
 Assertions.assertEquals(1.5, valueSummary.getAverage(), 1e-12);
}

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

@Test
public void maxGauge() {
 Registry r = newRegistry(true, 10000);
 r.maxGauge("foo").set(1.0);
 r.maxGauge("foo").set(3.0);
 r.maxGauge("foo").set(2.0);
 final DoubleSummaryStatistics valueSummary = r.gauges()
   .filter(Functions.nameEquals("foo"))
   .collect(Collectors.summarizingDouble(Gauge::value));
 Assertions.assertEquals(1, valueSummary.getCount());
 Assertions.assertEquals(3.0, valueSummary.getSum(), 1e-12);
}

相关文章