Skip to content

Commit

Permalink
[hertzbeat] update use PromQL to collect metrics from promethues serv…
Browse files Browse the repository at this point in the history
…er (#456)
  • Loading branch information
tomsun28 committed Nov 27, 2022
1 parent 24031fe commit e7457cd
Show file tree
Hide file tree
Showing 21 changed files with 645 additions and 417 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.usthe.collector.collect;

import com.usthe.common.entity.job.protocol.ServiceProtocol;
import com.usthe.common.model.ServicePodModel;
import com.usthe.common.entity.job.Metrics;
import com.usthe.common.entity.job.protocol.HttpProtocol;
import com.usthe.common.entity.message.CollectRep;
import org.springframework.beans.factory.InitializingBean;

import java.util.List;
import java.util.Map;


/**
Expand All @@ -31,50 +27,4 @@ public default void parseResponse(String resp, List<String> aliasFields, HttpPro
CollectRep.MetricsData.Builder builder, Long responseTime) {

}

/**
* k8s解析方式
*
* @param metrics
* @param resp
* @param podMap
* @param aliasFields
* @param service
* @param builder
* @param responseTime
*/
public default void parseK8sApi(Metrics metrics, Object resp, Map<String, ServicePodModel> podMap, List<String> aliasFields, ServiceProtocol service,
CollectRep.MetricsData.Builder builder, Long responseTime) {

}

/**
* 微服务响应体解析方法
* @param resp
* @param fields
* @param aliasFields
* @param jsonScript
* @param http
* @param tempcloums
* @param kv
*/
public default void parseResponse(String resp,List<String> fields, List<String> aliasFields ,List<String> jsonScript, HttpProtocol http,
Map<String,List<String>> tempcloums,String kv){

}

/**
* 微服务响应体解析方法
* @param resp
* @param field
* @param aliasField
* @param jsonScript
* @param http
* @param tempcloums
* @param kv
*/
public default void parseResponse(String resp,String field, String aliasField ,String jsonScript, HttpProtocol http,
Map<String,List<String>> tempcloums,String kv){

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public void collect(CollectRep.MetricsData.Builder builder,
parseResponseByDefault(resp, metrics.getAliasFields(), metrics.getHttp(), builder, responseTime);
} else if (DispatchConstants.PARSE_JSON_PATH.equals(parseType)) {
parseResponseByJsonPath(resp, metrics.getAliasFields(), metrics.getHttp(), builder, responseTime);
} else if (DispatchConstants.PARSE_PROMETHEUS.equals(parseType)) {
parseResponseByPrometheus(resp, metrics.getAliasFields(), metrics.getHttp(), builder);
} else if (DispatchConstants.PARSE_PROM_QL.equalsIgnoreCase(parseType)) {
parseResponseByPromQL(resp, metrics.getAliasFields(), metrics.getHttp(), builder);
} else if (DispatchConstants.PARSE_XML_PATH.equals(parseType)) {
parseResponseByXmlPath(resp, metrics.getAliasFields(), metrics.getHttp(), builder);
} else if (DispatchConstants.PARSE_WEBSITE.equals(parseType)){
Expand Down Expand Up @@ -358,8 +358,8 @@ private void parseResponseByJsonPath(String resp, List<String> aliasFields, Http
}
}

private void parseResponseByPrometheus(String resp, List<String> aliasFields, HttpProtocol http,
CollectRep.MetricsData.Builder builder) {
private void parseResponseByPromQL(String resp, List<String> aliasFields, HttpProtocol http,
CollectRep.MetricsData.Builder builder) {
AbstractPrometheusParse prometheusParser = PrometheusParseCreater.getPrometheusParse();
prometheusParser.handle(resp,aliasFields,http,builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PrometheusMatrixParser extends AbstractPrometheusParse {
public Boolean checkType(String responseStr) {
try {
PromVectorOrMatrix promVectorOrMatrix = GsonUtil.fromJson(responseStr, PromVectorOrMatrix.class);
if (DispatchConstants.PARSE_PROMETHEUS_MATRIX.equals(promVectorOrMatrix.getData().getResultType())) {
if (DispatchConstants.PARSE_PROM_QL_MATRIX.equals(promVectorOrMatrix.getData().getResultType())) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PrometheusVectorParser extends AbstractPrometheusParse {
public Boolean checkType(String responseStr) {
try {
PromVectorOrMatrix promVectorOrMatrix = GsonUtil.fromJson(responseStr, PromVectorOrMatrix.class);
if (DispatchConstants.PARSE_PROMETHEUS_VECTOR.equals(promVectorOrMatrix.getData().getResultType())) {
if (DispatchConstants.PARSE_PROM_QL_VECTOR.equals(promVectorOrMatrix.getData().getResultType())) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.util.concurrent.ConcurrentHashMap;

/**
* 数据收集策略工厂
* @author :myth
* @date :Created 2022/7/20 16:19
* @description: 数据收集策略工厂
*/
public class ParseStrategyFactory {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,11 @@
*/
public interface DispatchConstants {

// Protocol type related 协议类型相关 - start //
/**
* protocol http
*/
String PROTOCOL_HTTP = "http";

/**
* protocol 微服务http
*/
String PROTOCOL_HTTP_MICRO = "http_micro";

/**
* protocol icmp
*/
Expand Down Expand Up @@ -72,15 +66,6 @@ public interface DispatchConstants {
* protocol ssl Certificate - custom
*/
String PROTOCOL_SSL_CERT = "ssl_cert";
/**
* protocol 协议 k8s
*/
String PROTOCOL_K8S = "k8s";

/**
* protocol 协议 microService
*/
String PROTOCOL_SERVICE = "service";
// Protocol type related - end
// 协议类型相关 - end //

Expand Down Expand Up @@ -134,31 +119,15 @@ public interface DispatchConstants {
* 解析方式 prometheus规则
*/
String PARSE_PROMETHEUS = "prometheus";
String PARSE_MICRO = "micro";

String PARSE_CHAIN_REQUESTS = "requests";
String PARSE_PROMETHEUS_ACCEPT = "application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1";
String PARSE_PROMETHEUS_VECTOR = "vector";
String PARSE_PROMETHEUS_MATRIX = "matrix";

// http协议相关 - end //
// k8s相关 -- start//
/**
* k8s 解析数据按照获取值的方式
*/
String PARSE_SINGLE = "single";
/**
* k8s 解析数据算数组的大小
*/
String PARSE_GROUP = "group";
// k8s相关 -- end//
// 微服务相关 -- start//
/**
* 参数configParam的key
* prometheus accept header
*/
String CHILD_REQUESTS = "requests";
String PARSE_PROMETHEUS_ACCEPT = "application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1";
/**
* 通用解析链路
* PromQL Prometheus Query Language
* 解析方式 Prometheus Query Language
*/
String PARSE_CHAIN_COMMON = "common";
String PARSE_PROM_QL = "PromQL";
String PARSE_PROM_QL_VECTOR = "vector";
String PARSE_PROM_QL_MATRIX = "matrix";
}
119 changes: 0 additions & 119 deletions collector/src/main/java/com/usthe/collector/util/K8sClient.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit e7457cd

Please sign in to comment.