SkyWalking based distributed tracking system - micro-monitoring services

Previous article we build a track based on SkyWalking distributed environment, today to talk about the use of micro SkyWalking monitor our service (DUBBO)

Service Case

Suppose you have a micro-order service, it includes the following components

  • MySQL database partition tables and warehouses (2)
  • Producer (2) dubbo-provider
  • Consumers dubbo-consumer

Network topology is as follows

image

Producers of critical code

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    protected OrderMapper orderMapper;

    @Override
    public OrderVO getById(long id) {
        OrderVO orderVO = new OrderVO();
        Order order = orderMapper.selectById(id);
        BeanUtils.copyProperties(order,orderVO);
        return orderVO;
    }
}
复制代码

Consumers critical code

@RestController
public class OrderController {

    @Reference(retries = 0)
    private OrderService orderService;

    @GetMapping("/order/{id}")
    public OrderVO getOrder(@PathVariable long id){
        return orderService.getById(id);
    }

}
复制代码

Monitor Start

  • Use javaagentstart Producers

    -javaagent:E:\讯飞开发工具\skywalking\agent\skywalking-agent.jar -Dskywalking.agent.service_name=dubbo-provider -Dskywalking.collector.backend_service=192.168.136.129:11800

    -javaagent:E:\讯飞开发工具\skywalking\agent\skywalking-agent.jar -Dskywalking.agent.service_name=dubbo-provider2 -Dskywalking.collector.backend_service=192.168.136.129:11800

  • Start Consumers
    -javaagent:E:\讯飞开发工具\skywalking\agent\skywalking-agent.jar -Dskywalking.agent.service_name=dubbo-consumer -Dskywalking.collector.backend_service=192.168.136.129:11800

  • Analog request
    access in a browser http://localhost:9090/order/1184489161562816511, make multiple calls to load into force; modify the order id parameter, so call covering different databases

  • See the effect of
    access skywalking monitoring address http://192.168.136.129:8080/to view the monitoring results

    image
    dash board
    image
    Network topology
    image
    Error Log
    image
    Trace inquiry

Log Integration

In this section we look at the principles call chain:

  • Request arrives generate a global TraceID, through the whole series from TraceID can call chain, a TraceID on behalf of a request.
  • In addition to TraceID, but also you need to record calls SpanID parent-child relationships. Each service will record the Parent id and Span id, they can organize parent-child relationships through a complete call chain.
  • To view a complete call times to detect any calls as long as records according to TraceID, then the entire call parent-child relationship by Parent id and Span id organized.

It is because of TraceID so important, so we hope TraceID the call chain can output in a log file, once observed abnormal call us directly in the search log analysis platform TraceID logs can be retrieved associated with all greatly enhance our problem-solving efficiency.

Integration process (log4j2)

  • The introduction of the log package log4j2

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    复制代码
  • Introducing SW Kit

     <!--SW trace 跟踪-->
    <dependency>
        <groupId>org.apache.skywalking</groupId>
        <artifactId>apm-toolkit-log4j-2.x</artifactId>
        <version>6.4.0</version>
    </dependency>
    复制代码
  • Change Log display format log4j2.xml
    %d [%traceId] %-5p %c{1}:%L - %m%n

  • Start the application, watch the console

    image

    Just started when the acquisition is less than TraceID, so TID is displayed as N / A, calls the request after it starts again watch the console, find logs on all links are marked TraceID.

    image

Very simple steps let you add a call to the micro-service chain monitoring, why do not you try it?

Related articles:
based SkyWalking distributed tracking system - built environment

SpringBoot2.1.9 + dubbo2.7.3 + Nacos1.1.4 build your micro-service system

For more information, please public concern number: JAVA Rizhilu

Micro-channel public number

Guess you like

Origin juejin.im/post/5dc368216fb9a04ab462a0a2