Example #1
0
 /** sum old counter snapshots and new counter snapshots, sums are stored in new snapshots. */
 private void mergeCounters(
     Map<String, Map<Integer, MetricSnapshot>> newCounters,
     Map<String, Map<Integer, MetricSnapshot>> oldCounters) {
   for (Map.Entry<String, Map<Integer, MetricSnapshot>> entry : newCounters.entrySet()) {
     String metricName = entry.getKey();
     Map<Integer, MetricSnapshot> snapshots = entry.getValue();
     Map<Integer, MetricSnapshot> oldSnapshots = oldCounters.get(metricName);
     if (oldSnapshots != null && oldSnapshots.size() > 0) {
       for (Map.Entry<Integer, MetricSnapshot> snapshotEntry : snapshots.entrySet()) {
         Integer win = snapshotEntry.getKey();
         MetricSnapshot snapshot = snapshotEntry.getValue();
         MetricSnapshot oldSnapshot = oldSnapshots.get(win);
         if (oldSnapshot != null) {
           snapshot.set_longValue(snapshot.get_longValue() + oldSnapshot.get_longValue());
         }
       }
     }
   }
 }
Example #2
0
 public void mergeCounters(
     TopologyMetric tpMetric, MetaType metaType, String meta, Map<Integer, MetricSnapshot> data) {
   MetricInfo metricInfo = getMetricInfoByType(tpMetric, metaType);
   Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
   if (existing == null) {
     metricInfo.put_to_metrics(meta, data);
   } else {
     for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
       Integer win = dataEntry.getKey();
       MetricSnapshot snapshot = dataEntry.getValue();
       MetricSnapshot old = existing.get(win);
       if (old == null) {
         existing.put(win, snapshot);
       } else {
         old.set_ts(snapshot.get_ts());
         old.set_longValue(old.get_longValue() + snapshot.get_longValue());
       }
     }
   }
 }