Skip to content

Commit

Permalink
增加SpringCloud指标采集
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbingleixue committed Jan 10, 2024
1 parent 81edb23 commit f4f87f9
Show file tree
Hide file tree
Showing 34 changed files with 1,287 additions and 500 deletions.
41 changes: 41 additions & 0 deletions sermant-plugins/sermant-metrics/metrics-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<alibaba.dubbo.version>2.5.7</alibaba.dubbo.version>
<apache.dubbo.version>2.7.3</apache.dubbo.version>
<servlet-api.version>4.0.1</servlet-api.version>
<httpclient.version>4.5.13</httpclient.version>
<okhttp.version>2.7.5</okhttp.version>
<okhtt3.version>4.1.0</okhtt3.version>
<javax-servlet-api.version>3.0.1</javax-servlet-api.version>
<jsqlparser.version>4.4</jsqlparser.version>
<mysql.version>8.0.28</mysql.version>
</properties>
<dependencies>
<!--Provider依赖-->
Expand All @@ -40,6 +46,41 @@
<version>${apache.dubbo.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhtt3.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax-servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>${jsqlparser.version}</version>
</dependency>
<!--test依赖-->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ public class Constants {
*/
public static final String SSL_ENABLE = "sslEnabled";

/**
* 服务调用使用的CLIENT下表字段名
*/
public static final String CLIENT_INDEX = "index";

/**
* CLIENT集合名称
*/
public static final String CLIENTS_NAME = "clients";

/**
* DUBBO TCP协议集合
*/
Expand All @@ -81,12 +71,12 @@ public class Constants {
/**
* 连接信息头
*/
public static final String LINK_HEAD = "sermant_l7_link";
public static final String RPC_HEADER = "sermant_l7_rpc";

/**
* 连接信息头
* API连接信息头
*/
public static final String RPC_HEAD = "sermant_l7_rpc";
public static final String RPC_API_HEADER = "sermant_l7_rpc_api";

/**
* SSL开启标识
Expand All @@ -103,50 +93,50 @@ public class Constants {
*/
public static final String CONSUMER_SIDE = "consumer";

/**
* 提供者标识
*/
public static final String PROVIDER_SIDE = "provider";

/**
* 客户端 服务端标识的KEY
*/
public static final String SIDE_KEY = "side";

/**
* 字符串写下标保存到context局部变量中的key
* RPC信息保存到context局部变量中的key
*/
public static final String WRITE_INDEX_KEY = "writeIndex";
public static final String RPC_INFO_KEY = "rpcInfo";

/**
* 字符串读下标保存到context局部变量中的key
* 服务调用开始时间保存到context局部变量中的key
*/
public static final String READ_INDEX_KEY = "readIndex";
public static final String START_TIME_KEY = "startTime";

/**
* 连接信息保存到context局部变量中的key
* 异常线程ID
*/
public static final String LINK_INFO_KEY = "linkInfo";
public static final String EXCEPTION_PID = "-1";

/**
* RPC信息保存到context局部变量中的key
* 指标值的连接符
*/
public static final String RPC_INFO_KEY = "rpcInfo";
public static final String METRICS_LINK = "|";

Check warning on line 120 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/Constants.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议3.7 行末或空行不能有空格, 请去除多余空格 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/Constants.java:120:0: warning: 编程规范-建议3.7 行末或空行不能有空格, 请去除多余空格 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
/**
* HTTPS协议
*/
public static final String HTTPS_PROTOCOL = "https";

/**
* 服务调用开始时间保存到context局部变量中的key
* 最大成功响应编码
*/
public static final String START_TIME_KEY = "startTime";
public static final int MAX_SUCCESS_CODE = 399;

/**
* 异常线程ID
* 最大客户端失败编码
*/
public static final String EXCEPTION_PID = "-1";
public static final int MAX_CLIENT_ERROR_CODE = 499;

/**
* 指标值的连接符
* 最大服务端失败编码
*/
public static final String METRICS_LINK = "|";
public static final int MAX_SERVER_ERROR_CODE = 599;

private Constants() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* 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.huawei.metrics.common;

/**
* 结果类型
*
* @author zhp
* @since 2023-12-15
*/
public enum ResultType {
SUCCESS(0),

Check failure on line 26 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java:26:5: error: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck)
CLIENT_ERROR(1),

Check failure on line 27 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java:27:5: error: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck)
SERVER_ERROR(2),

Check failure on line 28 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java:28:5: error: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck)
ERROR(3);

Check failure on line 29 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java:29:5: error: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck)

private final int value;

