目前项目中用到了最基本的两个监控:spring boot admin和spring cloud hystrix,这里先介绍一下spring boot admin的实战。
添加依赖
- spring cloud
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <spring.cloud.version>Edgware.RELEASE</spring.cloud.version> <spring.boot.admin.version>1.5.7</spring.boot.admin.version> <profiles.dir>src/main/profiles</profiles.dir> </properties> <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>
配置文件
server: port: 8083 spring: application: name: monitor-admin jackson: serialization: indent_output: true mail: host: mx1.qq.com boot: admin: notify: mail: to: yourEmail@qq.com output: ansi: enabled: always endpoints: health: sensitive: false eureka: client: serviceUrl: defaultZone: http://eureka1:1111//eureka/ instance: prefer-ip-address: true leaseExpirationDurationInSeconds: 30 leaseRenewalIntervalInSeconds: 10 management: security: enabled: false endpoints: web: exposure: include: "*" #<2> endpoint: health: show-details: ALWAYS
这里有几个注意点:
- 邮件报警
●检测服务器的基本运行状态,宕机通知
●spring.boot.admin.notify.mail.to=yourEmail@qq.com
●具体的配置信息参照:http://codecentric.github.io/spring-boot-admin/1.5.7/#mail-notifications
●默认效果图:- endpoints.health.sensitive
设置为false,将所有的健康信息都暴漏显示。- management.security.enabled
设置为false,关闭安全限制
与上个参数结合使用效果如下:- endpoint.health.show-details
参考:http://mip.breakyizhan.com/springboot/3436.html
效果图
- 如果被监控的服务器,没有关闭安全限制,点击“Details”,只能看到部分信息,效果如下图:
- 如果想要看到更多的信息,需要设置management.security.enabled为false,设置后效果如下图:
来源:oschina
链接:https://my.oschina.net/u/226613/blog/1647236