Skywalking的调用监控

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,防止使用的冲突。

image-20201124141418709

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、此时如果页面显示

image-20201124144539652

那么 dubbo的调用就成功了。
7、打开skywalking查看dubbo调用的监控情况。
仪表盘:

image-20201124141713123

目前 dubbo_provider 和 dubbo_consumer 的服务已经出现,同时出现了两个接口分别是:/hello 接口,是浏览器调用dubb_consumer的http接口
com.itcast.api.IHelloService.hello() 是dubbo_consumer调用dubbo_provider的dubbo接口
拓扑图:

image-20201124141742109

该图中已经表示出了一个调用的链路关系:User(浏览器) ----> dubber_consumer ----> dubbo_provider并且在服务的上方标识出了每个服务代表的内容,dubbo_consumer是SpringMvc的服务,而dubbo_provider是Dubbo的服务。
追踪:

image-20201124141851454

MySql 调用监控

image-20201124143227544

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,防止使用的冲突。

image-20201124143653784

启动:

[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、此时如果页面显示

image-20201124143803894

那么 mysql的调用就成功了。
6、打开skywalking查看mysql调用的监控情况。
服务仪表盘:

image-20201124144057517

数据库仪表盘:

image-20201124144121271

点击数据库仪表盘可以看到详细的数据库响应时长、吞吐量、 SLA等数据。
拓扑图:

image-20201124144213721

该图中已经表示出了一个调用的链路关系:User(浏览器) ----> skywalking_mysql ----> localhost:3306并且在服务的上方标识出了每个服务代表的内容,skywalking_mysql是SpringMvc的服务,而localhost:3306是mysql的服务。

追踪:

image-20201124144301810

追踪图中显示本次调用耗时 22ms,其中spring MVC接口耗时19ms,那么另外的3ms是调用Mysql的耗时。
点击mysql的调用,可以看到详细的sql语句。

image-20201124144323764

这样可以很好的定位问题产生的原因,特别是在某些 sql语句执行慢的场景下。

posted @ 2020-11-24 14:52  天宇轩-王  阅读(1947)  评论(0编辑  收藏  举报