美文网首页
微服务-springcloud-dashboard-单节点

微服务-springcloud-dashboard-单节点

作者: jianshuqiang | 来源:发表于2019-07-14 20:29 被阅读0次

前言

本次使用的版本号是springcloud(Greenwich.SR2) springboot(2.1.6.RELEASE)

hystrix dashboard

单节点监控(

一、创建监控页面

1、引入GAV依赖pom文件

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.tool.dashboard</groupId>
    <artifactId>sys-tool-hystrix-dashboard</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sys-tool-hystrix-dashboard</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2、application.properties

server.port=10010
spring.application.name=sys-tool-dashboard

3、启动类头配置

@SpringBootApplication
@EnableHystrixDashboard

4、启动

5、访问

http://localhost:10010/hystrix

6、效果

image.png

创建监控方

1、引入gav

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

application.properties

server.port=10011
spring.application.name=company-info-test
#开启所有监控断点,也可以单独打开hystrix.stream
#management.endpoints.web.exposure.include=hystrix.stream
#  health,info,env......
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

3、使组件生效,在启动类种配置生效注解

//(exclude={DataSourceAutoConfiguration.class})去除自动连接数据库的配置,原因是父文件中引入了JPA
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@EnableCircuitBreaker

4,编写controller接口以及使用hystrix做容错

接口

@RestController
@RequestMapping("info-test")
public class TestDashBoard {
    @Autowired
    private StoreIntegration storeIntegration;
    @GetMapping("dashboard")
    public Object testDashBoard() {
        return storeIntegration.getStores();
    }
}

hystrix容错

@Component
public class StoreIntegration {

    @HystrixCommand(fallbackMethod = "defaultStores")
    public Object getStores() {
        return "success";
        //do stuff that might fail
    }

    public Object defaultStores() {
        return "error";
                /* something useful */
    }
}

5、启动测试

路径
http://localhost:10011/actuator/hystrix.stream
效果

image.png
看到的是ping,没有效果
然后访问接口
http://localhost:10011/info-test/dashboard

然后进入http://localhost:10011/actuator/hystrix.stream页面

image.png

6、进入监控页面(输入地址进行监控)

image.png
监控效果
image.png
再次访问接口,查看监控效果
访问(不断刷新)
http://localhost:10011/info-test/dashboard
监控页面
image.png

多节点监控

相关文章

网友评论

      本文标题:微服务-springcloud-dashboard-单节点

      本文链接:https://www.haomeiwen.com/subject/ulmikctx.html