diff --git a/metric-module/metric/pom.xml b/metric-module/metric/pom.xml
index e85c077e8cfe..3e2d6b7de06a 100644
--- a/metric-module/metric/pom.xml
+++ b/metric-module/metric/pom.xml
@@ -230,6 +230,10 @@
net.sf.ehcache
ehcache
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-yaml
+
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/MetricTagKey.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/MetricTagKey.java
index 015a71879d61..6c648a131ef4 100644
--- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/MetricTagKey.java
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/MetricTagKey.java
@@ -16,8 +16,6 @@
package com.navercorp.pinpoint.metric.common.model;
-import org.springframework.util.StringUtils;
-
import java.util.Objects;
/**
@@ -31,22 +29,10 @@ public class MetricTagKey {
private final String fieldName;
public MetricTagKey(String hostGroupId, String hostName, String metricName, String fieldName) {
- if (!StringUtils.hasLength(hostGroupId)) {
- throw new IllegalArgumentException("hostGroupId must not be empty");
- }
- if (!StringUtils.hasLength(hostName)) {
- throw new IllegalArgumentException("hostName must not be empty");
- }
- if (!StringUtils.hasLength(metricName)) {
- throw new IllegalArgumentException("metricName must not be empty");
- }
- if (!StringUtils.hasLength(fieldName)) {
- throw new IllegalArgumentException("fieldName must not be empty");
- }
- this.hostGroupId = hostGroupId;
- this.hostName = hostName;
- this.metricName = metricName;
- this.fieldName = fieldName;
+ this.hostGroupId = StringPrecondition.requireHasLength(hostGroupId, "hostGroupId");
+ this.hostName = StringPrecondition.requireHasLength(hostName, "hostName");
+ this.metricName = StringPrecondition.requireHasLength(metricName, "metricName");
+ this.fieldName = StringPrecondition.requireHasLength(fieldName, "fieldName");
}
public String getHostGroupId() {
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/Tag.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/Tag.java
index ddf6c3d0c41e..8e5f9301797b 100644
--- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/Tag.java
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/common/model/Tag.java
@@ -28,7 +28,9 @@ public class Tag {
private final String name;
private final String value;
- public Tag(String name, String value) {
+ @JsonCreator
+ public Tag(@JsonProperty("name") String name,
+ @JsonProperty("value") String value) {
this.name = Objects.requireNonNull(name);
this.value = Objects.requireNonNull(value);
}
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/controller/SystemMetricController.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/controller/SystemMetricController.java
index d6fe2f325005..2c80fd7003ba 100644
--- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/controller/SystemMetricController.java
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/controller/SystemMetricController.java
@@ -166,7 +166,7 @@ public SystemMetricView getCollectedMetricData(@RequestParam("hostGroupId") Stri
Range range = Range.newRange(from, to);
TimeWindow timeWindow = new TimeWindow(Range.newRange(from, to), DEFAULT_TIME_WINDOW_SAMPLER);
MetricDataSearchKey metricDataSearchKey = new MetricDataSearchKey(hostGroupId, hostName, systemMetricBasicGroupManager.findMetricName(metricDefinitionId), metricDefinitionId, range);
- SystemMetricData systemMetricData = systemMetricDataService.getCollectedMetricData(metricDataSearchKey, timeWindow);
+ SystemMetricData extends Number> systemMetricData = systemMetricDataService.getCollectedMetricData(metricDataSearchKey, timeWindow);
return new SystemMetricView(systemMetricData);
}
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Field.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Field.java
new file mode 100644
index 000000000000..642a7fa72c27
--- /dev/null
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Field.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2021 NAVER Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.navercorp.pinpoint.metric.web.mapping;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.navercorp.pinpoint.metric.common.model.Tag;
+import com.navercorp.pinpoint.metric.web.model.basic.metric.group.MatchingRule;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+
+public class Field {
+ private final String name;
+ private final List tags;
+ private final MatchingRule matchingRule;
+
+ @JsonCreator
+ public Field(@JsonProperty("name") String name,
+ @JsonProperty("tags") List tags,
+ @JsonProperty("matchingRule") MatchingRule matchingRule) {
+ this.name = Objects.requireNonNull(name, "name");
+ this.tags = defaultTags(tags);
+ this.matchingRule = Objects.requireNonNull(matchingRule, "matchingRule");
+ }
+
+ private List defaultTags(List tags) {
+ if (tags == null) {
+ return Collections.emptyList();
+ }
+ return tags;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List getTags() {
+ return tags;
+ }
+
+ public MatchingRule getMatchingRule() {
+ return matchingRule;
+ }
+
+ @Override
+ public String toString() {
+ return "Field{" +
+ "name='" + name + '\'' +
+ ", tags=" + tags +
+ ", matchingRule=" + matchingRule +
+ '}';
+ }
+}
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Mappings.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Mappings.java
new file mode 100644
index 000000000000..b3c7cef4a2f1
--- /dev/null
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Mappings.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2021 NAVER Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.navercorp.pinpoint.metric.web.mapping;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+import java.util.Objects;
+
+public class Mappings {
+
+ private final List mappings;
+
+ @JsonCreator
+ public Mappings(@JsonProperty("mappings") List mappings) {
+ this.mappings = Objects.requireNonNull(mappings, "mappings");
+ }
+
+ public List getMappings() {
+ return mappings;
+ }
+
+ @Override
+ public String toString() {
+ return "Mappings{" +
+ "groups=" + mappings +
+ '}';
+ }
+}
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Metric.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Metric.java
new file mode 100644
index 000000000000..2e1b1efe9529
--- /dev/null
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/mapping/Metric.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2021 NAVER Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.navercorp.pinpoint.metric.web.mapping;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.navercorp.pinpoint.metric.web.model.basic.metric.group.GroupingRule;
+
+import java.util.List;
+import java.util.Objects;
+
+public class Metric {
+ private final String name;
+ private final String title;
+ private final String definitionId;
+ private final GroupingRule grouping;
+ private final String unit;
+ private final List fields;
+
+ @JsonCreator
+ public Metric(@JsonProperty("name") String name,
+ @JsonProperty("title") String title,
+ @JsonProperty("definitionId") String definitionId,
+ @JsonProperty("grouping") GroupingRule grouping,
+ @JsonProperty("unit") String unit,
+ @JsonProperty("fields") List fields) {
+ this.name = Objects.requireNonNull(name, "name");
+ this.title = Objects.requireNonNull(title, "title");
+ this.definitionId = Objects.requireNonNull(definitionId, "definitionId");
+ this.grouping = Objects.requireNonNull(grouping, "grouping");
+ this.unit = Objects.requireNonNull(unit, "unit");
+ this.fields = Objects.requireNonNull(fields, "fields");
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getDefinitionId() {
+ return definitionId;
+ }
+
+ public GroupingRule getGrouping() {
+ return grouping;
+ }
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public List getFields() {
+ return fields;
+ }
+
+ @Override
+ public String toString() {
+ return "Metric{" +
+ "name='" + name + '\'' +
+ ", title='" + title + '\'' +
+ ", definitionId='" + definitionId + '\'' +
+ ", grouping=" + grouping +
+ ", unit='" + unit + '\'' +
+ ", fields=" + fields +
+ '}';
+ }
+}
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricBasicGroupManager.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricBasicGroupManager.java
index 469dca6b6c2d..e190e6c3eb29 100644
--- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricBasicGroupManager.java
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricBasicGroupManager.java
@@ -86,7 +86,7 @@ public class SystemMetricBasicGroupManager {
static {
//CPU
- List tagList = new ArrayList(1);
+ List tagList = new ArrayList<>(1);
Tag tag = new Tag("cpu", "cpu-total");
tagList.add(tag);
@@ -103,7 +103,7 @@ public class SystemMetricBasicGroupManager {
static {
//memory usage percent
- List tagList = new ArrayList(0);
+ List tagList = new ArrayList<>(0);
ElementOfBasicGroup memoryUsedPercent = new ElementOfBasicGroup(MEMORY_PERCENT_METRIC_NAME, "used_percent", tagList, MatchingRule.EXACT);
List elementOfBasicGroupList = new ArrayList<>(1);
@@ -114,7 +114,7 @@ public class SystemMetricBasicGroupManager {
static {
//memory usage
- List tagList = new ArrayList(0);
+ List tagList = new ArrayList<>(0);
ElementOfBasicGroup memoryTotal = new ElementOfBasicGroup(MEMORY_USAGE_METRIC_NAME, "total", tagList, MatchingRule.EXACT);
ElementOfBasicGroup memoryUsed = new ElementOfBasicGroup(MEMORY_USAGE_METRIC_NAME, "used", tagList, MatchingRule.EXACT);
@@ -127,7 +127,7 @@ public class SystemMetricBasicGroupManager {
static {
//disk usage
- List tagList = new ArrayList(0);
+ List tagList = new ArrayList<>(0);
ElementOfBasicGroup diskTotal = new ElementOfBasicGroup(DISK_USAGE_METRIC_NAME, "total", tagList, MatchingRule.ALL);
ElementOfBasicGroup diskUsed = new ElementOfBasicGroup(DISK_USAGE_METRIC_NAME, "used", tagList, MatchingRule.ALL);
List elementOfBasicGroupList = new ArrayList<>(2);
@@ -139,7 +139,7 @@ public class SystemMetricBasicGroupManager {
static {
//disk usage percent
- List tagList = new ArrayList(0);
+ List tagList = new ArrayList<>(0);
ElementOfBasicGroup diskUsedPercent = new ElementOfBasicGroup(DISK_PERCENT_METRIC_NAME, "used_percent", tagList, MatchingRule.ALL);
List elementOfBasicGroupList = new ArrayList<>(1);
elementOfBasicGroupList.add(diskUsedPercent);
@@ -149,7 +149,7 @@ public class SystemMetricBasicGroupManager {
static {
//disk usage
- List tagList = new ArrayList(0);
+ List tagList = new ArrayList<>(0);
ElementOfBasicGroup inodeTotal = new ElementOfBasicGroup(DISK_INODE_METRIC_NAME, "inodes_total", tagList, MatchingRule.ALL);
ElementOfBasicGroup inodeUsed = new ElementOfBasicGroup(DISK_INODE_METRIC_NAME, "inodes_used", tagList, MatchingRule.ALL);
ElementOfBasicGroup inodeFree = new ElementOfBasicGroup(DISK_INODE_METRIC_NAME, "inodes_free", tagList, MatchingRule.ALL);
@@ -253,7 +253,7 @@ public String findUnit(String metricDefinitionId) {
}
public List findMetricDefinitionIdList(String metricName) {
- List definitionIdList = new LinkedList();
+ List definitionIdList = new LinkedList<>();
if (CPU_METRIC_NAME.equals(metricName)) {
definitionIdList.add(CPU_DEFINITION_ID);
} else if (MEMORY_METRIC_NAME.equals(metricName)) {
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataService.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataService.java
index 10623ca80dac..afcda09961db 100644
--- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataService.java
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataService.java
@@ -32,7 +32,7 @@ public interface SystemMetricDataService {
List getSystemMetricBoList(QueryParameter queryParameter);
- SystemMetricChart getSystemMetricChart(TimeWindow timeWindow, QueryParameter queryParameter);
+ SystemMetricChart extends Number> getSystemMetricChart(TimeWindow timeWindow, QueryParameter queryParameter);
- SystemMetricData getCollectedMetricData(MetricDataSearchKey metricDataSearchKey, TimeWindow timeWindow);
+ SystemMetricData extends Number> getCollectedMetricData(MetricDataSearchKey metricDataSearchKey, TimeWindow timeWindow);
}
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataServiceImpl.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataServiceImpl.java
index 3402ec62b35e..b2d9dfc74230 100644
--- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataServiceImpl.java
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricDataServiceImpl.java
@@ -23,11 +23,12 @@
import com.navercorp.pinpoint.metric.common.model.SystemMetric;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.web.dao.SystemMetricDao;
+import com.navercorp.pinpoint.metric.web.mapping.Field;
+import com.navercorp.pinpoint.metric.web.mapping.Metric;
import com.navercorp.pinpoint.metric.web.model.MetricDataSearchKey;
import com.navercorp.pinpoint.metric.web.model.MetricValue;
import com.navercorp.pinpoint.metric.web.model.MetricValueGroup;
import com.navercorp.pinpoint.metric.web.model.SystemMetricData;
-import com.navercorp.pinpoint.metric.web.model.basic.metric.group.ElementOfBasicGroup;
import com.navercorp.pinpoint.metric.web.model.basic.metric.group.GroupingRule;
import com.navercorp.pinpoint.metric.web.model.chart.SystemMetricPoint;
import com.navercorp.pinpoint.metric.web.util.TimeWindow;
@@ -61,13 +62,15 @@ public class SystemMetricDataServiceImpl implements SystemMetricDataService {
private final SystemMetricDao systemMetricDoubleDao;
private final SystemMetricDataTypeService systemMetricDataTypeService;
- private final SystemMetricBasicGroupManager systemMetricBasicGroupManager;
+// private final SystemMetricBasicGroupManager systemMetricBasicGroupManager;
+ private final YMLSystemMetricBasicGroupManager systemMetricBasicGroupManager;
+
private final SystemMetricHostInfoService systemMetricHostInfoService;
public SystemMetricDataServiceImpl(SystemMetricDao systemMetricLongDao,
SystemMetricDao systemMetricDoubleDao,
SystemMetricDataTypeService systemMetricDataTypeService,
- SystemMetricBasicGroupManager systemMetricBasicGroupManager,
+ YMLSystemMetricBasicGroupManager systemMetricBasicGroupManager,
SystemMetricHostInfoService systemMetricHostInfoService) {
this.systemMetricLongDao = Objects.requireNonNull(systemMetricLongDao, "systemMetricLongDao");
this.systemMetricDoubleDao = Objects.requireNonNull(systemMetricDoubleDao, "systemMetricDoubleDao");
@@ -77,7 +80,7 @@ public SystemMetricDataServiceImpl(SystemMetricDao systemMetricLongDao,
}
@Override
- public List getSystemMetricBoList(QueryParameter queryParameter) {
+ public List getSystemMetricBoList(QueryParameter queryParameter) {
MetricDataName metricDataName = new MetricDataName(queryParameter.getMetricName(), queryParameter.getFieldName());
MetricDataType metricDataType = systemMetricDataTypeService.getMetricDataType(metricDataName);
@@ -93,7 +96,7 @@ public List getSystemMetricBoList(QueryParameter queryParameter) {
}
@Override
- public SystemMetricChart getSystemMetricChart(TimeWindow timeWindow, QueryParameter queryParameter) {
+ public SystemMetricChart extends Number> getSystemMetricChart(TimeWindow timeWindow, QueryParameter queryParameter) {
String metricName = queryParameter.getMetricName();
String fieldName = queryParameter.getFieldName();
@@ -113,27 +116,28 @@ public SystemMetricChart getSystemMetricChart(TimeWindow timeWindow, QueryParame
}
@Override
- public SystemMetricData getCollectedMetricData(MetricDataSearchKey metricDataSearchKey, TimeWindow timeWindow) {
+ public SystemMetricData extends Number> getCollectedMetricData(MetricDataSearchKey metricDataSearchKey, TimeWindow timeWindow) {
String metricDefinitionId = metricDataSearchKey.getMetricDefinitionId();
- List metricValueList = getMetricValues(metricDataSearchKey, timeWindow);
+ List> metricValueList = getMetricValues(metricDataSearchKey, timeWindow);
GroupingRule groupingRule = systemMetricBasicGroupManager.findGroupingRule(metricDefinitionId);
- List metricValueGroupList = groupingMetricValue(metricValueList, groupingRule);
+ List> metricValueGroupList = groupingMetricValue(metricValueList, groupingRule);
List timeStampList = createTimeStampList(timeWindow);
String title = systemMetricBasicGroupManager.findMetricTitle(metricDefinitionId);
String unit = systemMetricBasicGroupManager.findUnit(metricDefinitionId);
- return new SystemMetricData(title, unit, timeStampList ,metricValueGroupList);
+ return new SystemMetricData(title, unit, timeStampList, metricValueGroupList);
}
- private List getMetricValues(MetricDataSearchKey metricDataSearchKey, TimeWindow timeWindow) {
- List elementOfBasicGroupList = systemMetricBasicGroupManager.findElementOfBasicGroup(metricDataSearchKey.getMetricDefinitionId());
- List metricValueList = new ArrayList<>(elementOfBasicGroupList.size());
+ private List> getMetricValues(MetricDataSearchKey metricDataSearchKey, TimeWindow timeWindow) {
+ Metric elementOfBasicGroupList = systemMetricBasicGroupManager.findElementOfBasicGroup(metricDataSearchKey.getMetricDefinitionId());
+ List> metricValueList = new ArrayList<>(elementOfBasicGroupList.getFields().size());
- for (ElementOfBasicGroup elementOfBasicGroup : elementOfBasicGroupList) {
- MetricDataType metricDataType = systemMetricDataTypeService.getMetricDataType(new MetricDataName(metricDataSearchKey.getMetricName(), elementOfBasicGroup.getFieldName()));
- List metricTagList = systemMetricHostInfoService.getTag(metricDataSearchKey, elementOfBasicGroup);
+ for (Field field : elementOfBasicGroupList.getFields()) {
+ MetricDataName metricDataName = new MetricDataName(metricDataSearchKey.getMetricName(), field.getName());
+ MetricDataType metricDataType = systemMetricDataTypeService.getMetricDataType(metricDataName);
+ List metricTagList = systemMetricHostInfoService.getTag(metricDataSearchKey, field);
for (MetricTag metricTag : metricTagList) {
switch (metricDataType) {
@@ -156,43 +160,46 @@ private List getMetricValues(MetricDataSearchKey metricDataSearchKe
return metricValueList;
}
- private List groupingMetricValue(List metricValueList, GroupingRule groupingRule) {
- switch(groupingRule) {
- case TAG :
+ private List> groupingMetricValue(List> metricValueList, GroupingRule groupingRule) {
+ switch (groupingRule) {
+ case TAG:
return groupingByTag(metricValueList);
- default :
+ default:
throw new UnsupportedOperationException("unsupported groupingRule :" + groupingRule);
}
}
- private List groupingByTag(List metricValueList) {
- List uniqueTagGroupList = new ArrayList();
+ private List> groupingByTag(List> metricValueList) {
+ List uniqueTagGroupList = new ArrayList<>();
- for (MetricValue metricValue : metricValueList) {
+ for (MetricValue> metricValue : metricValueList) {
List tagList = metricValue.getTagList();
addTagList(uniqueTagGroupList, tagList);
}
- Map> metricValueGroupMap = new HashMap<>();
- for (MetricValue metricValue : metricValueList) {
+ Map>> metricValueGroupMap = new HashMap<>();
+ for (MetricValue> metricValue : metricValueList) {
int index = uniqueTagGroupList.indexOf(new TagGroup(metricValue.getTagList()));
TagGroup tagGroup = uniqueTagGroupList.get(index);
if (metricValueGroupMap.containsKey(tagGroup)) {
- List metricValues = metricValueGroupMap.get(tagGroup);
+ List> metricValues = metricValueGroupMap.get(tagGroup);
metricValues.add(metricValue);
} else {
- List metricValues = new ArrayList<>(1);
+ List> metricValues = new ArrayList<>(1);
metricValues.add(metricValue);
metricValueGroupMap.put(tagGroup, metricValues);
}
}
- Collection> valueList = metricValueGroupMap.values();
+ Collection>> valueList = metricValueGroupMap.values();
- List metricValueGroupList = new ArrayList<>(valueList.size());
- for (Map.Entry> entry : metricValueGroupMap.entrySet()) {
- metricValueGroupList.add(new MetricValueGroup(entry.getValue(),entry.getKey().toString()));
+ List> metricValueGroupList = new ArrayList<>(valueList.size());
+ for (Map.Entry>> entry : metricValueGroupMap.entrySet()) {
+ String groupName = entry.getKey().toString();
+ List> value = entry.getValue();
+ MetricValueGroup> group = new MetricValueGroup(value, groupName);
+ metricValueGroupList.add(group);
}
return metricValueGroupList;
@@ -210,11 +217,11 @@ private void addTagList(List uniqueTagList, List tagList) {
uniqueTagList.add(newTagGroup);
}
- private class TagGroup {
- private List tagList;
+ private static class TagGroup {
+ private final List tagList;
public TagGroup(List tagList) {
- this.tagList = Objects.requireNonNull(tagList, "tagList");;
+ this.tagList = Objects.requireNonNull(tagList, "tagList");
}
@Override
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoService.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoService.java
index f9dbcaf7b4ad..41d7e33362c3 100644
--- a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoService.java
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoService.java
@@ -17,6 +17,8 @@
package com.navercorp.pinpoint.metric.web.service;
import com.navercorp.pinpoint.metric.common.model.MetricTag;
+import com.navercorp.pinpoint.metric.web.mapping.Field;
+import com.navercorp.pinpoint.metric.web.mapping.Metric;
import com.navercorp.pinpoint.metric.web.model.MetricDataSearchKey;
import com.navercorp.pinpoint.metric.web.model.basic.metric.group.ElementOfBasicGroup;
@@ -32,5 +34,5 @@ public interface SystemMetricHostInfoService {
List getCollectedMetricInfo(String hostGroupId, String hostName);
- List getTag(MetricDataSearchKey metricDataSearchKey, ElementOfBasicGroup elementOfBasicGroup);
+ List getTag(MetricDataSearchKey metricDataSearchKey, Field elementOfBasicGroup);
}
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 a22bf7c62216..5022ba792e13 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
@@ -21,8 +21,8 @@
import com.navercorp.pinpoint.metric.common.model.MetricTagKey;
import com.navercorp.pinpoint.metric.common.model.Tag;
import com.navercorp.pinpoint.metric.web.dao.SystemMetricHostInfoDao;
+import com.navercorp.pinpoint.metric.web.mapping.Field;
import com.navercorp.pinpoint.metric.web.model.MetricDataSearchKey;
-import com.navercorp.pinpoint.metric.web.model.basic.metric.group.ElementOfBasicGroup;
import com.navercorp.pinpoint.metric.web.model.basic.metric.group.MatchingRule;
import org.springframework.stereotype.Service;
@@ -68,28 +68,29 @@ public List getCollectedMetricInfo(String hostGroupId, String hostName)
}
@Override
- public List getTag(MetricDataSearchKey metricDataSearchKey, ElementOfBasicGroup elementOfBasicGroup) {
- MetricTagCollection metricTagCollection = systemMetricHostInfoDao.selectMetricTagCollection(new MetricTagKey(metricDataSearchKey.getHostGroupId(), metricDataSearchKey.getHostName(), metricDataSearchKey.getMetricName() , elementOfBasicGroup.getFieldName()));
+ public List getTag(MetricDataSearchKey metricDataSearchKey, Field field) {
+ MetricTagKey metricTagKey = new MetricTagKey(metricDataSearchKey.getHostGroupId(), metricDataSearchKey.getHostName(), metricDataSearchKey.getMetricName(), field.getName());
+ MetricTagCollection metricTagCollection = systemMetricHostInfoDao.selectMetricTagCollection(metricTagKey);
- MatchingRule matchingRule = elementOfBasicGroup.getMatchingRule();
+ MatchingRule matchingRule = field.getMatchingRule();
switch (matchingRule) {
case EXACT :
- return exactMatchingTag(metricTagCollection, elementOfBasicGroup);
+ return exactMatchingTag(metricTagCollection, field);
case ALL :
- return allMatchingTag(metricTagCollection, elementOfBasicGroup);
+ return allMatchingTag(metricTagCollection, field);
default :
throw new UnsupportedOperationException("unsupported matchingRule:" + matchingRule);
}
}
- private List allMatchingTag(MetricTagCollection metricTagCollection, ElementOfBasicGroup elementOfBasicGroup) {
+ private List allMatchingTag(MetricTagCollection metricTagCollection, Field elementOfBasicGroup) {
return metricTagCollection.getMetricTagList();
}
- private List exactMatchingTag(MetricTagCollection metricTagCollection, ElementOfBasicGroup elementOfBasicGroup) {
+ private List exactMatchingTag(MetricTagCollection metricTagCollection, Field elementOfBasicGroup) {
List metricTagList = metricTagCollection.getMetricTagList();
- List tagList = elementOfBasicGroup.getTagList();
+ List tagList = elementOfBasicGroup.getTags();
List exactMetricTagList = new ArrayList<>();
for (MetricTag metricTag : metricTagList) {
diff --git a/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/YMLSystemMetricBasicGroupManager.java b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/YMLSystemMetricBasicGroupManager.java
new file mode 100644
index 000000000000..983625b4ba8e
--- /dev/null
+++ b/metric-module/metric/src/main/java/com/navercorp/pinpoint/metric/web/service/YMLSystemMetricBasicGroupManager.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2021 NAVER Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.navercorp.pinpoint.metric.web.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import com.navercorp.pinpoint.common.util.Assert;
+import com.navercorp.pinpoint.metric.web.mapping.Mappings;
+import com.navercorp.pinpoint.metric.web.mapping.Metric;
+import com.navercorp.pinpoint.metric.web.model.basic.metric.group.GroupingRule;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.BiFunction;
+
+/**
+ * @author minwoo.jung
+ */
+@Service
+public class YMLSystemMetricBasicGroupManager {
+
+ public static final String TELEGRAF_METRIC = "/pinot-web/telegraf-metric.yml";
+ private final Map definitionIdMap;
+ private final Map> metricIdMap;
+
+ public YMLSystemMetricBasicGroupManager() throws IOException {
+ this(new ClassPathResource(TELEGRAF_METRIC));
+ }
+
+ public YMLSystemMetricBasicGroupManager(Resource telegrafMetric) throws IOException {
+ Objects.requireNonNull(telegrafMetric, "telegrafMetric");
+
+ InputStream stream = telegrafMetric.getInputStream();
+
+ ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+ Mappings mappings = mapper.readValue(stream, Mappings.class);
+ List metrics = mappings.getMappings();
+
+ Map definitionIdMap = new HashMap<>();
+ for (Metric metric : metrics) {
+ Metric exist = definitionIdMap.put(metric.getDefinitionId(), metric);
+ Assert.state(exist == null, "duplicated metric " + metric + " / " + exist);
+ }
+ this.definitionIdMap = definitionIdMap;
+
+
+ Map> metricIdMap = new HashMap<>();
+ for (Metric metric : metrics) {
+ String definitionId = metric.getDefinitionId();
+ metricIdMap.computeIfPresent(metric.getName(), new BiFunction, List>() {
+ @Override
+ public List apply(String metricId, List definitionIdList) {
+ if (definitionIdList == null) {
+ definitionIdList = new ArrayList<>();
+ }
+ definitionIdList.add(definitionId);
+ return definitionIdList;
+ }
+ });
+ }
+ this.metricIdMap = metricIdMap;
+
+ }
+
+ public Metric findElementOfBasicGroup(String metricDefinitionId) {
+ Metric metrics = this.definitionIdMap.get(metricDefinitionId);
+ if (metrics != null) {
+ return metrics;
+ }
+ throw new UnsupportedOperationException("unsupported metric :" + metricDefinitionId);
+ }
+
+ public String findMetricName(String metricDefinitionId) {
+ Metric metrics = this.definitionIdMap.get(metricDefinitionId);
+ if (metrics != null) {
+ return metrics.getName();
+ }
+
+
+ throw new UnsupportedOperationException("unsupported metric :" + metricDefinitionId);
+ }
+
+ public String findMetricTitle(String metricDefinitionId) {
+ Metric metrics = this.definitionIdMap.get(metricDefinitionId);
+ if (metrics != null) {
+ return metrics.getTitle();
+ }
+
+ throw new UnsupportedOperationException("unsupported metric :" + metricDefinitionId);
+ }
+
+ public GroupingRule findGroupingRule(String metricDefinitionId) {
+ Metric metrics = this.definitionIdMap.get(metricDefinitionId);
+ if (metrics != null) {
+ return metrics.getGrouping();
+ }
+ throw new UnsupportedOperationException("unsupported metric :" + metricDefinitionId);
+ }
+
+ public String findUnit(String metricDefinitionId) {
+ Metric metrics = this.definitionIdMap.get(metricDefinitionId);
+ if (metrics != null) {
+ return metrics.getUnit();
+ }
+ throw new UnsupportedOperationException("unsupported metric :" + metricDefinitionId);
+ }
+
+ public List findMetricDefinitionIdList(String metricName) {
+ List definitionId = metricIdMap.get(metricName);
+ if (definitionId != null) {
+ return definitionId;
+ }
+ throw new UnsupportedOperationException("unsupported metric :" + metricName);
+ }
+}
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
new file mode 100644
index 000000000000..30a3c6ff08b7
--- /dev/null
+++ b/metric-module/metric/src/main/resources/pinot-web/telegraf-metric.yml
@@ -0,0 +1,73 @@
+mappings:
+ - definitionId: "cpu"
+ name: "cpu"
+ title: "cpu"
+ grouping: "TAG"
+ unit: "percent"
+ fields:
+ - name: "usage_user"
+ tags:
+ - { name: "cpu", value: "cpu-total" }
+ matchingRule: EXACT
+ - name: "usage_system"
+ tags:
+ - { name: "cpu", value: "cpu-total" }
+ matchingRule: EXACT
+ - name: "usage_idle"
+ tags:
+ - { name: "cpu", value: "cpu-total" }
+ matchingRule: EXACT
+
+ - definitionId: "memoryPercent"
+ name: "mem"
+ title: "memory usage percent"
+ grouping: "TAG"
+ unit: "percent"
+ fields:
+ - name: "used_percent"
+ matchingRule: EXACT
+
+ - definitionId: "memoryUsage"
+ name: "mem"
+ title: "memory usage"
+ grouping: "TAG"
+ unit: "byte"
+ fields:
+ - name: "total"
+ matchingRule: EXACT
+ - name: "used"
+ matchingRule: EXACT
+
+ - definitionId: "diskUsage"
+ name: "disk"
+ title: "disk usage"
+ grouping: "TAG"
+ unit: "byte"
+ fields:
+ - name: "total"
+ matchingRule: ALL
+ - name: "used"
+ matchingRule: ALL
+
+ - definitionId: "diskPercent"
+ name: "disk"
+ title: "disk usage percent"
+ grouping: "TAG"
+ unit: "percent"
+ fields:
+ - name: "used_percent"
+ matchingRule: ALL
+
+ - definitionId: "inodeUsage"
+ name: "disk"
+ title: "inode usage percent"
+ grouping: "TAG"
+ unit: "count"
+ fields:
+ - name: "inodes_total"
+ matchingRule: ALL
+ - name: "inodes_used"
+ matchingRule: ALL
+ - name: "inodes_free"
+ matchingRule: ALL
+
diff --git a/metric-module/metric/src/test/java/com/navercorp/pinpoint/metric/web/mapping/MappingsTest.java b/metric-module/metric/src/test/java/com/navercorp/pinpoint/metric/web/mapping/MappingsTest.java
new file mode 100644
index 000000000000..afaeb98be8bc
--- /dev/null
+++ b/metric-module/metric/src/test/java/com/navercorp/pinpoint/metric/web/mapping/MappingsTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2021 NAVER Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.navercorp.pinpoint.metric.web.mapping;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import com.navercorp.pinpoint.metric.web.model.basic.metric.group.MatchingRule;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+
+public class MappingsTest {
+
+ @Test
+ public void test2() throws IOException {
+ InputStream resource = getClass().getResourceAsStream("/pinot-web/telegraf-metric.yml");
+
+ ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+
+ Mappings mappings = mapper.readValue(resource, Mappings.class);
+ Metric metric = mappings.getMappings().get(0);
+ Assert.assertEquals("cpu", metric.getName());
+ Assert.assertEquals("usage_user", metric.getFields().get(0).getName());
+// Assert.assertEquals("");
+ }
+
+}
\ No newline at end of file