/** * {@inheritDoc} */ @Override public void update(List<Metric> metrics) { Preconditions.checkNotNull(metrics, "metrics"); final List<Metric> newMetrics = new ArrayList<>(metrics.size()); for (Metric m : metrics) { long offset = m.getTimestamp() % stepMillis; long stepBoundary = m.getTimestamp() - offset; String dsType = getDataSourceType(m); if (isGauge(dsType) || isNormalized(dsType)) { Metric atStepBoundary = new Metric(m.getConfig(), stepBoundary, m.getValue()); newMetrics.add(atStepBoundary); // gauges are not normalized } else if (isRate(dsType)) { Metric normalized = normalize(m, stepBoundary); if (normalized != null) { newMetrics.add(normalized); } } else if (!isInformational(dsType)) { // unknown type - use a safe fallback newMetrics.add(m); // we cannot normalize this } } observer.update(newMetrics); }
void assertMetrics(long step, long heartbeat, List<Metric> input, List<TimeVal> expected) { ManualClock clock = new ManualClock(0); MemoryMetricObserver mmo = new MemoryMetricObserver("m", 1); MetricObserver transform = new NormalizationTransform(mmo, step, heartbeat, TimeUnit.MILLISECONDS, clock); int i = 0; for (Metric m : input) { transform.update(UnmodifiableList.of(m)); Metric result = mmo.getObservations().get(0).get(0); assertEquals(TimeVal.from(result), expected.get(i)); i++; } }
/** * {@inheritDoc} */ @Override public void update(List<Metric> metrics) { Preconditions.checkNotNull(metrics, "metrics"); final List<Metric> newMetrics = new ArrayList<>(metrics.size()); for (Metric m : metrics) { long offset = m.getTimestamp() % stepMillis; long stepBoundary = m.getTimestamp() - offset; String dsType = getDataSourceType(m); if (isGauge(dsType) || isNormalized(dsType)) { Metric atStepBoundary = new Metric(m.getConfig(), stepBoundary, m.getValue()); newMetrics.add(atStepBoundary); // gauges are not normalized } else if (isRate(dsType)) { Metric normalized = normalize(m, stepBoundary); if (normalized != null) { newMetrics.add(normalized); } } else if (!isInformational(dsType)) { // unknown type - use a safe fallback newMetrics.add(m); // we cannot normalize this } } observer.update(newMetrics); }
NormalizationTransform normalizationTransform = new NormalizationTransform(observer, 60, 120, TimeUnit.SECONDS, manualClock); CounterToRateMetricTransform toRateMetricTransform =
NormalizationTransform normalizationTransform = new NormalizationTransform(observer, 60, 120, TimeUnit.SECONDS, manualClock); CounterToRateMetricTransform toRateMetricTransform =