From bc17fa327d9eb782cbc50c93a0e5248388db2f81 Mon Sep 17 00:00:00 2001 From: minwoo-jung Date: Wed, 19 Oct 2022 16:23:59 +0900 Subject: [PATCH] [#9280] Matching rules have been improved --- .../basic/metric/group/MatchingRule.java | 14 ++++-- .../SystemMetricHostInfoServiceImpl.java | 25 ++++++++++- .../resources/pinot-web/telegraf-metric.yml | 44 ++++++++++++++----- 3 files changed, 66 insertions(+), 17 deletions(-) diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/model/basic/metric/group/MatchingRule.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/model/basic/metric/group/MatchingRule.java index 852785716140..fe693a37c2c1 100644 --- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/model/basic/metric/group/MatchingRule.java +++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/model/basic/metric/group/MatchingRule.java @@ -6,10 +6,16 @@ * @author minwoo.jung */ public enum MatchingRule { - EXACT(1, "exact"), - CONTAIN(2, "contain"), - ALL(3, "all"), - UNKNOWN(100, "unknown"); + // only one + EXACT_ONE(1, "exact_one"), + ANY_ONE(2, "any_one"), + + //multi + CONTAIN(100, "contain"), + ALL(200, "all"), + + + UNKNOWN(999, "unknown"); private final int code; private final String value; diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImpl.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImpl.java index 2c0aedffe2ca..d3a9771756ed 100644 --- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImpl.java +++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImpl.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -96,8 +97,10 @@ public List getTag(MetricDataSearchKey metricDataSearchKey, Field fie MatchingRule matchingRule = field.getMatchingRule(); switch (matchingRule) { - case EXACT : + case EXACT_ONE: return getExactMatchingTag(metricDataSearchKey, field); + case ANY_ONE: + return getAnyOneTag(metricDataSearchKey, field); case ALL : return createTag(metricDataSearchKey, field, tags); default : @@ -105,6 +108,24 @@ public List getTag(MetricDataSearchKey metricDataSearchKey, Field fie } } + private List getAnyOneTag(MetricDataSearchKey metricDataSearchKey, Field field) { + MetricTagKey metricTagKey = new MetricTagKey(metricDataSearchKey.getHostGroupName(), metricDataSearchKey.getHostName(), metricDataSearchKey.getMetricName(), field.getName(), getSaveTime()); + MetricTagCollection metricTagCollection = systemMetricHostInfoDao.selectMetricTagCollection(metricTagKey); + + List metricTagList = metricTagCollection.getMetricTagList(); + List anyOneTag = new ArrayList<>(); + + if (metricTagList.size() != 1) { + return Collections.emptyList(); + } + + MetricTag metricTag = metricTagList.get(0); + anyOneTag.add(metricTag.copy()); + + return anyOneTag; + + } + private List createTag(MetricDataSearchKey metricDataSearchKey, Field field, List tags) { if (tags == null || tags.isEmpty()) { return allMatchingTag(metricDataSearchKey, field); @@ -139,7 +160,7 @@ private List getExactMatchingTag(MetricDataSearchKey metricDataSearch continue; } if (collectedTagList.containsAll(tagList)) { - exactMetricTagList.add(metricTag); + exactMetricTagList.add(metricTag.copy()); } } diff --git a/metric-module/metric/src/main/resources/pinot-web/telegraf-metric.yml b/metric-module/metric/src/main/resources/pinot-web/telegraf-metric.yml index a9ff239abffb..d33b4ec6f54d 100644 --- a/metric-module/metric/src/main/resources/pinot-web/telegraf-metric.yml +++ b/metric-module/metric/src/main/resources/pinot-web/telegraf-metric.yml @@ -8,15 +8,15 @@ mappings: - name: "usage_user" tags: - { name: "cpu", value: "cpu-total" } - matchingRule: EXACT + matchingRule: EXACT_ONE - name: "usage_system" tags: - { name: "cpu", value: "cpu-total" } - matchingRule: EXACT + matchingRule: EXACT_ONE - name: "usage_idle" tags: - { name: "cpu", value: "cpu-total" } - matchingRule: EXACT + matchingRule: EXACT_ONE - definitionId: "memoryPercent" name: "mem" @@ -25,7 +25,7 @@ mappings: unit: "percent" fields: - name: "used_percent" - matchingRule: EXACT + matchingRule: EXACT_ONE - definitionId: "memoryUsage" name: "mem" @@ -34,9 +34,9 @@ mappings: unit: "byte" fields: - name: "total" - matchingRule: EXACT + matchingRule: EXACT_ONE - name: "used" - matchingRule: EXACT + matchingRule: EXACT_ONE - definitionId: "diskUsage" name: "disk" @@ -78,11 +78,11 @@ mappings: unit: "percent" fields: - name: "load1" - matchingRule: EXACT + matchingRule: EXACT_ONE - name: "load5" - matchingRule: EXACT + matchingRule: EXACT_ONE - name: "load15" - matchingRule: EXACT + matchingRule: EXACT_ONE - definitionId: "swap" name: "swap" @@ -91,6 +91,28 @@ mappings: unit: "count" fields: - name: "total" - matchingRule: EXACT + matchingRule: EXACT_ONE - name: "used" - matchingRule: EXACT + matchingRule: EXACT_ONE + + - definitionId: "apacheWorker" + name: "apache" + title: "apache Worker" + grouping: "TAG" + unit: "count" + fields: + - name: "BusyWorkers" + matchingRule: ANY_ONE + - name: "IdleWorkers" + matchingRule: ANY_ONE + + - definitionId: "nginxActive" + name: "nginx" + title: "nginx active/waiting" + grouping: "TAG" + unit: "count" + fields: + - name: "active" + matchingRule: ANY_ONE + - name: "waiting" + matchingRule: ANY_ONE \ No newline at end of file