Example #1
0
  private void resetPoints(Map<String, Map<Integer, MetricSnapshot>> metrics) {
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metrics.entrySet()) {
      String meta = metricEntry.getKey();
      MetricType metricType = MetricUtils.metricType(meta);
      Map<Integer, MetricSnapshot> winData = metricEntry.getValue();

      if (metricType == MetricType.HISTOGRAM || metricType == MetricType.TIMER) {
        for (MetricSnapshot snapshot : winData.values()) {
          snapshot.set_points(new ArrayList<Long>(0));
        }
      }
    }
  }
Example #2
0
 /** histograms are sampled, but we just update points */
 public void mergeHistograms(
     MetricInfo metricInfo,
     String meta,
     Map<Integer, MetricSnapshot> data,
     Map<String, Integer> metaCounters,
     Map<String, Map<Integer, Histogram>> histograms) {
   Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
   if (existing == null) {
     metricInfo.put_to_metrics(meta, data);
     Map<Integer, Histogram> histogramMap = new HashMap<>();
     for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
       Histogram histogram = MetricUtils.metricSnapshot2Histogram(dataEntry.getValue());
       histogramMap.put(dataEntry.getKey(), histogram);
     }
     histograms.put(meta, histogramMap);
   } 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);
         histograms.get(meta).put(win, MetricUtils.metricSnapshot2Histogram(snapshot));
       } else {
         if (snapshot.get_ts() >= old.get_ts()) {
           old.set_ts(snapshot.get_ts());
           // update points
           MetricUtils.updateHistogramPoints(histograms.get(meta).get(win), snapshot.get_points());
         }
       }
     }
   }
   updateMetricCounters(meta, metaCounters);
 }
Example #3
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 #4
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());
       }
     }
   }
 }
Example #5
0
  private void adjustMetrics(
      Map<String, Map<Integer, MetricSnapshot>> metrics,
      Map<String, Integer> metaCounters,
      Map<String, Map<Integer, Histogram>> histograms,
      Map<String, Map<Integer, Timer>> timers) {
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metrics.entrySet()) {
      String meta = metricEntry.getKey();
      MetricType metricType = MetricUtils.metricType(meta);
      MetaType metaType = MetricUtils.metaType(meta);
      Map<Integer, MetricSnapshot> winData = metricEntry.getValue();

      if (metricType == MetricType.HISTOGRAM) {
        for (Map.Entry<Integer, MetricSnapshot> dataEntry : winData.entrySet()) {
          MetricSnapshot snapshot = dataEntry.getValue();
          Integer cnt = metaCounters.get(meta);
          Histogram histogram = histograms.get(meta).get(dataEntry.getKey());
          if (cnt != null && cnt > 1) {

            Snapshot snapshot1 = histogram.getSnapshot();
            snapshot.set_mean(snapshot1.getMean());
            snapshot.set_p50(snapshot1.getMedian());
            snapshot.set_p75(snapshot1.get75thPercentile());
            snapshot.set_p95(snapshot1.get95thPercentile());
            snapshot.set_p98(snapshot1.get98thPercentile());
            snapshot.set_p99(snapshot1.get99thPercentile());
            snapshot.set_p999(snapshot1.get999thPercentile());
            snapshot.set_stddev(snapshot1.getStdDev());
            snapshot.set_min(snapshot1.getMin());
            snapshot.set_max(snapshot1.getMax());

            if (metaType == MetaType.TOPOLOGY) {
              snapshot.set_points(Arrays.asList(ArrayUtils.toObject(snapshot1.getValues())));
            }
          }
          if (metaType != MetaType.TOPOLOGY) {
            snapshot.set_points(new ArrayList<Long>(0));
          }
        }

      } else if (metricType == MetricType.TIMER) {
        for (Map.Entry<Integer, MetricSnapshot> dataEntry : winData.entrySet()) {
          MetricSnapshot snapshot = dataEntry.getValue();
          Integer cnt = metaCounters.get(meta);
          if (cnt != null && cnt > 1) {
            Timer timer = timers.get(meta).get(dataEntry.getKey());
            Snapshot snapshot1 = timer.getSnapshot();
            snapshot.set_p50(snapshot1.getMedian());
            snapshot.set_p75(snapshot1.get75thPercentile());
            snapshot.set_p95(snapshot1.get95thPercentile());
            snapshot.set_p98(snapshot1.get98thPercentile());
            snapshot.set_p99(snapshot1.get99thPercentile());
            snapshot.set_p999(snapshot1.get999thPercentile());
            snapshot.set_stddev(snapshot1.getStdDev());
            snapshot.set_min(snapshot1.getMin());
            snapshot.set_max(snapshot1.getMax());
          }
          snapshot.set_points(new ArrayList<Long>(0));
        }
      }
    }
  }
Example #6
0
  /** timers are sampled, we just update points */
  public void mergeTimers(
      MetricInfo metricInfo,
      String meta,
      Map<Integer, MetricSnapshot> data,
      Map<String, Integer> metaCounters,
      Map<String, Map<Integer, Timer>> timers) {
    Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
    if (existing == null) {
      metricInfo.put_to_metrics(meta, data);
      Map<Integer, Timer> timerMap = new HashMap<>();
      for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
        Timer timer = MetricUtils.metricSnapshot2Timer(dataEntry.getValue());
        timerMap.put(dataEntry.getKey(), timer);
      }
      timers.put(meta, timerMap);
    } 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);
          timers.get(meta).put(win, MetricUtils.metricSnapshot2Timer(snapshot));
        } else {
          if (snapshot.get_ts() >= old.get_ts()) {
            old.set_ts(snapshot.get_ts());
            old.set_m1(old.get_m1() + snapshot.get_m1());
            old.set_m5(old.get_m5() + snapshot.get_m5());
            old.set_m15(old.get_m15() + snapshot.get_m15());

            // update points
            MetricUtils.updateTimerPoints(timers.get(meta).get(win), snapshot.get_points());
          }
        }
      }
    }
    updateMetricCounters(meta, metaCounters);
  }
Example #7
0
 /** meters are not sampled. */
 public void mergeMeters(
     MetricInfo metricInfo,
     String meta,
     Map<Integer, MetricSnapshot> data,
     Map<String, Integer> metaCounters) {
   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 {
         if (snapshot.get_ts() >= old.get_ts()) {
           old.set_ts(snapshot.get_ts());
           old.set_mean(old.get_mean() + snapshot.get_mean());
           old.set_m1(old.get_m1() + snapshot.get_m1());
           old.set_m5(old.get_m5() + snapshot.get_m5());
           old.set_m15(old.get_m15() + snapshot.get_m15());
         }
       }
     }
   }
   updateMetricCounters(meta, metaCounters);
 }
Example #8
0
 public void mergeGauges(
     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 {
         if (snapshot.get_ts() >= old.get_ts()) {
           old.set_ts(snapshot.get_ts());
           if (metaType != MetaType.TOPOLOGY) {
             old.set_doubleValue(snapshot.get_doubleValue());
           } else { // for topology metric, gauge might be add-able, e.g., cpu, memory, etc.
             old.set_doubleValue(old.get_doubleValue() + snapshot.get_doubleValue());
           }
         }
       }
     }
   }
 }