ResultType(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;

/**
* dubbo报文转码、解码增强声明
* dubbo2.6.x报文转码、解码增强声明
*
* @author zhp
* @since 2023-10-17
*/
public class ExchangeCodecDeclarer extends AbstractDeclarer {
private static final String ENHANCE_CLASS = "com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec";

private static final String ENCODE_METHODS_NAMES = "encode";

private static final String DECODE_METHODS_NAMES = "decode";

private static final int ENCODE_PARAM_COUNT = 3;
private static final String DECODE_METHODS_NAMES = "decodeBody";

private static final int DECODE_PARAM_COUNT = 2;

Expand All @@ -47,10 +43,8 @@ public ClassMatcher getClassMatcher() {

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{InterceptDeclarer.build(MethodMatcher.nameEquals(ENCODE_METHODS_NAMES)
.and(MethodMatcher.paramCountEquals(ENCODE_PARAM_COUNT)), new ExchangeCodecInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals(DECODE_METHODS_NAMES)
.and(MethodMatcher.paramCountEquals(DECODE_PARAM_COUNT)), new ExchangeCodecInterceptor())
return new InterceptDeclarer[]{InterceptDeclarer.build(MethodMatcher.nameEquals(DECODE_METHODS_NAMES)
.and(MethodMatcher.paramCountEquals(DECODE_PARAM_COUNT)), new ExchangeCodecInterceptor())
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;

/**
* dubbo监控过滤器增强声明
* dubbo2.6.x监控过滤器增强声明
*
* @author zhp
* @since 2023-10-17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;

/**
* dubbo报文转码、解码增强声明
* dubbo2.7.x报文转码、解码增强声明
*
* @author zhp
* @since 2023-10-17
*/
public class ExchangeCodecDeclarer extends AbstractDeclarer {
private static final String ENHANCE_CLASS = "org.apache.dubbo.remoting.exchange.codec.ExchangeCodec";

private static final String ENCODE_METHODS_NAMES = "encode";

private static final String DECODE_METHODS_NAMES = "decode";

private static final int ENCODE_PARAM_COUNT = 3;
private static final String DECODE_METHODS_NAMES = "decodeBody";

private static final int DECODE_PARAM_COUNT = 2;

Expand All @@ -47,10 +43,8 @@ public ClassMatcher getClassMatcher() {

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{InterceptDeclarer.build(MethodMatcher.nameEquals(ENCODE_METHODS_NAMES)
.and(MethodMatcher.paramCountEquals(ENCODE_PARAM_COUNT)), new ExchangeCodecInterceptor()),
InterceptDeclarer.build(MethodMatcher.nameEquals(DECODE_METHODS_NAMES)
.and(MethodMatcher.paramCountEquals(DECODE_PARAM_COUNT)), new ExchangeCodecInterceptor())
return new InterceptDeclarer[]{InterceptDeclarer.build(MethodMatcher.nameEquals(DECODE_METHODS_NAMES)
.and(MethodMatcher.paramCountEquals(DECODE_PARAM_COUNT)), new ExchangeCodecInterceptor())
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;

/**
* dubbo监控过滤器增强声明
* dubbo2.7.x监控过滤器增强声明
*
* @author zhp
* @since 2023-10-17
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* 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.huawei.metrics.declarer.httpclient;

import com.huawei.metrics.declarer.AbstractDeclarer;
import com.huawei.metrics.interceptor.httpclient.HttpClientInterceptor;

import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer;
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher;
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;

/**
* HttpClient4.x请求方法拦截声明
*
* @author zhp
* @since 2023-12-15
*/
public class HttpClientDeclarer extends AbstractDeclarer {
/**
* 增强类的全限定名 http请求
*/
private static final String[] ENHANCE_CLASSES = {
"org.apache.http.impl.client.AbstractHttpClient",
"org.apache.http.impl.client.DefaultRequestDirector",
"org.apache.http.impl.client.InternalHttpClient",
"org.apache.http.impl.client.MinimalHttpClient"
};

@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.nameContains(ENHANCE_CLASSES);
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
InterceptDeclarer.build(MethodMatcher.nameContains("doExecute", "execute")
.and(MethodMatcher.paramTypesEqual(
"org.apache.http.HttpHost",
"org.apache.http.HttpRequest",
"org.apache.http.protocol.HttpContext")),
new HttpClientInterceptor())
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* 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.huawei.metrics.declarer.httpurlconnection;

import com.huawei.metrics.declarer.AbstractDeclarer;
import com.huawei.metrics.interceptor.httpurlconnection.ConnectorInterceptor;

import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer;
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher;
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;

/**
* HttpURLConnection1.7.x+链接方法拦截声明
*
* @author zhp
* @since 2023-12-15
*/
public class ConnectDeclarer extends AbstractDeclarer {
private static final String ENHANCE_CLASS = "sun.net.www.protocol.http.HttpURLConnection";

@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.nameEquals(ENHANCE_CLASS);
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
InterceptDeclarer.build(MethodMatcher.nameEquals("connect"),
new ConnectorInterceptor())
};
}
}
Loading

0 comments on commit f4f87f9

Please sign in to comment.