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; } }
private void addTabularMetrics(MetricFilter filter, List<Metric> metrics, TagList tags, String attrName, CompositeData obj) { Map<String, Object> values = new HashMap<>(); // tabular composite data has a value called key and one called value values.put(obj.get("key").toString(), obj.get("value")); for (Map.Entry<String, Object> e : values.entrySet()) { final Tag compositeTag = Tags.newTag(COMPOSITE_PATH_KEY, e.getKey()); final TagList newTags = getTagListWithAdditionalTag(tags, compositeTag); if (filter.matches(MonitorConfig.builder(attrName).withTags(newTags).build())) { addMetric(metrics, attrName, newTags, e.getValue()); } } }
public MonitorConfig getMonitorConfig(final String metricName, final Tag tag, final TagList tagList) { MonitorConfig mc = monitorConfigMap.get(metricName); if (mc != null) return mc; final MonitorConfig.Builder monitorConfig = MonitorConfig.builder(metricName); if (tagList != null) monitorConfig.withTags(tagList); if (tag != null) monitorConfig.withTag(tag); mc = monitorConfig.build(); monitorConfigMap.put(metricName, mc); return mc; }
/** * 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); }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. The timer * uses a TimeUnit of milliseconds. */ public static Stopwatch start(String name, TagList list, TimeUnit unit) { final MonitorConfig config = new MonitorConfig.Builder(name).withTags(list).build(); return INSTANCE.get(config, unit).start(); }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. The timer * uses a TimeUnit of milliseconds. */ public static Stopwatch start(String name, TagList list) { final MonitorConfig config = new MonitorConfig.Builder(name).withTags(list).build(); return INSTANCE.get(config, TimeUnit.MILLISECONDS).start(); }
/** * Create a new builder initialized with the specified config. */ public Builder(MonitorConfig config) { this(config.getName()); withTags(config.getTags()); withPublishingPolicy(config.getPublishingPolicy()); }
private static MonitorConfig subId(MonitorConfig config, String sub) { String newName = config.getName() + "." + sub; return MonitorConfig.builder(newName).withTags(config.getTags()) .withPublishingPolicy(config.getPublishingPolicy()) .build(); }
/** * Returns a copy of the monitor config with additional tags. */ public MonitorConfig withAdditionalTags(TagList newTags) { return copy().withTags(newTags).build(); } }
@Test public void testHashCode() throws Exception { MonitorConfig m1 = new MonitorConfig.Builder("a").withTags(tags1).build(); MonitorConfig m2 = new MonitorConfig.Builder("a").withTags(tags2).build(); MonitorConfig m3 = new MonitorConfig.Builder("a").withTags(tags1).build(); assertTrue(m1.hashCode() == m1.hashCode()); assertTrue(m1.hashCode() != m2.hashCode()); assertTrue(m1.hashCode() == m3.hashCode()); }
/** * Returns a copy of the current MonitorConfig. */ private MonitorConfig.Builder copy() { return MonitorConfig.builder(name).withTags(tags).withPublishingPolicy(policy); }
@Test public void testAccessors() throws Exception { long now = System.currentTimeMillis(); Metric m1 = new Metric("a", tags1, now, 42); assertEquals(m1.getConfig(), new MonitorConfig.Builder("a").withTags(tags1).build()); assertEquals(m1.getTimestamp(), now); assertEquals(m1.getValue(), 42); }
/** * 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); }
/** * Creates a new instance. * * @param name name of the metric * @param tags tags associated with the metric * @param timestamp point in time when the metric value was sampled * @param value value of the metric */ public Metric(String name, TagList tags, long timestamp, Object value) { this(new MonitorConfig.Builder(name).withTags(tags).build(), timestamp, value); }
@Test public void testEquals() throws Exception { MonitorConfig m1 = new MonitorConfig.Builder("a").withTags(tags1).build(); MonitorConfig m2 = new MonitorConfig.Builder("a").withTags(tags2).build(); MonitorConfig m3 = new MonitorConfig.Builder("a").withTags(tags1).build(); assertNotNull(m1); assertFalse(m1.toString().equals(m2.toString())); assertTrue(m1.equals(m1)); assertFalse(m1.equals(m2)); assertTrue(m1.equals(m3)); }
/** * Set the gauge for a given name, tagList by a given value. */ public static void set(String name, TagList list, double value) { final MonitorConfig config = MonitorConfig.builder(name).withTags(list).build(); set(config, value); }
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; } }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }
private ServoTracer(String name) { config = MonitorConfig.builder(name).withTags(tags).build(); stopwatch = DynamicTimer.start(config, TimeUnit.MICROSECONDS); }