Skip to content

Commit

Permalink
[#noissue] Add telegraf yml mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Oct 5, 2021
1 parent 0860017 commit 89326a8
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 72 deletions.
4 changes: 4 additions & 0 deletions metric-module/metric/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.navercorp.pinpoint.metric.common.model;

import org.springframework.util.StringUtils;

import java.util.Objects;

/**
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Tag> tags;
private final MatchingRule matchingRule;

@JsonCreator
public Field(@JsonProperty("name") String name,
@JsonProperty("tags") List<Tag> tags,
@JsonProperty("matchingRule") MatchingRule matchingRule) {
this.name = Objects.requireNonNull(name, "name");
this.tags = defaultTags(tags);
this.matchingRule = Objects.requireNonNull(matchingRule, "matchingRule");
}

private List<Tag> defaultTags(List<Tag> tags) {
if (tags == null) {
return Collections.emptyList();
}
return tags;
}

public String getName() {
return name;
}

public List<Tag> getTags() {
return tags;
}

public MatchingRule getMatchingRule() {
return matchingRule;
}

@Override
public String toString() {
return "Field{" +
"name='" + name + '\'' +
", tags=" + tags +
", matchingRule=" + matchingRule +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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<Metric> mappings;

@JsonCreator
public Mappings(@JsonProperty("mappings") List<Metric> mappings) {
this.mappings = Objects.requireNonNull(mappings, "mappings");
}

public List<Metric> getMappings() {
return mappings;
}

@Override
public String toString() {
return "Mappings{" +
"groups=" + mappings +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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<Field> 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<Field> 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<Field> getFields() {
return fields;
}

@Override
public String toString() {
return "Metric{" +
"name='" + name + '\'' +
", title='" + title + '\'' +
", definitionId='" + definitionId + '\'' +
", grouping=" + grouping +
", unit='" + unit + '\'' +
", fields=" + fields +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class SystemMetricBasicGroupManager {

static {
//CPU
List<Tag> tagList = new ArrayList<Tag>(1);
List<Tag> tagList = new ArrayList<>(1);
Tag tag = new Tag("cpu", "cpu-total");
tagList.add(tag);

Expand All @@ -103,7 +103,7 @@ public class SystemMetricBasicGroupManager {

static {
//memory usage percent
List<Tag> tagList = new ArrayList<Tag>(0);
List<Tag> tagList = new ArrayList<>(0);

ElementOfBasicGroup memoryUsedPercent = new ElementOfBasicGroup(MEMORY_PERCENT_METRIC_NAME, "used_percent", tagList, MatchingRule.EXACT);
List<ElementOfBasicGroup> elementOfBasicGroupList = new ArrayList<>(1);
Expand All @@ -114,7 +114,7 @@ public class SystemMetricBasicGroupManager {

static {
//memory usage
List<Tag> tagList = new ArrayList<Tag>(0);
List<Tag> 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);
Expand All @@ -127,7 +127,7 @@ public class SystemMetricBasicGroupManager {

static {
//disk usage
List<Tag> tagList = new ArrayList<Tag>(0);
List<Tag> 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<ElementOfBasicGroup> elementOfBasicGroupList = new ArrayList<>(2);
Expand All @@ -139,7 +139,7 @@ public class SystemMetricBasicGroupManager {

static {
//disk usage percent
List<Tag> tagList = new ArrayList<Tag>(0);
List<Tag> tagList = new ArrayList<>(0);
ElementOfBasicGroup diskUsedPercent = new ElementOfBasicGroup(DISK_PERCENT_METRIC_NAME, "used_percent", tagList, MatchingRule.ALL);
List<ElementOfBasicGroup> elementOfBasicGroupList = new ArrayList<>(1);
elementOfBasicGroupList.add(diskUsedPercent);
Expand All @@ -149,7 +149,7 @@ public class SystemMetricBasicGroupManager {

static {
//disk usage
List<Tag> tagList = new ArrayList<Tag>(0);
List<Tag> 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);
Expand Down Expand Up @@ -253,7 +253,7 @@ public String findUnit(String metricDefinitionId) {
}

public List<String> findMetricDefinitionIdList(String metricName) {
List<String> definitionIdList = new LinkedList<String>();
List<String> definitionIdList = new LinkedList<>();
if (CPU_METRIC_NAME.equals(metricName)) {
definitionIdList.add(CPU_DEFINITION_ID);
} else if (MEMORY_METRIC_NAME.equals(metricName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface SystemMetricDataService {

List<SystemMetric> 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);
}
Loading

0 comments on commit 89326a8

Please sign in to comment.