[collector]采集器支持mysql协议指标采集

This commit is contained in:
tomsun28
2022-01-30 12:56:57 +08:00
parent 6a9fe9912f
commit 34458bf468
9 changed files with 118 additions and 8 deletions

View File

@@ -31,7 +31,7 @@
<dependency>
<groupId>com.usthe.tancloud</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
</dependency>
<!-- etcd -->
<dependency>
@@ -84,6 +84,13 @@
<artifactId>aviator</artifactId>
<version>5.2.7</version>
</dependency>
<!--collect-->
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
</dependencies>
</project>

View File

@@ -3,6 +3,7 @@ package com.usthe.collector.dispatch;
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;
import com.usthe.collector.collect.AbstractCollect;
import com.usthe.collector.collect.database.JdbcCommonCollect;
import com.usthe.collector.collect.http.HttpCollectImpl;
import com.usthe.collector.collect.icmp.IcmpCollectImpl;
import com.usthe.collector.collect.telnet.TelnetCollectImpl;
@@ -107,6 +108,9 @@ public class MetricsCollect implements Runnable, Comparable<MetricsCollect> {
case DispatchConstants.PROTOCOL_TELNET:
abstractCollect = TelnetCollectImpl.getInstance();
break;
case DispatchConstants.PROTOCOL_JDBC:
abstractCollect = JdbcCommonCollect.getInstance();
break;
// todo
default: break;
}

View File

@@ -32,7 +32,7 @@ public class JsonPathParser {
* 使用jsonPath来解析json内容
* @param content json内容
* @param jsonPath jsonPath脚本
* @return 解析后的内容
* @return 解析后的内容 [{'name': 'tom', 'speed': '433'},{'name': 'lili', 'speed': '543'}]
*/
public static List<Map<String, Object>> parseContentWithJsonPath(String content, String jsonPath) {
if (content == null || jsonPath == null || "".equals(content) || "".equals(jsonPath)) {

View File

@@ -0,0 +1,31 @@
package com.usthe.collector.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* prometheus-format-text parser
* @author tom
* @date 2022/1/9 14:12
*/
public class PrometheusTextParser {
/**
* 解析prometheusText
* @param content 待解析文本内容
* @return eg:[{'name': 'tom', 'speed': '433'},{'name': 'lili', 'speed': '543'},{'name': 'sam', 'speed': '643'}]
*/
public static Map<String, List<Map<String, Object>>> parsePrometheusText(String content) {
String[] lines = content.split("\n");
Map<String, List<Map<String, Object>>> parseResult = new HashMap<>(8);
for (String lineTmp : lines) {
String line = lineTmp.trim();
if (line.length() == 0 || line.startsWith("#")) {
continue;
}
}
return null;
}
}

View File

@@ -29,6 +29,6 @@ public class Field {
private String unit;
@ApiModelProperty(value = "是否是实例字段", position = 3)
private boolean instance;
private Boolean instance;
}

View File

@@ -49,6 +49,11 @@ public class Message<T> {
this.msg = msg;
}
public Message(byte code, String msg) {
this.code = code;
this.msg = msg;
}
public Message(T data) {
this.data = data;
}

View File

@@ -0,0 +1,39 @@
package com.usthe.common.entity.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
/**
* 历史单指标数据
* @author tom
* @date 2022/1/21 09:58
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "历史单指标数据")
public class MetricsHistoryData {
@ApiModelProperty(value = "监控ID", position = 0)
private Long id;
@ApiModelProperty(value = "监控类型", position = 1)
private String app;
@ApiModelProperty(value = "监控指标组", position = 2)
private String metric;
@ApiModelProperty(value = "监控指标", position = 4)
private Field field;
@ApiModelProperty(value = "监控指标历史值 instance<==>values", position = 5)
private Map<String, List<Value>> values;
}

View File

@@ -23,18 +23,26 @@ public class Value {
this.origin = origin;
}
public Value(String origin, long time) {
this.origin = origin;
this.time = time;
}
@ApiModelProperty(value = "原始值", position = 0)
private String origin;
@ApiModelProperty(value = "平均值", position = 1)
private String mean;
@ApiModelProperty(value = "中位数值", position = 0)
@ApiModelProperty(value = "中位数值,暂不支持", position = 2)
private String median;
@ApiModelProperty(value = "最小值", position = 0)
@ApiModelProperty(value = "最小值", position = 3)
private String min;
@ApiModelProperty(value = "最大值", position = 0)
@ApiModelProperty(value = "最大值", position = 4)
private String max;
@ApiModelProperty(value = "数据采集时间,此字段查历史数据时有效", position = 5)
private Long time;
}

View File

@@ -22,7 +22,7 @@ public class JdbcProtocol {
/**
* 端口号
*/
private Integer port;
private String port;
/**
* 数据库用户名(可选)
*/
@@ -32,7 +32,23 @@ public class JdbcProtocol {
*/
private String password;
/**
* 数据库链接url eg: jdbc:mysql://localhost:3306
* 数据库
*/
private String database;
/**
* 数据库类型 mysql oracle ...
*/
private String platform;
/**
* SQL查询方式 oneRow, multiRow, columns
*/
private String queryType;
/**
* sql
*/
private String sql;
/**
* 数据库链接url eg: jdbc:mysql://localhost:3306/usthe
*/
private String url;
}