@Override public void notify(ZuulFilter filter, ExecutionStatus status) { DynamicCounter.increment(METRIC_PREFIX + filter.getClass().getSimpleName(), "status", status.name(), "filtertype", filter.filterType().toString()); } }
@Test public void testShouldNotThrow() throws Exception { DynamicCounter.increment("name", "", ""); } }
@Override public void notify(ZuulFilter filter, ExecutionStatus status) { DynamicCounter.increment(METRIC_PREFIX + filter.getClass().getSimpleName(), "status", status.name(), "filtertype", filter.filterType().toString()); } }
/** * Increment the counter for a given name, tagList. */ public static void increment(String name, TagList list) { final MonitorConfig config = new MonitorConfig.Builder(name).withTags(list).build(); increment(config); }
/** * Increment the counter for a given name, tagList by a given delta. */ public static void increment(String name, TagList list, long delta) { final MonitorConfig config = MonitorConfig.builder(name).withTags(list).build(); increment(config, delta); }
/** * Increment a counter specified by a name, and a sequence of (key, value) pairs. */ public static void increment(String name, String... tags) { final MonitorConfig.Builder configBuilder = MonitorConfig.builder(name); Preconditions.checkArgument(tags.length % 2 == 0, "The sequence of (key, value) pairs must have even size: one key, one value"); try { for (int i = 0; i < tags.length; i += 2) { configBuilder.withTag(tags[i], tags[i + 1]); } increment(configBuilder.build()); } catch (IllegalArgumentException e) { LOGGER.warn("Failed to get a counter to increment: {}", e.getMessage()); } }
private Object getValue(Monitor<?> monitor) { try { if (limiter != null) { final MonitorValueCallable c = new MonitorValueCallable(monitor); return limiter.callWithTimeout(c, 1, TimeUnit.SECONDS); } else { return monitor.getValue(); } } catch (TimeLimiter.UncheckedTimeoutException e) { LOGGER.warn("timeout trying to get value for {}", monitor.getConfig()); TIMEOUT_ERROR.increment(); } catch (Exception e) { LOGGER.warn("failed to get value for " + monitor.getConfig(), e); DynamicCounter.increment(GET_VALUE_ERROR, "id", e.getClass().getSimpleName()); } return null; }
private void putMetricData(List<Metric> batch) { METRICS_COUNTER.increment(batch.size()); final Stopwatch s = PUTS_TIMER.start(); try { cloudWatch.putMetricData(createPutRequest(batch)); } catch (AmazonServiceException e) { final Tag error = new BasicTag("error", e.getErrorCode()); DynamicCounter.increment(ERRORS_COUNTER_ID.withAdditionalTag(error)); LOG.error("Error while submitting data for metrics : " + batch, e); } catch (Exception e) { final Tag error = new BasicTag("error", e.getClass().getSimpleName()); DynamicCounter.increment(ERRORS_COUNTER_ID.withAdditionalTag(error)); LOG.error("Error while submitting data for metrics : " + batch, e); } catch (Error e) { final Tag error = new BasicTag("error", e.getClass().getSimpleName()); DynamicCounter.increment(ERRORS_COUNTER_ID.withAdditionalTag(error)); throw Throwables.propagate(e); } finally { s.stop(); } }
protected void logAuth(ServletRequest request) { if (serverConfig.shouldLogIdentityHeaders()) { if (request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; String clientName = getHeader(httpRequest, AbstractEurekaIdentity.AUTH_NAME_HEADER_KEY); String clientVersion = getHeader(httpRequest, AbstractEurekaIdentity.AUTH_VERSION_HEADER_KEY); DynamicCounter.increment(MonitorConfig.builder(NAME_PREFIX + clientName + "-" + clientVersion).build()); } } }
@Test public void testDynamicCounterIncrement() { DynamicCounter.increment(CONFIG); assertEquals(1, registry.counter(ID).count()); }
@Test public void testByStrings() throws Exception { clock.set(1L); DynamicCounter.increment("byName"); DynamicCounter.increment("byName"); StepCounter c = getByName("byName"); clock.set(60001L); assert c != null; assertEquals(c.getCount(0), 2L); DynamicCounter.increment("byName2", "key", "value", "key2", "value2"); DynamicCounter.increment("byName2", "key", "value", "key2", "value2"); StepCounter c2 = getByName("byName2"); clock.set(120001L); assert c2 != null; assertEquals(c2.getCount(0), 2L); }
@Test public void testExpiration() throws Exception { clock.set(0L); DynamicCounter.increment("test1", tagList); DynamicCounter.increment("test2", tagList); clock.set(500L); DynamicCounter.increment("test1", tagList); clock.set(1000L); DynamicCounter.increment("test1", tagList); clock.set(60200L); StepCounter c1 = getByName("test1"); assert c1 != null; assertEquals(c1.getCount(0), 3L); // the expiration task is not using Clock Thread.sleep(200); StepCounter c2 = getByName("test2"); assertNull(c2, "Counters not used in a while should expire"); }
@Test public void testHasRightType() throws Exception { DynamicCounter.increment("test1", tagList); StepCounter c = getByName("test1"); assert c != null; Tag type = c.getConfig().getTags().getTag(DataSourceType.KEY); assertEquals(type.getValue(), "NORMALIZED"); }
@Test public void testGetValue() throws Exception { clock.set(0L); DynamicCounter.increment("test1", tagList); StepCounter c = getByName("test1"); clock.set(60000L); assert c != null; assertEquals(c.getCount(0), 1L); c.increment(13); clock.set(120000L); assertEquals(c.getCount(0), 13L); }
private String normalizeRoutingKey(Message msg) { String routingKey = msg.getRoutingKey(); if(routingKey == null || routingKey.trim().length() == 0) { emptyRoutingKeyCount += 1; DynamicCounter.increment("emptyRoutingKeyCount"); if(log.isDebugEnabled()) { log.debug("Message {} with empty routing key", Arrays.asList(msg.getPayload())); } return EMPTY_ROUTING_KEY_REPLACEMENT; } return routingKey; }
@Override public void notify(ZuulFilter filter, ExecutionStatus status) { DynamicCounter.increment(METRIC_PREFIX + filter.getClass().getSimpleName(), "status", status.name(), "filtertype", filter.filterType().toString()); } }
/** * Increment the counter for a given name, tagList by a given delta. */ public static void increment(String name, TagList list, long delta) { final MonitorConfig config = MonitorConfig.builder(name).withTags(list).build(); increment(config, delta); }
/** * Increment the counter for a given name, tagList. */ public static void increment(String name, TagList list) { final MonitorConfig config = new MonitorConfig.Builder(name).withTags(list).build(); increment(config); }
protected void enqueue(Message message) { if (!queue4Sink.offer(message)) { droppedMessagesCount.incrementAndGet(); DynamicCounter.increment( MonitorConfig.builder(TagKey.DROPPED_COUNT) .withTag("reason", "queueFull") .withTag("sink", sinkId) .build()); } }
protected void logAuth(ServletRequest request) { if (serverConfig.shouldLogIdentityHeaders()) { if (request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; String clientName = getHeader(httpRequest, AbstractEurekaIdentity.AUTH_NAME_HEADER_KEY); String clientVersion = getHeader(httpRequest, AbstractEurekaIdentity.AUTH_VERSION_HEADER_KEY); DynamicCounter.increment(MonitorConfig.builder(NAME_PREFIX + clientName + "-" + clientVersion).build()); } } }