/** * Persist metrics into metric store * * @param metricValues a non-empty deque of {@link MetricValues} */ private void persistMetrics(Deque<MetricValues> metricValues, Map<TopicIdMetaKey, TopicProcessMeta> topicProcessMetaMap) { long now = System.currentTimeMillis(); long lastMetricTime = metricValues.peekLast().getTimestamp(); List<MetricValue> topicLevelDelays = new ArrayList<>(); //add topic level delay metrics for (Map.Entry<TopicIdMetaKey, TopicProcessMeta> entry : topicProcessMetaMap.entrySet()) { TopicProcessMeta topicProcessMeta = entry.getValue(); long delay = now - TimeUnit.SECONDS.toMillis(topicProcessMeta.getOldestMetricsTimestamp()); topicLevelDelays.add(new MetricValue(topicProcessMeta.getOldestMetricsTimestampMetricName(), MetricType.GAUGE, delay)); delay = now - TimeUnit.SECONDS.toMillis(topicProcessMeta.getLatestMetricsTimestamp()); topicLevelDelays.add(new MetricValue(topicProcessMeta.getLatestMetricsTimestampMetricName(), MetricType.GAUGE, delay)); } List<MetricValue> processorMetrics = new ArrayList<>(topicLevelDelays); processorMetrics.add(new MetricValue(processMetricName, MetricType.COUNTER, metricValues.size())); metricValues.add(new MetricValues(metricsContextMap, TimeUnit.MILLISECONDS.toSeconds(now), processorMetrics)); metricStore.add(metricValues); metricsProcessedCount += metricValues.size(); PROGRESS_LOG.debug("{} metrics persisted. Last metric's timestamp: {}", metricsProcessedCount, lastMetricTime); }
/** * Persist metrics into metric store * * @param metricValues a non-empty deque of {@link MetricValues} */ private void persistMetrics(Deque<MetricValues> metricValues, Map<TopicIdMetaKey, TopicProcessMeta> topicProcessMetaMap) { long now = System.currentTimeMillis(); long lastMetricTime = metricValues.peekLast().getTimestamp(); List<MetricValue> topicLevelDelays = new ArrayList<>(); //add topic level delay metrics for (Map.Entry<TopicIdMetaKey, TopicProcessMeta> entry : topicProcessMetaMap.entrySet()) { TopicProcessMeta topicProcessMeta = entry.getValue(); long delay = now - TimeUnit.SECONDS.toMillis(topicProcessMeta.getOldestMetricsTimestamp()); topicLevelDelays.add(new MetricValue(topicProcessMeta.getOldestMetricsTimestampMetricName(), MetricType.GAUGE, delay)); delay = now - TimeUnit.SECONDS.toMillis(topicProcessMeta.getLatestMetricsTimestamp()); topicLevelDelays.add(new MetricValue(topicProcessMeta.getLatestMetricsTimestampMetricName(), MetricType.GAUGE, delay)); } List<MetricValue> processorMetrics = new ArrayList<>(topicLevelDelays); processorMetrics.add(new MetricValue(processMetricName, MetricType.COUNTER, metricValues.size())); metricValues.add(new MetricValues(metricsContextMap, TimeUnit.MILLISECONDS.toSeconds(now), processorMetrics)); metricStore.add(metricValues); metricsProcessedCount += metricValues.size(); PROGRESS_LOG.debug("{} metrics persisted. Last metric's timestamp: {}", metricsProcessedCount, lastMetricTime); }
@Override public void add(Collection<? extends MetricValues> metricValues) { List<CubeFact> facts = Lists.newArrayListWithCapacity(metricValues.size()); for (MetricValues metricValue : metricValues) { String scope = metricValue.getTags().get(Constants.Metrics.Tag.SCOPE); List<Measurement> metrics = Lists.newArrayList(); // todo improve this logic? for (MetricValue metric : metricValue.getMetrics()) { String measureName = (scope == null ? "system." : scope + ".") + metric.getName(); MeasureType type = metric.getType() == MetricType.COUNTER ? MeasureType.COUNTER : MeasureType.GAUGE; metrics.add(new Measurement(measureName, type, metric.getValue())); } CubeFact fact = new CubeFact(metricValue.getTimestamp()) .addDimensionValues(metricValue.getTags()) .addMeasurements(metrics); facts.add(fact); } cube.get().add(facts); }
@Override public void add(Collection<? extends MetricValues> metricValues) { List<CubeFact> facts = Lists.newArrayListWithCapacity(metricValues.size()); for (MetricValues metricValue : metricValues) { String scope = metricValue.getTags().get(Constants.Metrics.Tag.SCOPE); List<Measurement> metrics = Lists.newArrayList(); // todo improve this logic? for (MetricValue metric : metricValue.getMetrics()) { String measureName = (scope == null ? "system." : scope + ".") + metric.getName(); MeasureType type = metric.getType() == MetricType.COUNTER ? MeasureType.COUNTER : MeasureType.GAUGE; metrics.add(new Measurement(measureName, type, metric.getValue())); } CubeFact fact = new CubeFact(metricValue.getTimestamp()) .addDimensionValues(metricValue.getTags()) .addMeasurements(metrics); facts.add(fact); } cube.get().add(facts); }
break; lastMetricTimeSecs = metricValues.getTimestamp(); currentMessageId = input.getId(); if (LOG.isTraceEnabled()) {
break; lastMetricTimeSecs = metricValues.getTimestamp(); currentMessageId = input.getId(); if (LOG.isTraceEnabled()) {