SpringCloud之Dashboard服务监控

1、dashboard-ha 监控服务

在这里插入图片描述

<?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>com.yzm</groupId>
        <artifactId>springcloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>dashboard-ha</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>dashboard-ha</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

启动类

@EnableFeignClients
@EnableEurekaClient
@EnableHystrixDashboard
@EnableHystrix
@SpringBootApplication
public class DashboardHaApplication {
	...
}

application.yml

server:
  port: 8073

spring:
  application:
    name: dashboard-ha

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8088/eureka/

feign:
  hystrix:
    enabled: true

management:
  endpoints:
    web:
      exposure:
        include: "*"
      cors:
        allowed-origins: "*"
        allowed-methods: "*"

Controller

@RestController
public class HaController {

    @Resource
    private HaFeign haFeign;

    @Value("${server.port}")
    private String port;

    @GetMapping("hello")
    public String hello(@RequestParam String name) {
        return "ha," + name + " ! " + "访问端口号:" + port;
    }

    @GetMapping("ha")
    public String ha(@RequestParam String name) {
        return haFeign.callHi(name);
    }
}

Service

@FeignClient(value = "dashboard-hi", fallback = HaBack.class)
public interface HaFeign {

    @GetMapping("hello")
    String callHi(@RequestParam String name);
}
@Service
public class HaBack implements HaFeign {
    @Override
    public String callHi(String name) {
        return "dashboard-hi 服务挂了";
    }
}

2、dashboard-hi 监控服务

在这里插入图片描述

<?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>com.yzm</groupId>
        <artifactId>springcloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>dashboard-hi</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>dashboard-hi</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
@EnableFeignClients
@EnableEurekaClient
@EnableHystrixDashboard
@EnableHystrix
@SpringBootApplication
public class DashboardHiApplication {

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

}
server:
  port: 8074

spring:
  application:
    name: dashboard-hi

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8088/eureka/

feign:
  hystrix:
    enabled: true

management:
  endpoints:
    web:
      exposure:
        include: "*"
      cors:
        allowed-origins: "*"
        allowed-methods: "*"

Controller

@RestController
public class HiController {

    @Resource
    private HiFeign hiFeign;

    @Value("${server.port}")
    private String port;

    @GetMapping("hello")
    public String hello(@RequestParam String name) {
        return "hi," + name + " ! " + "访问端口号:" + port;
    }

    @GetMapping("hi")
    public String hi(@RequestParam String name) {
        return hiFeign.callHa(name);
    }

}

Service

@FeignClient(value = "dashboard-ha", fallback = HiBack.class)
public interface HiFeign {

    @GetMapping("hello")
    String callHa(@RequestParam String name);
}
@Service
public class HiBack implements HiFeign {
    @Override
    public String callHa(String name) {
        return "dashboard-ha 服务挂了";
    }
}

3、独立监控界面

依次启动eureka、dashboard-ha、dashboard-hi 服务

访问
http://localhost:8073/actuator/hystrix.stream
在这里插入图片描述
会一直在ping…

访问
http://localhost:8073/ha?name=yzm
http://localhost:8074/hi?name=yzm

打开ha服务的监控界面
http://localhost:8073/hystrix
在这里插入图片描述
在这里插入图片描述
可以看到刚刚有过ha服务一次请求被转发到hi服务
刷新4次 http://localhost:8073/ha?name=yzm
在这里插入图片描述
同样的打开hi服务的监控页面
在这里插入图片描述

4、聚合监控界面

dashboard-turbine 服务
在这里插入图片描述

<?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>com.yzm</groupId>
        <artifactId>springcloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>dashboard-turbine</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>dashboard-turbine</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

启动类

@EnableTurbine
@EnableEurekaClient
@SpringBootApplication
public class DashboardTurbineApplication {

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

}

application.yml

server:
  port: 8075

spring:
  application:
    name: dashboard-turbine

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8088/eureka/

# 聚合dashboard-hi,dashboard-ha的监控
turbine:
  app-config: dashboard-hi,dashboard-ha
  cluster-name-expression: new String("default")
  combine-host-port: true

启动 turbine 服务
访问 http://localhost:8073/hystrix 打开监控界面(8073、8074都行)
在这里插入图片描述
在这里插入图片描述

相关链接

首页
上一篇:Zipkin服务追踪
下一篇:Gateway网卡路由、断言

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值