Skip to content

Commit

Permalink
增加SpringCloud指标采集
Browse files Browse the repository at this point in the history
Signed-off-by: hanbingleixue <[email protected]>
  • Loading branch information
hanbingleixue committed Jan 11, 2024
1 parent 81edb23 commit c83aa32
Show file tree
Hide file tree
Showing 34 changed files with 1,353 additions and 514 deletions.
44 changes: 43 additions & 1 deletion sermant-plugins/sermant-metrics/metrics-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
<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依赖-->
<!--provided依赖-->
<dependency>
<groupId>com.huaweicloud.sermant</groupId>
<artifactId>sermant-agentcore-core</artifactId>
Expand All @@ -40,6 +46,42 @@
<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>
<!--SQL解析第三方依赖-->
<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 @@ -104,49 +94,74 @@ public class Constants {
public static final String CONSUMER_SIDE = "consumer";

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

/**
* 客户端 服务端标识的KEY
* RPC信息保存到context局部变量中的key
*/
public static final String SIDE_KEY = "side";
public static final String RPC_INFO_KEY = "rpcInfo";

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

/**
* 字符串读下标保存到context局部变量中的key
* 异常线程ID
*/
public static final String READ_INDEX_KEY = "readIndex";
public static final String EXCEPTION_PID = "-1";

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

/**
* RPC信息保存到context局部变量中的key
* HTTPS协议
*/
public static final String RPC_INFO_KEY = "rpcInfo";
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;

/**
* MYSQL 客户端异常编码
*/
public static final int[][] MYSQL_CLIENT_ERROR = {{1, 999}, {2000, 2999}};

/**
* MYSQL 服务服务端编码
*/
public static final int[][] MYSQL_SERVER_ERROR = {{1000, 1999}, {3000, 4000}};

/**
* dubbo请求成功
*/
public static final byte DUBBO_OK = 20;

/**
* dubbo客户端异常编码
*/
public static final byte[] DUBBO_CLIENT_ERROR = {30, 40, 90};

/**
* dubbo服务端异常编码
*/
public static final byte[] DUBBO_SERVER_ERROR = {31, 80, 50, 60, 70, 100};

private Constants() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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),

/**
* 客户端错误
*/
CLIENT_ERROR(1),

/**
* 服务端错误
*/
SERVER_ERROR(2),

/**
* 请求失败
*/
ERROR(3);

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 @@ -17,26 +17,22 @@
package com.huawei.metrics.declarer.alibaba;

import com.huawei.metrics.declarer.AbstractDeclarer;
import com.huawei.metrics.interceptor.alibaba.ExchangeCodecInterceptor;
import com.huawei.metrics.interceptor.dubbo.alibaba.ExchangeCodecInterceptor;

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;

/**
* 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 @@ -17,14 +17,14 @@
package com.huawei.metrics.declarer.alibaba;

import com.huawei.metrics.declarer.AbstractDeclarer;
import com.huawei.metrics.interceptor.alibaba.MonitorFilterInterceptor;
import com.huawei.metrics.interceptor.dubbo.alibaba.MonitorFilterInterceptor;

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;

/**
* dubbo监控过滤器增强声明
* dubbo2.6.x监控过滤器增强声明
*
* @author zhp
* @since 2023-10-17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@
package com.huawei.metrics.declarer.apache;

import com.huawei.metrics.declarer.AbstractDeclarer;
import com.huawei.metrics.interceptor.apache.ExchangeCodecInterceptor;
import com.huawei.metrics.interceptor.dubbo.apache.ExchangeCodecInterceptor;

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;

/**
* 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 @@ -17,14 +17,14 @@
package com.huawei.metrics.declarer.apache;

import com.huawei.metrics.declarer.AbstractDeclarer;
import com.huawei.metrics.interceptor.apache.MonitorFilterInterceptor;
import com.huawei.metrics.interceptor.dubbo.apache.MonitorFilterInterceptor;

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;

/**
* dubbo监控过滤器增强声明
* dubbo2.7.x监控过滤器增强声明
*
* @author zhp
* @since 2023-10-17
Expand Down
Loading

0 comments on commit c83aa32

Please sign in to comment.