com.netflix.spectator.api.Counter类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(191)

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

Counter介绍

[英]Measures the rate of change based on calls to increment.
[中]根据对增量的调用测量更改速率。

代码示例

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

/**
 * Request is replayable on a different origin IFF
 *   A) we have not started to send response back to the client  AND
 *   B) we have not lost any of its body chunks
 */
protected boolean isRequestReplayable() {
  if (startedSendingResponseToClient) {
    NO_RETRY_RESP_STARTED.increment();
    return false;
  }
  if (proxiedRequestWithoutBuffering) {
    NO_RETRY_INCOMPLETE_BODY.increment();
    return false;
  }
  return true;
}

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

@Test
public void testDynamicCounterIncrement() {
 DynamicCounter.increment(CONFIG);
 assertEquals(1, registry.counter(ID).count());
}

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

@Override public Id id() {
 return get().id();
}

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

@Test
public void testIncrement() {
 Counter c = new DefaultCounter(clock, NoopId.INSTANCE);
 c.increment();
 Assertions.assertEquals(c.count(), 1L);
 c.increment();
 c.increment();
 Assertions.assertEquals(c.count(), 3L);
}

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

@Test
public void testGet() {
 Registry r = newRegistry(5, true);
 Counter c = r.counter(r.createId("foo"));
 c.increment(42);
 Meter m = r.get(c.id());
 Assertions.assertEquals(c.measure().iterator().next(), m.measure().iterator().next());
}

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

@Test
public void testDynamicTimerRecordSeconds() {
 DynamicTimer.record(CONFIG, 42);
 Id id = ID.withTag("unit", "MILLISECONDS");
 assertEquals(1, registry.counter(id.withTag(Statistic.count)).count());
 assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12);
 assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12);
 assertEquals(42, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12);
}

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

@Test
public void testAddNaN() {
 Counter c = new DefaultCounter(clock, NoopId.INSTANCE);
 c.add(1.0);
 c.add(Double.NaN);
 Assertions.assertEquals(c.actualCount(), 1.0, 1e-12);
}

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

@Override public double actualCount() {
 return get().actualCount();
}

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

@Override public void add(double amount) {
 get().add(amount);
}

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

@Test
public void testInit() {
 Counter c = newCounter("foo");
 Assertions.assertEquals(c.count(), 0L);
 c.increment();
 Assertions.assertEquals(c.count(), 1L);
}

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

private void doMeasurementTest(Counter c, int expectedValue, long expectedTime) {
 c.increment(expectedValue);
 clock.setWallTime(expectedTime);
 List<Measurement> measurements = Utils.toList(c.measure());
 Assertions.assertEquals(1, measurements.size());
 Measurement m = measurements.get(0);
 Assertions.assertEquals(c.id(), m.id());
 Assertions.assertEquals(expectedTime, m.timestamp());
 Assertions.assertEquals(expectedValue, m.value(), 0.1e-12);
}

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

@Test
public void testBasicTimerRecordSeconds() {
 BasicTimer d = new BasicTimer(CONFIG, TimeUnit.SECONDS);
 register(d);
 d.record(42, TimeUnit.NANOSECONDS);
 Id id = ID.withTag("unit", "SECONDS");
 assertEquals(1, registry.counter(id.withTag(Statistic.count)).count());
 assertEquals(42e-9, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12);
 assertEquals(42e-9 * 42e-9, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12);
 assertEquals(42e-9, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12);
}

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

@Test
public void counterAdd() {
 Counter c = registry.counter("foo");
 Assertions.assertEquals(0.0, c.actualCount(), 1e-12);
 c.add(1.5);
 Assertions.assertEquals(1.5, c.actualCount(), 1e-12);
}

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

@Test
public void testDoubleCounterAdd() {
 DoubleCounter c = new DoubleCounter(CONFIG, Clock.WALL);
 register(c);
 c.increment(0.2);
 assertEquals(0.2, registry.counter(ID).actualCount());
}

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

/**
 * Update the counter by {@code amount}.
 *
 * @param amount
 *     Amount to add to the counter.
 */
default void increment(long amount) {
 add(amount);
}

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

protected static void incrementExceptionCounter(Throwable throwable, String handler) {
  registry.counter("server.connection.exception",
      "handler", handler,
      "id", throwable.getClass().getSimpleName())
      .increment();
}

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

@Test
public void testIncrement() {
 Registry r = new DefaultRegistry(clock);
 Id id = r.createId("test");
 Counter c = IntervalCounter.get(r, id);
 Assertions.assertEquals(0, c.count());
 c.increment();
 Assertions.assertEquals(1, c.count());
 c.increment(41);
 Assertions.assertEquals(42, c.count());
}

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

@Test
public void testMeasure() {
 Counter c = new DefaultCounter(clock, NoopId.INSTANCE);
 c.increment(42);
 clock.setWallTime(3712345L);
 for (Measurement m : c.measure()) {
  Assertions.assertEquals(m.id(), c.id());
  Assertions.assertEquals(m.timestamp(), 3712345L);
  Assertions.assertEquals(m.value(), 42.0, 0.1e-12);
 }
}

代码示例来源: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 testBasicTimerRecordMillis() {
 BasicTimer d = new BasicTimer(CONFIG);
 register(d);
 d.record(42, TimeUnit.NANOSECONDS);
 Id id = ID.withTag("unit", "MILLISECONDS");
 assertEquals(1, registry.counter(id.withTag(Statistic.count)).count());
 assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12);
 assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12);
 assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12);
}

相关文章