public DurationThresholdTracker(MetricId id, SemanticMetricRegistry metricRegistry, Integer threshold) { final MetricId thresholdId = id.tagged("what", ENDPOINT_REQUEST_DURATION_THRESHOLD_RATE.tag()) .tagged("threshold", threshold.toString()); this.durationThresholdMeter = metricRegistry.meter(thresholdId); this.threshold = threshold; }
public SemanticMetricsFactory(final SemanticMetricRegistry metricRegistry, Predicate<What> enabledMetrics, Set<Integer> precreateCodes, DurationThresholdConfig durationThresholdConfig) { this.metricRegistry = metricRegistry; this.metricId = MetricId.build(); this.enabledMetrics = enabledMetrics; this.precreateCodes = precreateCodes; this.durationThresholdConfig = durationThresholdConfig; }
baseMetricId.tagged( "what", "memcache-results", "component", "memcache-client"); final MetricId meterId = id.tagged("unit", "operations"); MetricId getId = id.tagged("operation", "get"); this.gets = registry.timer(getId); MetricId getMetersId = MetricId.join(getId, meterId); this.getHits = registry.meter(getMetersId.tagged("result", "success", "cache-result", "hit")); this.getMisses = registry.meter(getMetersId.tagged("result", "success", "cache-result", "miss")); this.getFailures = registry.meter(getMetersId.tagged("result", "failure")); registry.register(getId.tagged("what", "memcache-hit-ratio", "unit", "%"), hitRatio); MetricId setId = id.tagged("operation", "set"); this.sets = registry.timer(setId); MetricId setMetersId = MetricId.join(setId, meterId); this.setSuccesses = registry.meter(setMetersId.tagged("result", "success")); this.setFailures = registry.meter(setMetersId.tagged("result", "failure")); MetricId multigetId = id.tagged("operation", "multiget"); this.multigets = registry.timer(multigetId); MetricId multigetMetersId = MetricId.join(multigetId, meterId); this.multigetSuccesses = registry.meter(multigetMetersId.tagged("result", "success")); this.multigetFailures = registry.meter(multigetMetersId.tagged("result", "failure"));
/** * Join the specified set of metric names. * * @param parts Multiple metric names to join using the separator. * @return A newly created metric name which has the name of the specified parts and includes * all tags of all child metric names. **/ public static MetricId join(MetricId... parts) { final StringBuilder nameBuilder = new StringBuilder(); final Map<String, String> tags = new HashMap<String, String>(); boolean first = true; for (MetricId part : parts) { final String name = part.getKey(); if (name != null && !name.isEmpty()) { if (first) { first = false; } else { nameBuilder.append(SEPARATOR); } nameBuilder.append(name); } if (!part.getTags().isEmpty()) { tags.putAll(part.getTags()); } } return new MetricId(nameBuilder.toString(), tags); }
@Override public int compareTo(MetricId o) { if (o == null) { return -1; } // fast path, same object, or same content. if (this == o) { return 0; } // fast path, different hashes. final int h = Integer.compare(hash, o.hash); if (h != 0) { return h; } final int k = compareKey(key, o.getKey()); if (k != 0) { return k; } return compareTags(tags.entrySet(), o.tags.entrySet()); }
public static Map<String, String> buildAttributes(MetricId id, String type) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.putAll(id.getTags()); builder.put("metric_type", type); return builder.build(); }
private String joinKeys(MetricId... parts) { final StringBuilder key = new StringBuilder(); for (final MetricId part : parts) { final String name = part.getKey(); if (name != null && !name.isEmpty()) { if (key.length() > 0) { key.append('.'); } key.append(name); } } return key.toString(); }
protected void registerAll(final MetricId prefix, final SemanticMetricSet metrics) throws IllegalArgumentException { for (final Map.Entry<MetricId, Metric> entry : metrics.getMetrics().entrySet()) { if (entry.getValue() instanceof SemanticMetricSet) { registerAll(MetricId.join(prefix, entry.getKey()), (SemanticMetricSet) entry.getValue()); } else { register(MetricId.join(prefix, entry.getKey()), entry.getValue()); } } }
/** * Build the MetricName that is this with another path appended to it. * <p> * The new MetricName inherits the tags of this one. * * @param part The extra path element to add to the new metric. * @return A new metric name relative to the original by the path specified in p. */ public MetricId resolve(final String part) { return new MetricId(extendKey(part), tags); }
/** * Build a new metric name using the specific path components. * * @param parts Path of the new metric name. * @return A newly created metric name with the specified path. **/ public static MetricId build(final String... parts) { if (parts == null || parts.length == 0) { return MetricId.EMPTY; } if (parts.length == 1) { return new MetricId(parts[0], EMPTY_TAGS); } return new MetricId(key(parts), EMPTY_TAGS); }
/** * Add tags to a metric name and return the newly created MetricName. * * @param add Tags to add. * @return A newly created metric name with the specified tags associated with it. */ public MetricId tagged(Map<String, String> add) { final TreeMap<String, String> tags = new TreeMap<>(this.tags); tags.putAll(add); return new MetricId(key, tags); }
@Override public ServiceMetrics createForService(String serviceName) { final MetricId id = metricId.tagged("service", serviceName); return new SemanticServiceMetrics(metricRegistry, id, precreateCodes, enabledMetrics, durationThresholdConfig); } }
/** * Wraps an {@link java.util.concurrent.ScheduledExecutorService} uses an auto-generated default * name. * * @param delegate {@link java.util.concurrent.ScheduledExecutorService} to wrap. * @param registry {@link com.codahale.metrics.MetricRegistry} that will contain the metrics. */ public InstrumentedScheduledExecutorService( ScheduledExecutorService delegate, SemanticMetricRegistry registry ) { this(delegate, registry, new MetricId().tagged("executor", "scheduled-executor-" + NAME_COUNTER.incrementAndGet())); }
/** * Key prefix to apply to all reported metrics. * * @return this builder */ public Builder prefix(String prefix) { this.prefix = MetricId.build(prefix); return this; }
private BatchBuilder createBuilder( final List<Batch.Point> points, final long timestamp, final MetricId id, final String metricType ) { final String key = joinKeys(prefix, id); final String unit = getUnit(id.getTags()); return new BatchBuilder(points, timestamp, key, id.getTags(), unit, metricType); }
public SemanticAggregatorTimer( final MetricId id, final List<String> shardKey, final Remote remote, final TimeSource timeSource) { this.key = id.getKey(); this.remote = remote; this.timeSource = timeSource; allAttributes = SemanticAggregator.buildAttributes(id, "timer"); shard = Sharder.buildShardKey(shardKey, allAttributes); }