shink commented on a change in pull request #2165:
URL: https://github.com/apache/incubator-inlong/pull/2165#discussion_r785602811
##########
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:
And the names of metrics are usually joind with underscores in
Prometheus.
```suggestion
CounterMetricFamily totalCounter = new
CounterMetricFamily(metricName + "_total", "The total number of dataproxy
metrics.",
Arrays.asList("dimension"));
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]