public Counter apply(MonitorConfig config) { return new BasicCounter(config); } }
public void increment(String value) { counters.computeIfAbsent(value, v -> { MonitorConfig c = baseConfig.withAdditionalTag(new com.netflix.servo.tag.BasicTag("c", v)); return new BasicCounter(c); }).increment(); }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof BasicCounter)) { return false; } BasicCounter m = (BasicCounter) obj; return config.equals(m.getConfig()) && count.get() == m.count.get(); }
@Test public void testEqualsPolicy() throws Exception { BasicCounter other = new BasicCounter( MonitorConfig.builder("name").withPublishingPolicy(OtherPolicy.INSTANCE).build()); BasicCounter dflt = newInstance("name"); assertNotEquals(other, dflt); assertNotEquals(other.hashCode(), dflt.hashCode()); } }
private void incrementStateCounter(PassportState state) { switch (state) { case IN_REQ_HEADERS_RECEIVED: IN_REQ_HEADERS_RECEIVED_CNT.increment(); break; case IN_REQ_LAST_CONTENT_RECEIVED: IN_REQ_LAST_CONTENT_RECEIVED_CNT.increment(); break; case OUT_REQ_HEADERS_SENT: OUT_REQ_HEADERS_SENT_CNT.increment(); break; case OUT_REQ_LAST_CONTENT_SENT: OUT_REQ_LAST_CONTENT_SENT_CNT.increment(); break; case IN_RESP_HEADERS_RECEIVED: IN_RESP_HEADERS_RECEIVED_CNT.increment(); break; case IN_RESP_LAST_CONTENT_RECEIVED: IN_RESP_LAST_CONTENT_RECEIVED_CNT.increment(); break; case OUT_RESP_HEADERS_SENT: OUT_RESP_HEADERS_SENT_CNT.increment(); break; case OUT_RESP_LAST_CONTENT_SENT: OUT_RESP_LAST_CONTENT_SENT_CNT.increment(); break; } } }
@Test public void testExpiration() { BasicCounter c1 = new BasicCounter(MonitorConfig.builder("c1").build()); BasicCounter c2 = new BasicCounter(MonitorConfig.builder("c2").build()); BasicCounter c3 = new BasicCounter(MonitorConfig.builder("c3").build()); ManualClock manualClock = new ManualClock(0); c1.increment(); Metric m1 = new Metric(c1.getConfig(), manualClock.now(), c1.getValue(0)); Metric m2 = new Metric(c2.getConfig(), manualClock.now(), c2.getValue()); toRateMetricTransform.update(UnmodifiableList.of(m2)); assertEquals(NormalizationTransform.HEARTBEAT_EXCEEDED.getValue(0).longValue(), 0); Metric m3 = new Metric(c3.getConfig(), manualClock.now(), c3.getValue()); toRateMetricTransform.update(UnmodifiableList.of(m3)); assertEquals(NormalizationTransform.HEARTBEAT_EXCEEDED.getValue(0).longValue(), 1);
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt == MaxInboundConnectionsHandler.CONNECTION_THROTTLED_EVENT) { connectionThrottled.increment(); } else if (evt instanceof IdleStateEvent) { connectionIdleTimeout.increment(); } super.userEventTriggered(ctx, evt); } }
private Counter getOrCreateCounter(String exceptionName) { Counter counter = exceptionCounters.get(exceptionName); if (counter == null) { counter = new BasicCounter(MonitorConfig.builder(name).withTag("id", exceptionName).build()); if (exceptionCounters.putIfAbsent(exceptionName, counter) == null) { DefaultMonitorRegistry.getInstance().register(counter); } else { counter = exceptionCounters.get(exceptionName); } } return counter; }
@Test public void testUnregisteredBasicCounterIncrement() { BasicCounter c = new BasicCounter(CONFIG); c.increment(); assertEquals(1, registry.counters().count()); assertEquals(1, registry.counter("test").count()); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { try { super.channelInactive(ctx); } finally { currentConnections.decrementAndGet(); connectionClosed.increment(); } }
@Test public void testDefaultPolicy() throws Exception { assertEquals( newInstance("A").getConfig().getPublishingPolicy(), DefaultPublishingPolicy.getInstance()); }
private BasicCounter getCounter(String name) { BasicCounter counter = map.get(name); if (counter == null) { synchronized (lock) { counter = map.get(name); if (counter != null) { return counter; } List<Tag> tags = new ArrayList<Tag>(2); tags.add(InjectableTag.HOSTNAME); tags.add(InjectableTag.IP); counter = new BasicCounter(MonitorConfig.builder(name).withTags(tags).build()); map.putIfAbsent(name, counter); DefaultMonitorRegistry.getInstance().register(counter); } } return counter; } }
@Test public void testBasicCounterIncrementAmount() { BasicCounter c = new BasicCounter(CONFIG); register(c); c.increment(42); assertEquals(42, registry.counter(ID).count()); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { connectionErrors.increment(); if (LOG.isInfoEnabled()) { LOG.info("Connection error caught. " + String.valueOf(cause), cause); } super.exceptionCaught(ctx, cause); }
@Test public void testHasCounterTag() throws Exception { Tag type = newInstance("foo").getConfig().getTags().getTag(DataSourceType.KEY); assertEquals(type.getValue(), "COUNTER"); }
/** * Create a new counter instance. */ public static Counter newCounter(String name) { return new BasicCounter(MonitorConfig.builder(name).build()); }
@Test public void testBasicCounterIncrement() { BasicCounter c = new BasicCounter(CONFIG); register(c); c.increment(); assertEquals(1, registry.counter(ID).count()); }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { currentConnections.incrementAndGet(); totalConnections.increment(); ctx.channel().attr(ATTR_CURRENT_CONNS).set(currentConnections); super.channelActive(ctx); }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof BasicCounter)) { return false; } BasicCounter m = (BasicCounter) obj; return config.equals(m.getConfig()) && count.get() == m.count.get(); }