Example #1
0
 public static Map<MetricName, Metric> filterMetrics(
     Map<MetricName, Metric> metrics, MetricPredicate predicate) {
   final Map<MetricName, Metric> result = new HashMap<MetricName, Metric>();
   for (Entry<MetricName, Metric> entry : metrics.entrySet()) {
     if (predicate.matches(entry.getKey(), entry.getValue())) {
       result.put(entry.getKey(), entry.getValue());
     }
   }
   return result;
 }
 /**
  * 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>> getGroupedMetrics(
     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);
 }
Example #3
0
 public static Map<String, Map<MetricName, Metric>> sortAndFilterMetrics(
     Map<MetricName, Metric> metrics, MetricPredicate predicate) {
   final Map<String, Map<MetricName, Metric>> sortedMetrics =
       new TreeMap<String, Map<MetricName, Metric>>();
   for (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;
       }
       Map<MetricName, Metric> subMetrics = sortedMetrics.get(scopedName);
       if (subMetrics == null) {
         subMetrics = new TreeMap<MetricName, Metric>();
         sortedMetrics.put(scopedName, subMetrics);
       }
       subMetrics.put(entry.getKey(), entry.getValue());
     }
   }
   return sortedMetrics;
 }