Rpc 調用監控
Skywalking(6.5.0) 支持的Rpc框架有以下幾種:
Dubbo 2.5.4 -> 2.6.0
Dubbox 2.8.4
Apache Dubbo 2.7.0
Motan 0.2.x -> 1.1.0
gRPC 1.x
Apache ServiceComb Java Chassis 0.1 -> 0.5,1.0.x
SOFARPC 5.4.0
使用Spring Boot和Dubbo搭建一個簡單的服務提供方和服務消費方來測試Skywalking對於Rpc調用的支持。可以使用資源文件夾下已經完成打包的 skywalking_dubbo_consumer.jar 和skywalking_dubbo_provider.jar 來進行測試。
服務提供方
pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.itcast</groupId>
<artifactId>skywalking_dubbo_provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>skywalking_dubbo_provider</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--添加springboot和dubbo集成配置-->
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties:
spring.application.name=skywalking_dubbo_provider
spring.dubbo.server=true
spring.dubbo.registry=N/A
server.port=8086
IHelloService接口:
public interface IHelloService {
public String hello();
}
HelloServiceImpl實現類:
@Service(interfaceClass = IHelloService.class)
@Component
public class HelloServiceImpl implements IHelloService {
@Override
public String hello() {
return "hello skywalking";
}
}
SkywalkingDubboProviderApplication啟動類:
@SpringBootApplication
//添加dubbo生效注解
@EnableDubboConfiguration
public class SkywalkingDubboProviderApplication {
public static void main(String[] args) {
SpringApplication.run(SkywalkingDubboProviderApplication.class, args);
}
}
服務消費方
pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.itcast</groupId>
<artifactId>skywalking_dubbo_consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>skywalking_dubbo_consumer</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties:
spring.application.name=skywalking_dubbo_consumer
server.port=8085
IHelloService接口:
public interface IHelloService {
public String hello();
}
TestController:
@RestController
public class TestController {
@Reference(url = "dubbo://127.0.0.1:20880")
private IHelloService helloService;
@GetMapping("/hello")
public String hello(){
return helloService.hello();
}
}
SkywalkingDubboConsumerApplication啟動類:
@SpringBootApplication
//添加dubbo生效注解
@EnableDubboConfiguration
public class SkywalkingDubboConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(SkywalkingDubboConsumerApplication.class, args);
}
}
部署方式
1、將 skywalking_dubbo_consumer.jar 和 skywalking_dubbo_provider.jar 上傳
至 /usr/local/skywalking 目錄下。
2、首先我們復制兩份agent,防止使用的沖突。
3 、先啟動provider,等待啟動成功。
[root@middleware skywalking-jar]# ll
總用量 58868
-rw-r--r--. 1 root root 21705956 11月 23 15:59 skywalking_dubbo_consumer.jar
-rw-r--r--. 1 root root 21705951 11月 23 15:59 skywalking_dubbo_provider.jar
-rw-r--r--. 1 root root 16862447 11月 23 16:33 skywalking_springboot.jar
[root@middleware skywalking-jar]# java -javaagent:/root/apache-skywalking-apm-bin/agent-dubbo-provider/skywalking-agent.jar -jar skywalking_dubbo_provider.jar &
[1] 103225
[root@middleware skywalking-jar]# DEBUG 2020-11-24 09:25:02:285 main AgentPackagePath : The beacon class location is jar:file:/root/apache-skywalking-apm-bin/agent-dubbo-provider/skywalking-agent.jar!/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.class.
INFO 2020-11-24 09:25:02:290 main SnifferConfigInitializer : Config file found in /root/apache-skywalking-apm-bin/agent-dubbo-provider/config/agent.config.
2020-11-24 09:25:09.426 INFO 103225 --- [ main] c.a.dubbo.common.logger.LoggerFactory : using logger: com.alibaba.dubbo.common.logger.slf4j.Slf4jLoggerAdapter
████████▄ ███ █▄ ▀█████████▄ ▀█████████▄ ▄██████▄
███ ▀███ ███ ███ ███ ███ ███ ███ ███ ███
███ ███ ███ ███ ███ ███ ███ ███ ███ ███
███ ███ ███ ███ ▄███▄▄▄██▀ ▄███▄▄▄██▀ ███ ███
███ ███ ███ ███ ▀▀███▀▀▀██▄ ▀▀███▀▀▀██▄ ███ ███
███ ███ ███ ███ ███ ██▄ ███ ██▄ ███ ███
███ ▄███ ███ ███ ███ ███ ███ ███ ███ ███
████████▀ ████████▀ ▄█████████▀ ▄█████████▀ ▀██████▀
:: Dubbo :: (v2.6.0)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.10.RELEASE)
2020-11-24 09:25:09.972 INFO 103225 --- [ main] c.i.s.SkywalkingDubboProviderApplication : Starting SkywalkingDubboProviderApplication v0.0.1-SNAPSHOT on middleware with PID 103225 (/root/skywalking-jar/skywalking_dubbo_provider.jar started by root in /root/skywalking-jar)
2020-11-24 09:25:09.973 INFO 103225 --- [ main] c.i.s.SkywalkingDubboProviderApplication : No active profile set, falling back to default profiles: default
2020-11-24 09:25:13.540 INFO 103225 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.dubbo-com.alibaba.dubbo.spring.boot.DubboProperties' of type [com.alibaba.dubbo.spring.boot.DubboProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-11-24 09:25:13.544 INFO 103225 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'com.alibaba.dubbo.spring.boot.DubboConsumerAutoConfiguration' of type [com.alibaba.dubbo.spring.boot.DubboConsumerAutoConfiguration$$EnhancerBySpringCGLIB$$30931a08] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
出現如圖所示內容,應用就已經啟動成功了。
4、啟動consumer,等待啟動成功。
[root@middleware skywalking-jar]# java -javaagent:/root/apache-skywalking-apm-bin/agent-dubbo-consumer/skywalking-agent.jar -jar skywalking_dubbo_consumer.jar &
[2] 104390
[root@middleware skywalking-jar]# DEBUG 2020-11-24 09:26:11:178 main AgentPackagePath : The beacon class location is jar:file:/root/apache-skywalking-apm-bin/agent-dubbo-consumer/skywalking-agent.jar!/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.class.
INFO 2020-11-24 09:26:11:180 main SnifferConfigInitializer : Config file found in /root/apache-skywalking-apm-bin/agent-dubbo-consumer/config/agent.config.
2020-11-24 09:26:17.377 INFO 104390 --- [ main] c.a.dubbo.common.logger.LoggerFactory : using logger: com.alibaba.dubbo.common.logger.slf4j.Slf4jLoggerAdapter
████████▄ ███ █▄ ▀█████████▄ ▀█████████▄ ▄██████▄
███ ▀███ ███ ███ ███ ███ ███ ███ ███ ███
███ ███ ███ ███ ███ ███ ███ ███ ███ ███
███ ███ ███ ███ ▄███▄▄▄██▀ ▄███▄▄▄██▀ ███ ███
███ ███ ███ ███ ▀▀███▀▀▀██▄ ▀▀███▀▀▀██▄ ███ ███
███ ███ ███ ███ ███ ██▄ ███ ██▄ ███ ███
███ ▄███ ███ ███ ███ ███ ███ ███ ███ ███
████████▀ ████████▀ ▄█████████▀ ▄█████████▀ ▀██████▀
:: Dubbo :: (v2.6.0)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.10.RELEASE)
2020-11-24 09:26:17.863 INFO 104390 --- [ main] c.i.s.SkywalkingDubboConsumerApplication : Starting SkywalkingDubboConsumerApplication v0.0.1-SNAPSHOT on middleware with PID 104390 (/root/skywalking-jar/skywalking_dubbo_consumer.jar started by root in /root/skywalking-jar)
2020-11-24 09:26:17.864 INFO 104390 --- [ main] c.i.s.SkywalkingDubboConsumerApplication : No active profile set, falling back to default profiles: default
2020-11-24 09:26:21.627 INFO 104390 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.dubbo-com.alibaba.dubbo.spring.boot.DubboProperties' of type [com.alibaba.dubbo.spring.boot.DubboProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-11-24 09:26:21.631 INFO 104390 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'com.alibaba.dubbo.spring.boot.DubboConsumerAutoConfiguration' of type [com.alibaba.dubbo.spring.boot.DubboConsumerAutoConfiguration$$EnhancerBySpringCGLIB$$a56fb0dc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-11-24 09:26:22.692 INFO 104390 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8085 (http)
2020-11-24 09:26:22.758 INFO 104390 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-11-24 09:26:22.758 INFO 104390 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2020-11-24 09:26:22.948 INFO 104390 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-11-24 09:26:22.948 INFO 104390 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4941 ms
5 、調用接口,接口地址為: http://192.168.1.106:8085/hello
6、此時如果頁面顯示
那么 dubbo的調用就成功了。
7、打開skywalking查看dubbo調用的監控情況。
儀表盤:
目前 dubbo_provider 和 dubbo_consumer 的服務已經出現,同時出現了兩個接口分別是:/hello 接口,是瀏覽器調用dubb_consumer的http接口
com.itcast.api.IHelloService.hello() 是dubbo_consumer調用dubbo_provider的dubbo接口
拓撲圖:
該圖中已經表示出了一個調用的鏈路關系:User(瀏覽器) ----> dubber_consumer ----> dubbo_provider並且在服務的上方標識出了每個服務代表的內容,dubbo_consumer是SpringMvc的服務,而dubbo_provider是Dubbo的服務。
追蹤:
MySql 調用監控
Spring Data JDBC訪問Mysql
創建一個Spring Boot工程,集成Spring Data JDBC。可以直接使用資源文件中提供的skywalking_mysql.jar 。
pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.itcast</groupId>
<artifactId>skywalking_mysql</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>skywalking_mysql</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
pojo類:
@Table("t_user")
public class User {
@Id
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
dao接口:
public interface UserRepository extends CrudRepository<User, Integer> {
}
controller:
@RestController
public class MysqlController {
@Autowired
private UserRepository userRepository;
@GetMapping("/users")
public List<User> findAll(){
List<User> result = new ArrayList<>();
//使用迭代器進行遍歷
userRepository.findAll().forEach((user) -> {
result.add(user);
});
return result;
}
}
啟動類:
@SpringBootApplication
public class SkywalkingMysqlApplication {
public static void main(String[] args) {
SpringApplication.run(SkywalkingMysqlApplication.class, args);
}
}
application.properties:
spring.datasource.url=jdbc:mysql://localhost:33306/skywalking
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
server.port=8087
部署方式
1、將 skywalking_mysql.jar 上傳至 /usr/local/skywalking 目錄下。
2、首先我們復制agent,防止使用的沖突。
啟動:
[root@middleware skywalking-jar]# DEBUG 2020-11-24 10:50:13:449 main AgentPackagePath : The beacon class location is jar:file:/root/apache-skywalking-apm-bin/agent-mysql/skywalking-agent.jar!/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.class.
INFO 2020-11-24 10:50:13:454 main SnifferConfigInitializer : Config file found in /root/apache-skywalking-apm-bin/agent-mysql/config/agent.config.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.10.RELEASE)
2020-11-24 10:50:20.290 INFO 46783 --- [ main] c.i.s.SkywalkingMysqlApplication : Starting SkywalkingMysqlApplication v0.0.1-SNAPSHOT on middleware with PID 46783 (/root/skywalking-jar/skywalking_mysql.jar started by root in /root/skywalking-jar)
2020-11-24 10:50:20.295 INFO 46783 --- [ main] c.i.s.SkywalkingMysqlApplication : No active profile set, falling back to default profiles: default
2020-11-24 10:50:22.305 INFO 46783 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-11-24 10:50:22.464 INFO 46783 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 147ms. Found 1 repository interfaces.
2020-11-24 10:50:23.324 INFO 46783 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$f4361a45] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-11-24 10:50:24.094 INFO 46783 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http)
2020-11-24 10:50:24.155 INFO 46783 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-11-24 10:50:24.155 INFO 46783 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2020-11-24 10:50:24.335 INFO 46783 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-11-24 10:50:24.336 INFO 46783 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3910 ms
2020-11-24 10:50:25.524 INFO 46783 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-11-24 10:50:26.155 INFO 46783 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8087 (http) with context path ''
2020-11-24 10:50:26.159 INFO 46783 --- [ main] c.i.s.SkywalkingMysqlApplication : Started SkywalkingMysqlApplication in 7.697 seconds (JVM running for 13.111)
2020-11-24 10:50:58.918 INFO 46783 --- [nio-8087-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-11-24 10:50:58.918 INFO 46783 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-11-24 10:50:58.951 INFO 46783 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 32 ms
2020-11-24 10:50:59.280 INFO 46783 --- [nio-8087-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
4 、調用接口,接口地址為: http:/192.168.1.106:8087/users
5、此時如果頁面顯示
那么 mysql的調用就成功了。
6、打開skywalking查看mysql調用的監控情況。
服務儀表盤:
數據庫儀表盤:
點擊數據庫儀表盤可以看到詳細的數據庫響應時長、吞吐量、 SLA等數據。
拓撲圖:
該圖中已經表示出了一個調用的鏈路關系:User(瀏覽器) ----> skywalking_mysql ----> localhost:3306並且在服務的上方標識出了每個服務代表的內容,skywalking_mysql是SpringMvc的服務,而localhost:3306是mysql的服務。
追蹤:
追蹤圖中顯示本次調用耗時 22ms,其中spring MVC接口耗時19ms,那么另外的3ms是調用Mysql的耗時。
點擊mysql的調用,可以看到詳細的sql語句。
這樣可以很好的定位問題產生的原因,特別是在某些 sql語句執行慢的場景下。