@Test public void testBasic() throws Exception { MonitorRegistry registry = new BasicMonitorRegistry(); registry.registerObject(new BasicCounter("foo")); MetricPoller poller = new MonitorRegistryMetricPoller(registry); Metric metric = poller.poll(MATCH_ALL).get(0); TagList tags = BasicTagList.copyOf( new BasicTag("MonitorId", "foo"), new BasicTag("ClassName", "com.netflix.servo.util.BasicCounter"), DataSourceType.COUNTER); assertEquals(metric.getConfig(), new MetricConfig("Count", tags)); }
private void refreshMonitorCache(MetricFilter filter) { final long age = System.currentTimeMillis() - cacheLastUpdateTime.get(); if (age > cacheTTL) { List<Monitor<?>> monitors = Lists.newArrayList(); for (Monitor<?> monitor : registry.getRegisteredMonitors()) { try { getMonitors(monitors, filter, monitor); } catch (Exception e) { LOGGER.warn("failed to get monitors for composite " + monitor.getConfig(), e); } } cacheLastUpdateTime.set(System.currentTimeMillis()); cachedMonitors.set(monitors); LOGGER.debug( "cache refreshed, {} monitors matched filter, previous age {} seconds", monitors.size(), age / 1000); } else { LOGGER.debug( "cache age of {} seconds is within ttl of {} seconds", age / 1000, cacheTTL / 1000); } }