@Override protected void publish(Iterator<MetricValues> metrics) { while (metrics.hasNext()) { metricStore.add(metrics.next()); } }
@Override protected void publish(Iterator<MetricValues> metrics) { List<MetricValues> metricValues = new ArrayList<>(); while (metrics.hasNext()) { metricValues.add(metrics.next()); } metricStore.add(metricValues); }
private void gauge(Map<String, String> context, String metric, long timestamp, Long value) throws Exception { metricStore.add(new MetricValues(context, metric, timestamp, value, MetricType.GAUGE)); }
/** * 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); }