@Test public void testNotifications() { uaaMetricsEmitter.enableNotification(); emitter.sendNotification(new Notification("/api", 45L, 0)); Mockito.verify(statsDClient).time("requests.api.latency", 45L); }
public void sendLiveStat(String groupName, Counter counter, long value) { if (client != null) { if (log.isTraceEnabled()) { log.trace("Looking for aspect matching " + groupName + " / " + counter.getName()); } CounterToStatsDConfiguration.StatsDAspect aspect = config.getAspect(CounterToStatsDConfiguration.StatsDOutputType.LIVE, groupName, counter); if (aspect != null) { log.trace("Found aspect " + aspect); String fullName = aspect.getFullName(counter.getName()); log.trace("Sending " + aspect.getType() + '(' + fullName + " -> " + counter.getValue() + ')'); switch (aspect.getType()) { case GAUGE: client.gauge(fullName, value); break; case COUNTER: client.count(fullName, value); break; default: client.time(fullName, value); } } } }
public void sendFinalStats(Counters counters) { if (client != null) { for (CounterGroup group : counters) { for (Counter counter : group) { if (log.isTraceEnabled()) { log.trace("Looking for aspect matching " + group.getName() + " / " + counter.getName()); } CounterToStatsDConfiguration.StatsDAspect aspect = config.getAspect(CounterToStatsDConfiguration.StatsDOutputType.FINAL, group, counter); if (aspect != null) { String fullName = aspect.getFullName(counter.getName()); if (log.isTraceEnabled()) { log.trace("Sending " + aspect.getType() + '(' + fullName + " -> " + counter.getValue() + ')'); } switch (aspect.getType()) { case GAUGE: client.gauge(fullName, counter.getValue()); break; case COUNTER: client.count(fullName, counter.getValue()); break; default: client.time(fullName, counter.getValue()); } } } } } }
@Override public void updateImpl(List<Metric> metrics) { // The statsd client doesn't do any checks on the underlying socket's state // and the socket connects only once, so we cannot trust the socket to stay // open over a period of time. If this is changed/fixed we could reuse the // client but until then it cannot be safely reused. StatsDClient statsd = createClient(); LOGGER.debug("sending data"); try { for (Metric metric : metrics) { String aspect = namingConvention.getName(metric); if (metric.getConfig().getTags().getTag(DataSourceType.COUNTER.getValue()) != null) { statsd.count(aspect, metric.getNumberValue().longValue()); } else if (metric.hasNumberValue()) { statsd.gauge(aspect, metric.getNumberValue().longValue()); } else { statsd.set(aspect, metric.getValue().toString()); } statsd.time(aspect, metric.getTimestamp() / 1000); } } finally { statsd.stop(); } }