本文整理了Java中com.netflix.spectator.api.Registry.counters
方法的一些代码示例,展示了Registry.counters
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry.counters
方法的具体详情如下:
包路径:com.netflix.spectator.api.Registry
类名称:Registry
方法名:counters
[英]Returns a stream of all registered counters. This operation is mainly used for testing as a convenient way to get an aggregated value. For example, to generate a summary of all counters with name "foo":
LongSummaryStatistics summary = r.counters()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Counter::count));
[中]返回所有已注册计数器的流。此操作主要用于测试,作为获取聚合值的方便方法。例如,要生成名为“foo”的所有计数器的摘要:
代码示例来源:origin: Netflix/servo
@Test
public void testUnregisteredBasicCounter() {
BasicCounter c = new BasicCounter(CONFIG);
assertEquals(0, registry.counters().count());
}
代码示例来源:origin: Netflix/servo
@Test
public void testUnregisteredBasicCounterIncrement() {
BasicCounter c = new BasicCounter(CONFIG);
c.increment();
assertEquals(1, registry.counters().count());
assertEquals(1, registry.counter("test").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<Counter> counters() {
return composite.counters();
}
代码示例来源:origin: Netflix/spectator
private long sum(Registry r, String name) {
return r.counters().filter(Functions.nameEquals(name)).mapToLong(Counter::count).sum();
}
代码示例来源:origin: Netflix/spectator
@Test
public void basic() {
Registry r = new DefaultRegistry();
BucketCounter c = BucketCounter.get(
r, r.createId("test"), BucketFunctions.latency(4, TimeUnit.SECONDS));
c.record(TimeUnit.MILLISECONDS.toNanos(3750));
Assertions.assertEquals(1, r.counters().count());
Assertions.assertEquals(1, sum(r, "test"));
c.record(TimeUnit.MILLISECONDS.toNanos(4221));
Assertions.assertEquals(2, r.counters().count());
Assertions.assertEquals(2, sum(r, "test"));
c.record(TimeUnit.MILLISECONDS.toNanos(4221));
Assertions.assertEquals(2, r.counters().count());
Assertions.assertEquals(3, sum(r, "test"));
}
代码示例来源: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 correctTypeForCountersStream() {
Registry r = newRegistry(5, false);
r.counter("a").increment();
r.counter("b").increment();
Assertions.assertEquals(2, r.counters().count());
Assertions.assertEquals(2, r.stream().filter(m -> m instanceof Counter).count());
}
代码示例来源:origin: Netflix/spectator
@Test
public void endpointUnknownIfNotSet() {
Registry registry = new DefaultRegistry();
IpcLogger logger = new IpcLogger(registry, clock, LoggerFactory.getLogger(getClass()));
logger.createServerEntry()
.withOwner("test")
.markStart()
.markEnd()
.log();
registry.counters().forEach(c -> {
Assertions.assertEquals("unknown", Utils.getTagValue(c.id(), "ipc.endpoint"));
});
}
}
代码示例来源:origin: Netflix/spectator
@Test
public void counters() {
Registry r = newRegistry(true, 10000);
r.counter("foo").increment();
r.counter("foo", "a", "1", "b", "2").increment();
r.counter("foo", "a", "1", "b", "3").increment(13L);
r.counter("foo", "a", "1", "b", "2").increment();
r.counter("bar", "a", "1", "b", "2").increment();
Assertions.assertEquals(4, r.counters().count());
final LongSummaryStatistics summary = r.counters()
.filter(Functions.nameEquals("foo"))
.collect(Collectors.summarizingLong(Counter::count));
Assertions.assertEquals(3L, summary.getCount());
Assertions.assertEquals(16L, summary.getSum());
Assertions.assertEquals(13L, summary.getMax());
}
内容来源于网络,如有侵权,请联系作者删除!