public Timer apply(MonitorConfig config) { return new BasicTimer(config, unit); } }
public void cleanIdle(long delayMs) { Stopwatch start = executionTimeStats.start(); try { apacheHttpClient.getClientHandler().getHttpClient() .getConnectionManager() .closeIdleConnections(delayMs, TimeUnit.SECONDS); } catch (Throwable e) { logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
/** * Get the total time for all updates. */ public Double getTotalTime() { return getTotal(0); }
@Test public void testUnregisteredBasicTimerIncrement() { BasicTimer t = new BasicTimer(CONFIG); t.record(42, TimeUnit.MILLISECONDS); Id id = registry.createId("test") .withTag("unit", "MILLISECONDS"); assertEquals(3, registry.counters().count()); assertEquals(0, registry.timers().count()); assertEquals(1, registry.gauges().count()); assertEquals(0, registry.distributionSummaries().count()); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).count()); assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).count()); assertEquals(42.0, registry.maxGauge(id.withTag(Statistic.max)).value()); }
/** * {@inheritDoc} */ @Override public void record(long duration, TimeUnit unit) { recordNanos(unit.toNanos(duration)); }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof BasicTimer)) { return false; } BasicTimer m = (BasicTimer) obj; return config.equals(m.getConfig()) && totalTime.equals(m.totalTime) && count.equals(m.count) && totalOfSquares.equals(m.totalOfSquares) && max.equals(m.max); }
@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); }
/** * {@inheritDoc} */ @Override @Deprecated public void record(long duration) { long nanos = timeUnit.toNanos(duration); recordNanos(nanos); }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof BasicTimer)) { return false; } BasicTimer m = (BasicTimer) obj; return config.equals(m.getConfig()) && totalTime.equals(m.totalTime) && count.equals(m.count) && totalOfSquares.equals(m.totalOfSquares) && max.equals(m.max); }
private BasicTimer newTimer(ConfigUnit configUnit) { return new BasicTimer(configUnit.config, configUnit.unit); }
@Override public void run() { Stopwatch start = executionTimeStats.start(); try { HttpClientConnectionManager cm = (HttpClientConnectionManager) apacheHttpClient .getConfiguration() .getProperty(ApacheClientProperties.CONNECTION_MANAGER); cm.closeIdleConnections(connectionIdleTimeout, TimeUnit.SECONDS); } catch (Throwable e) { s_logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
@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); }
/** * {@inheritDoc} */ @Override public Long getValue(int pollerIndex) { final long cnt = count.getCurrentCount(pollerIndex); final long value = (long) (getTotal(pollerIndex) / cnt); return (cnt == 0) ? 0L : value; }
/** * {@inheritDoc} */ @Override public void record(long duration, TimeUnit unit) { recordNanos(unit.toNanos(duration)); }
/** * Create a new timer with only the name specified. */ public static Timer newTimer(String name, TimeUnit unit) { return new BasicTimer(MonitorConfig.builder(name).build(), unit); }
@Override public Message get(String messageId) { Stopwatch sw = monitor.get.start(); try { return execute("get", messageStoreKey, () -> { String json = quorumConn.hget(messageStoreKey, messageId); if(json == null){ if (logger.isDebugEnabled()) { logger.debug("Cannot get the message payload " + messageId); } return null; } Message msg = om.readValue(json, Message.class); return msg; }); } finally { sw.stop(); } }
/** * Get the total time for all updates. */ public Double getTotalTime() { return getTotal(0); }
/** * {@inheritDoc} */ @Override @Deprecated public void record(long duration) { long nanos = timeUnit.toNanos(duration); recordNanos(nanos); }
@Test public void testUnregisteredBasicTimer() { BasicTimer t = new BasicTimer(CONFIG); assertEquals(0, registry.timers().count()); }
@Override public List<Message> peek(final int messageCount) { Stopwatch sw = monitor.peek.start(); try { Set<String> ids = peekIds(0, messageCount); if (ids == null) { return Collections.emptyList(); } List<Message> msgs = execute("peek", messageStoreKey, () -> { List<Message> messages = new LinkedList<Message>(); for (String id : ids) { String json = nonQuorumConn.hget(messageStoreKey, id); Message message = om.readValue(json, Message.class); messages.add(message); } return messages; }); return msgs; } finally { sw.stop(); } }