如何追踪MySQL访问?

  • 引入所需插件
<!-- jdbc插件,监控所有的jdbc调用 -->
<dependency>
    <groupId>com.ai.cloud</groupId>
    <artifactId>skywalking-jdbc-plugin</artifactId>
    <version>{latest_version}</version>
</dependency>
  • 设置特定的JDBC Driver
Driver="com.ai.cloud.skywalking.plugin.jdbc.mysql.MySQLTracingDriver"
  • 设置特定的JDBC URL
jdbc.url=tracing:jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8

如何追踪MySQL之外的其他JDBC?

  • 引入所需插件
<!-- jdbc插件,监控所有的jdbc调用 -->
<dependency>
    <groupId>com.ai.cloud</groupId>
    <artifactId>skywalking-jdbc-plugin</artifactId>
    <version>{latest_version}</version>
</dependency>
  • 轻松实现自定义的JDBC Driver扩展
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.ai.cloud.skywalking.plugin.jdbc.TracingDriver;

public class XXXDBTracingDriver extends TracingDriver {
	static {
		try {
			DriverManager.registerDriver(new XXXDBTracingDriver());
		} catch (SQLException e) {
			throw new RuntimeException("register "
					+ MySQLTracingDriver.class.getName() + " driver failure.");
		}
	}

	/**
	 * 继承自TracingDriver,返回真实的Driver
	 */
	@Override
	protected Driver registerTracingDriver() {
		try {
			//示例:return new com.mysql.jdbc.Driver();
			return new Driver();
		} catch (SQLException e) {
			throw new RuntimeException("create Driver failure.");
		}
	}
}
  • 设置新实现的JDBC Driver
Driver="XXXDBTracingDriver"
  • 设置特定的JDBC URL
jdbc.url=tracing:jdbc:xxxdb://localhost:3306/test