You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/01/17 02:33:47 UTC

[GitHub] [incubator-inlong] shink commented on a change in pull request #2165: [INLONG-2106] DataProxy expose metric data using prometheus HttpServer.

shink commented on a change in pull request #2165:
URL: https://github.com/apache/incubator-inlong/pull/2165#discussion_r785601011



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/metrics/prometheus/PrometheusMetricListener.java
##########
@@ -105,7 +140,114 @@ public void snapshot(String domain, List<MetricItemValue> itemValues) {
                     metricValue.addAndGet(fieldValue);
                 }
             }
+            // id dimension
+            String dimensionKey = itemValue.getKey();
+            MetricItemValue dimensionMetricValue = this.dimensionMetricValueMap.get(dimensionKey);
+            if (dimensionKey == null) {
+                dimensionMetricValue = new MetricItemValue(dimensionKey, new ConcurrentHashMap<String, String>(),
+                        new ConcurrentHashMap<String, MetricValue>());
+                this.dimensionMetricValueMap.putIfAbsent(dimensionKey, dimensionMetricValue);
+                dimensionMetricValue = this.dimensionMetricValueMap.get(dimensionKey);
+                dimensionMetricValue.getDimensions().putAll(itemValue.getDimensions());
+                // add prometheus label name
+                for (Entry<String, String> entry : itemValue.getDimensions().entrySet()) {
+                    if (!this.dimensionKeys.contains(entry.getKey())) {
+                        this.dimensionKeys.add(entry.getKey());
+                    }
+                }
+            }
+            // count
+            for (Entry<String, MetricValue> entry : itemValue.getMetrics().entrySet()) {
+                String fieldName = entry.getValue().name;
+                MetricValue metricValue = dimensionMetricValue.getMetrics().get(fieldName);
+                if (metricValue == null) {
+                    metricValue = MetricValue.of(fieldName, entry.getValue().value);
+                    dimensionMetricValue.getMetrics().put(metricValue.name, metricValue);
+                    continue;
+                }
+                metricValue.value += entry.getValue().value;
+            }
+        }
+    }
+
+    /**
+     * collect
+     * 
+     * @return
+     */
+    @Override
+    public List<MetricFamilySamples> collect() {
+
+        // total
+        CounterMetricFamily totalCounter = new CounterMetricFamily(metricName + ".total", "help",
+                Arrays.asList("dimension"));

Review comment:
       I think the help information should be more detailed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org