/** * Check if a yammer metric name is an interested metric */ public static boolean isInterested(com.yammer.metrics.core.MetricName metricName) { return isInterested(metricName.getGroup(), metricName.getName(), metricName.getType(), yammerMetricScopeToTags(metricName.getScope())); }
@Override public boolean matches(MetricName name, Metric metric) { return name.getType().equals(getType()); } };
protected String sanitizeName(MetricName name) { final StringBuilder sb = new StringBuilder() .append(name.getGroup()) .append('.') .append(name.getType()) .append('.'); if (name.hasScope()) { sb.append(name.getScope()) .append('.'); } return sb.append(name.getName()).toString(); }
protected String sanitizeName(MetricName name) { final StringBuilder sb = new StringBuilder() .append(name.getGroup()) .append('.') .append(name.getType()) .append('.'); if (name.hasScope()) { sb.append(name.getScope()) .append('.'); } return sb.append(name.getName()).toString(); }
private String sanitizeName(MetricName name) { final StringBuilder sb = new StringBuilder() .append(name.getGroup()) .append('.') .append(name.getType()) .append('.'); if (name.hasScope()) { sb.append(name.getScope()) .append('.'); } return sb.append(name.getName()).toString(); }
protected String sanitizeName(MetricName name, String... path) { final StringBuilder sb = new StringBuilder(name.getGroup()); sb.append('.'); sb.append(name.getType()).append('.'); if (name.hasScope()) { sb.append(name.getScope()).append('.'); } String[] metricParts = name.getName().split("\\["); sb.append(metricParts[0]); for (String part : path) { sb.append('.').append(part); } for (int i = 1; i < metricParts.length; i++) { sb.append('[').append(metricParts[i]); } return sb.toString(); }
/** * Returns a grouped and sorted map of all registered metrics which match then given {@link * MetricPredicate}. * * @param predicate a predicate which metrics have to match to be in the results * @return all registered metrics which match {@code predicate}, sorted by name */ public SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics(MetricPredicate predicate) { final SortedMap<String, SortedMap<MetricName, Metric>> groups = new TreeMap<String, SortedMap<MetricName, Metric>>(); for (Map.Entry<MetricName, Metric> entry : metrics.entrySet()) { final String qualifiedTypeName = entry.getKey().getGroup() + "." + entry.getKey() .getType(); if (predicate.matches(entry.getKey(), entry.getValue())) { final String scopedName; if (entry.getKey().hasScope()) { scopedName = qualifiedTypeName + "." + entry.getKey().getScope(); } else { scopedName = qualifiedTypeName; } SortedMap<MetricName, Metric> group = groups.get(scopedName); if (group == null) { group = new TreeMap<MetricName, Metric>(); groups.put(scopedName, group); } group.put(entry.getKey(), entry.getValue()); } } return Collections.unmodifiableSortedMap(groups); }
protected String sanitizeName(MetricName name) { if (name == null) { return ""; } final String qualifiedTypeName = name.getGroup() + "." + name.getType() + "." + name.getName(); final String metricName = name.hasScope() ? qualifiedTypeName + '.' + name.getScope() : qualifiedTypeName; final StringBuilder sb = new StringBuilder(); for (int i = 0; i < metricName.length(); i++) { final char p = metricName.charAt(i); if (!(p >= 'A' && p <= 'Z') && !(p >= 'a' && p <= 'z') && !(p >= '0' && p <= '9') && (p != '_') && (p != '-') && (p != '.') && (p != '\0')) { sb.append('_'); } else { sb.append(p); } } return sb.toString(); } }
@Override public void processGauge(MetricName name, Gauge gauge, Object context) throws Exception { try { gauge.value(); } catch (NoSuchElementException ex) { throw new InvalidGaugeException(String.format("%s.%s.%s", name.getGroup(), name.getType(), name.getName()), ex); } } }
public static String qualifyMetricName(MetricName mn) { String qualifiedTypeName = mn.getGroup() + "." + mn.getType(); if (mn.hasScope()) { qualifiedTypeName += "." + mn.getScope(); } qualifiedTypeName += "." + mn.getName(); return qualifiedTypeName; }
public String qualifyMetricName(MetricName mn) { String qualifiedTypeName = mn.getGroup() + "." + mn.getType(); if (mn.hasScope()) { qualifiedTypeName += "." + mn.getScope(); } qualifiedTypeName += "." + mn.getName(); return qualifiedTypeName; }
private MeasurementV1 createMeasurement(com.yammer.metrics.core.MetricName name, Long timestamp, Map<String, String> tags, Map<String, Double> fields) { MeasurementV1 measurement = new MeasurementV1(); measurement.setTimestamp(timestamp); measurement.setName(name.getName()); measurement.setTags(new HashMap<String, String>(tags)); if (name.getGroup() != null && !name.getGroup().isEmpty()) measurement.getTags().put("group", name.getGroup()); if (name.getType() != null && !name.getType().isEmpty()) measurement.getTags().put("type", name.getType()); if (name.getScope() != null && !name.getScope().isEmpty()) { if (name.getGroup() != null && name.getGroup().startsWith("kafka.") && name.getScope().contains(".")) { /* * Decompose kafka metrics tags which uses yammer metrics Scope to "squash" all tags together */ String[] scope = name.getScope().split("\\."); for (int s = 0; s < scope.length; s += 2) { measurement.getTags().put(scope[s], scope[s + 1]); } } else { measurement.getTags().put("scope", name.getScope()); } } measurement.setFields(new HashMap<String, Double>(fields)); return measurement; }
/** * Check if a yammer metric name is an interested metric */ public static boolean isInterested(com.yammer.metrics.core.MetricName metricName) { return isInterested(metricName.getGroup(), metricName.getName(), metricName.getType(), yammerMetricScopeToTags(metricName.getScope())); }
private void copyIndexingMetricsToCounters(Context context) { final String COUNTER_GROUP = "HBase Indexer Metrics"; SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics( new IndexerMetricsUtil.IndexerMetricPredicate()); for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) { SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue(); for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) { MetricName metricName = metricEntry.getKey(); Metric metric = metricEntry.getValue(); String counterName = metricName.getType() + ": " + metricName.getName(); if (metric instanceof Counter) { Counter counter = (Counter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(counter.count()); } else if (metric instanceof Meter) { Meter meter = (Meter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(meter.count()); } else if (metric instanceof Timer) { Timer timer = (Timer) metric; context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum()); } } } }
private void copyIndexingMetricsToCounters(Context context) { final String COUNTER_GROUP = "HBase Indexer Metrics"; SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics( new IndexerMetricsUtil.IndexerMetricPredicate()); for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) { SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue(); for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) { MetricName metricName = metricEntry.getKey(); Metric metric = metricEntry.getValue(); String counterName = metricName.getType() + ": " + metricName.getName(); if (metric instanceof Counter) { Counter counter = (Counter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(counter.count()); } else if (metric instanceof Meter) { Meter meter = (Meter) metric; context.getCounter(COUNTER_GROUP, counterName).increment(meter.count()); } else if (metric instanceof Timer) { Timer timer = (Timer) metric; context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum()); } } } }
/** * This method transforms the MetricName into a new MetricName that represents a DeltaCounter. * The transformation includes prepending a "\u2206" character to the name. * * @param metricName The MetricName which needs to be transformed * @return The new MetricName representing a DeltaCounter */ public static MetricName getDeltaCounterMetricName(MetricName metricName) { if (isDelta(metricName.getName())) { return metricName; } else { String name = getDeltaCounterName(metricName.getName()); return new MetricName(metricName.getGroup(), metricName.getType(), name, metricName.getScope()); } }
/** * This method transforms the MetricName into a new MetricName that represents a DeltaCounter. * The transformation includes prepending a "\u2206" character to the name. * * @param metricName The MetricName which needs to be transformed * @return The new MetricName representing a DeltaCounter */ public static MetricName getDeltaCounterMetricName(MetricName metricName) { if (isDelta(metricName.getName())) { return metricName; } else { String name = getDeltaCounterName(metricName.getName()); return new MetricName(metricName.getGroup(), metricName.getType(), name, metricName.getScope()); } }
@Override public void processTimer(MetricName name, Timer timer, Void context) throws Exception { MetricName samplingName, rateName; if (name instanceof TaggedMetricName) { TaggedMetricName taggedMetricName = (TaggedMetricName) name; samplingName = new TaggedMetricName( taggedMetricName.getGroup(), taggedMetricName.getName() + ".duration", taggedMetricName.getTags()); rateName = new TaggedMetricName( taggedMetricName.getGroup(), taggedMetricName.getName() + ".rate", taggedMetricName.getTags()); } else { samplingName = new MetricName(name.getGroup(), name.getType(), name.getName() + ".duration"); rateName = new MetricName(name.getGroup(), name.getType(), name.getName() + ".rate"); } writeSummarizable(samplingName, timer); writeSampling(samplingName, timer); writeMetered(rateName, timer); if (clear) timer.clear(); }