服务监控

最近更新时间: 2024-09-05 15:09:00

操作场景

该任务指导您使用服务监控功能。

前提条件

开始实践服务监控功能前,请确保已完成了 【SDK 下载】 。

操作步骤

向工程中添加 spring-cloud-tsf-starter 依赖并开启 @EnableTsf 注解 。

注意:

如果您使用的是 1.15.0-Edgware-RELEASE/1.15.0-Finchley-RELEASE 及之前的版本,使用方法参考 【Spring Cloud SDK 历史版本使用方法】 。

Finchley 版本 SDK 相关设置

  1. 向工程中添加依赖。在 pom.xml 中添加以下代码,依赖的是 spring-cloud-tsf-sleuth 而不是 spring-cloud-tsf-monitor
  <dependency>
          <groupid>com.tencent.tsf</groupid>
          <artifactid>spring-cloud-tsf-sleuth</artifactid>
          <version><!-- 调整为 SDK 最新版本号 --></version>
  </dependency>
  1. 向 Application 类中添加注解 @EnableTsfMonitor
 // 下面省略了无关的代码
   import com.tencent.tsf.monitor.annotation.EnableTsfMonitor;
   @SpringBootApplication
   @EnableTsfMonitor
   public class ProviderApplication {
       public static void main(String[] args) {
           SpringApplication.run(ProviderApplication.class, args);
       }
   }