本文整理了Java中com.netflix.spectator.api.Gauge
类的一些代码示例,展示了Gauge
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Gauge
类的具体详情如下:
包路径:com.netflix.spectator.api.Gauge
类名称:Gauge
[英]A meter with a single value that can only be sampled at a point in time. A typical example is a queue size.
[中]只有一个值的仪表,只能在某个时间点取样。一个典型的例子是队列大小。
代码示例来源:origin: Netflix/zuul
private void incrementCurrentRequestsInFlight(ChannelHandlerContext ctx)
{
currentRequestsGauge.set(currentRequests.incrementAndGet());
ctx.channel().attr(ATTR_REQ_INFLIGHT).set(INFLIGHT);
}
代码示例来源:origin: Netflix/Priam
public void incCassStop() {
cassStop.set(cassStop.value() + 1);
}
代码示例来源:origin: Netflix/servo
@Override public Id id() {
return get().id();
}
代码示例来源:origin: Netflix/servo
@Override public double value() {
return get().value();
}
}
代码示例来源:origin: Netflix/spectator
@Test
public void testIncrement() {
String[] tagValue = new String[] { "default" };
Gauge g = factory.gauge(factory.createId("testIncrement",
Collections.singleton(new TestTagFactory(tagValue))));
Assertions.assertEquals(Double.NaN, g.value(), 1e-12);
Assertions.assertEquals("testIncrement:tag=default", g.id().toString());
g.set(1);
Assertions.assertEquals(1.0, g.value(), 1e-12);
g.set(3);
Assertions.assertEquals(3.0, g.value(), 1e-12);
tagValue[0] = "value2";
Assertions.assertEquals("testIncrement:tag=value2", g.id().toString());
g.set(1);
Assertions.assertEquals(1.0, g.value(), 1e-12);
tagValue[0] = "default";
Assertions.assertEquals("testIncrement:tag=default", g.id().toString());
g.set(4);
Assertions.assertEquals(4.0, g.value(), 1e-12);
}
代码示例来源:origin: Netflix/spectator
@Test
public void expiration() {
final long initTime = TimeUnit.MINUTES.toMillis(30);
final long fifteenMinutes = TimeUnit.MINUTES.toMillis(15);
// Not expired on init, wait for activity to mark as active
clock.setWallTime(initTime);
Gauge g = newGauge("foo");
Assertions.assertFalse(g.hasExpired());
g.set(42.0);
Assertions.assertFalse(g.hasExpired());
Assertions.assertEquals(g.value(), 42.0, 1e-12);
// Expires with inactivity
clock.setWallTime(initTime + fifteenMinutes);
Assertions.assertFalse(g.hasExpired());
// Expires with inactivity
clock.setWallTime(initTime + fifteenMinutes + 1);
Assertions.assertEquals(g.value(), Double.NaN, 1e-12);
Assertions.assertTrue(g.hasExpired());
// Activity brings it back
g.set(1.0);
Assertions.assertEquals(g.value(), 1.0, 1e-12);
Assertions.assertFalse(g.hasExpired());
}
代码示例来源:origin: Netflix/spectator
private void doMeasurementTest(Gauge g, int expectedValue, long expectedTime) {
g.set(expectedValue);
clock.setWallTime(expectedTime);
List<Measurement> measurements = Utils.toList(g.measure());
Assertions.assertEquals(1, measurements.size());
Measurement m = measurements.get(0);
Assertions.assertEquals(g.id(), m.id());
Assertions.assertEquals(expectedTime, m.timestamp());
Assertions.assertEquals(expectedValue, m.value(), 0.1e-12);
}
代码示例来源:origin: Netflix/spectator
@Test
public void measure() {
final ServoRegistry r = new ServoRegistry(clock);
Gauge g = r.gauge(r.createId("foo"));
g.set(1.0);
Iterator<Measurement> ms = g.measure().iterator();
Assertions.assertTrue(ms.hasNext());
Measurement m = ms.next();
Assertions.assertFalse(ms.hasNext());
Assertions.assertEquals("foo", m.id().name());
Assertions.assertEquals(1.0, 1.0, 1e-12);
}
代码示例来源:origin: Netflix/spectator
@Override protected void update(Registry registry) {
double sum = Double.NaN;
Iterator<ValueEntry<T>> iter = pairs.iterator();
while (iter.hasNext()) {
final ValueEntry<T> pair = iter.next();
final T obj = pair.ref.get();
if (obj != null) {
double v = pair.f.applyAsDouble(obj);
if (!Double.isNaN(v)) {
sum = Double.isNaN(sum) ? v : sum + v;
}
} else {
iter.remove();
}
}
if (pairs.isEmpty()) {
LOGGER.trace("gauge [{}] has expired", gauge.id());
}
LOGGER.trace("setting gauge [{}] to {}", gauge.id(), sum);
gauge.set(sum);
}
}
代码示例来源:origin: Netflix/spectator
private void assertLongTaskTimer(Registry r, Id id, long timestamp, int activeTasks, double duration) {
PolledMeter.update(r);
Gauge g = r.gauge(id.withTag(Statistic.activeTasks));
Assertions.assertEquals(timestamp, g.measure().iterator().next().timestamp());
Assertions.assertEquals(activeTasks, g.value(), 1.0e-12);
g = r.gauge(id.withTag(Statistic.duration));
Assertions.assertEquals(timestamp, g.measure().iterator().next().timestamp());
Assertions.assertEquals(duration, g.value(), 1.0e-12);
}
代码示例来源:origin: Netflix/servo
@Override public Iterable<Measurement> measure() {
return get().measure();
}
代码示例来源:origin: Netflix/servo
@Override public boolean hasExpired() {
return get().hasExpired();
}
代码示例来源:origin: Netflix/servo
@Test
public void testDynamicGauge() {
DynamicGauge.set(CONFIG, 42.0);
assertEquals(42.0, registry.gauge(ID).value(), 1e-12);
}
代码示例来源:origin: Netflix/spectator
@Test
public void gaugeMeasure() {
Gauge g = registry.gauge("foo");
g.set(42.0);
int i = 0;
for (Measurement m : g.measure()) {
++i;
Assertions.assertEquals("foo", m.id().name());
Assertions.assertEquals(42.0, m.value(), 1e-12);
}
Assertions.assertEquals(1, i);
}
代码示例来源:origin: com.netflix.spectator/spectator-api
@Override protected void update(Registry registry) {
double sum = Double.NaN;
Iterator<ValueEntry<T>> iter = pairs.iterator();
while (iter.hasNext()) {
final ValueEntry<T> pair = iter.next();
final T obj = pair.ref.get();
if (obj != null) {
double v = pair.f.applyAsDouble(obj);
if (!Double.isNaN(v)) {
sum = Double.isNaN(sum) ? v : sum + v;
}
} else {
iter.remove();
}
}
if (pairs.isEmpty()) {
LOGGER.trace("gauge [{}] has expired", gauge.id());
}
LOGGER.trace("setting gauge [{}] to {}", gauge.id(), sum);
gauge.set(sum);
}
}
代码示例来源:origin: com.netflix.servo/servo-core
@Override public Iterable<Measurement> measure() {
return get().measure();
}
代码示例来源:origin: com.netflix.servo/servo-core
@Override public boolean hasExpired() {
return get().hasExpired();
}
代码示例来源:origin: Netflix/zuul
private void decrementCurrentRequestsIfOneInflight(ChannelHandlerContext ctx)
{
if (ctx.channel().attr(ATTR_REQ_INFLIGHT).getAndRemove() != null) {
currentRequestsGauge.set(currentRequests.decrementAndGet());
}
}
}
代码示例来源:origin: Netflix/Priam
public void incCassAutoStart() {
cassAutoStart.set(cassAutoStart.value() + 1);
}
代码示例来源:origin: Netflix/servo
@Test
public void testDoubleGauge() {
DoubleGauge c = new DoubleGauge(CONFIG);
register(c);
c.set(42.0);
assertEquals(42.0, registry.gauge(ID).value(), 1e-12);
}
内容来源于网络,如有侵权,请联系作者删除!