欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Kite的学习历程SpringCloud之Sentinel监控初步使用

程序员文章站 2022-06-06 14:41:15
...

Kite学习历程的第二十九天

1.sentinel安装

1.1 下载

大部分都是在Github上进行下载,但是下载速度巨慢,而且有时下到一般会出现错误。所以我们可以在百度网盘找资源进行下载

1.2 运行

在cmd控制台输入:java -jar 文件名 进行运行
Kite的学习历程SpringCloud之Sentinel监控初步使用

1.3 进行访问

访问:localhost:8080
账号密码都为:sentinel
Kite的学习历程SpringCloud之Sentinel监控初步使用

2. 创建测试微服务cloudalibaba-sentinel-serverice8401

2.1 修改pom.xml引入依赖文件


<dependencies>
        <!--nacos依赖的引入-->

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!--后续做持久化会被用到-->
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-datasource-nacos</artifactId>
        </dependency>


        <!--SpringCloud ailibaba sentinel -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        <!--openfeign-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <!--引入自己创建的entities包-->
        <dependency>
            <groupId>cn.kitey.spring</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!-- SpringBoot整合Web组件+actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--日常通用jar包配置-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>4.6.3</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

2.2 创建application.yml配置文件

sentinel:配置在让其受到监控

server:
  port: 8401

spring:
  application:
    name: cloudalibaba-sentinel-service
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    sentinel:
      transport:
        dashboard: localhost:8080 #配置Sentinel dashboard地址
        port: 8719
management:
  endpoints:
    web:
      exposure:
        include: '*'

2.3 创建主启动类类


@SpringBootApplication
@EnableDiscoveryClient
public class sentinelMain8401 {

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

2.4 创建controller包,以进controller类

@RestController
@Slf4j
public class FlowLimitController {
    @GetMapping("/testA")
    public String testA()
    {
        log.info(Thread.currentThread().getName()+"\t"+"...testA");
        return "------testA";
    }

    @GetMapping("/testB")
    public String testB()
    {
        log.info(Thread.currentThread().getName()+"\t"+"...testB");
        return "------testB";
    }

}


3. 运行cloudalibaba-sentinel-serverice8401进行测试

访问地址:
http://localhost:8401/testB
http://localhost:8401/testA
Kite的学习历程SpringCloud之Sentinel监控初步使用
查看sentinel控制台网站
Kite的学习历程SpringCloud之Sentinel监控初步使用
测试成功!