private void reportYammerMetrics(long now) throws Exception { LOG.debug("Reporting yammer metrics."); YammerMetricProcessor.Context context = new YammerMetricProcessor.Context(this, now, _brokerId, _reportingIntervalMs); for (Map.Entry<com.yammer.metrics.core.MetricName, Metric> entry : Metrics.defaultRegistry().allMetrics().entrySet()) { LOG.trace("Processing yammer metric {}, scope = {}", entry.getKey(), entry.getKey().getScope()); entry.getValue().processWith(_yammerMetricProcessor, entry.getKey(), context); } LOG.debug("Finished reporting yammer metrics."); }
/** * Convert a Yammer metric to a CruiseControlMetric */ public static CruiseControlMetric toCruiseControlMetric(long now, int brokerId, com.yammer.metrics.core.MetricName metricName, double value, String attribute) { CruiseControlMetric ccm = toCruiseControlMetric(now, brokerId, metricName.getName(), yammerMetricScopeToTags(metricName.getScope()), value, attribute); if (ccm == null) { throw new IllegalArgumentException(String.format("Cannot convert yammer metric %s to a Cruise Control metric for " + "broker %d at time %d for tag %s", metricName, brokerId, now, attribute)); } return ccm; }
/** * 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 metricName, Metric metric) { if (indexerName == null) { return METRIC_GROUP.equals(metricName.getGroup()); } else { return METRIC_GROUP.equals(metricName.getGroup()) && indexerName.equals(metricName.getScope()); } }
@Override public boolean matches(MetricName metricName, Metric metric) { if (indexerName == null) { return METRIC_GROUP.equals(metricName.getGroup()); } else { return METRIC_GROUP.equals(metricName.getGroup()) && indexerName.equals(metricName.getScope()); } }
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 void reportYammerMetrics(long now) throws Exception { LOG.debug("Reporting yammer metrics."); YammerMetricProcessor.Context context = new YammerMetricProcessor.Context(this, now, _brokerId, _reportingIntervalMs); for (Map.Entry<com.yammer.metrics.core.MetricName, Metric> entry : Metrics.defaultRegistry().allMetrics().entrySet()) { LOG.trace("Processing yammer metric {}, scope = {}", entry.getKey(), entry.getKey().getScope()); entry.getValue().processWith(_yammerMetricProcessor, entry.getKey(), context); } LOG.debug("Finished reporting yammer metrics."); }
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(); } }
/** * Convert a Yammer metric to a CruiseControlMetric */ public static CruiseControlMetric toCruiseControlMetric(long now, int brokerId, com.yammer.metrics.core.MetricName metricName, double value, String attribute) { CruiseControlMetric ccm = toCruiseControlMetric(now, brokerId, metricName.getName(), yammerMetricScopeToTags(metricName.getScope()), value, attribute); if (ccm == null) { throw new IllegalArgumentException(String.format("Cannot convert yammer metric %s to a Cruise Control metric for " + "broker %d at time %d for tag %s", metricName, brokerId, now, attribute)); } return ccm; }
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; }
public String qualifyMetricName(MetricName mn) { String qualifiedTypeName = mn.getGroup() + "." + mn.getType(); if (mn.hasScope()) { qualifiedTypeName += "." + mn.getScope(); } qualifiedTypeName += "." + mn.getName(); return qualifiedTypeName; }
public static String qualifyMetricName(MetricName mn) { String qualifiedTypeName = mn.getGroup() + "." + mn.getType(); if (mn.hasScope()) { qualifiedTypeName += "." + mn.getScope(); } qualifiedTypeName += "." + mn.getName(); return qualifiedTypeName; }
/** * 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())); }
String[] scope = name.getScope().split("\\.");
/** * 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()); } }