spring cloud 使用zipkin日誌監控

  1. 建立項目加入maven依賴,這是一個web項目,所以也加入spring boot web依賴,一般情況會與註冊中心配合使用,需要的可以加入註冊中心客戶端依賴
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>2.12.0</version>
        </dependency>
  1. 日誌監控啓動類
@SpringBootApplication
@EnableEurekaClient
@EnableZipkinServer
public class ZipkinApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZipkinApplication.class, args);
    }

}

3.application.yml

server:
  port: 9411
spring:
  application:
    name: zipkin-server
  profiles:
    active: dev
management:
  metrics:
    web:
      server:
        auto-time-requests: false

eureka:
  client:
    service-url:
      defaultZone: http://root:zxy2019@192.168.2.90:8001/eureka/
  instance:
    hostname: ${spring.cloud.client.ip-address}
    instance-id: ${eureka.instance.hostname}:${server.port}
    prefer-ip-address: true

客戶端服務調用
6. 添加maven依賴

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin</artifactId>
        </dependency>
  1. zipkin配置文件
spring:
  sleuth:
    sampler:
      probability: 1.0 #日誌採集頻率,最高1.0全部收集,可以爲小數20.01,就是1%
#開放監控端點
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章