Spring boot admin - 微服务监测demo
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Spring boot admin - 微服务监测demo,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4678字,纯文字阅读大概需要7分钟。
内容图文
因为服务器的不稳定,而且小的服务越来越多,添加一个微服务的监测会更放心一些。
参考:https://github.com/codecentric/spring-boot-admin
http://codecentric.github.io/spring-boot-admin/2.1.2/#_what_is_spring_boot_admin
首先是用于监测其他服务的Spring boot admin
- 按文档说明,最好创建一个新的Project用于监测。创建到选择Dependencies的时候,发现Ops下可以选Spring Boot Admin(Server)
2. 按文档说明,需要几处代码的添加
- 启动类
package com.cnipr.pt; import de.codecentric.boot.admin.server.config.EnableAdminServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableAdminServer @SpringBootApplication //已经包含Configuration和AutoConfiguration public class MonitorApplication { public static void main(String[] args) { SpringApplication.run(MonitorApplication. class , args); } }
- application.properties(以下配置为了在微服务状态变化时发送邮件)
spring.mail.host=XXX.123.net spring.mail.port=25 spring.mail.username=username spring.mail.password=123456 spring.boot.admin.notify.mail.from=xxxxx@gmail.com spring.boot.admin.notify.mail.to=xxxxx@gmail.com
- pom.xml
<? 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.2.RELEASE</version><relativePath/><!-- lookup parent from repository --></parent><groupId>com.cnipr.pt</groupId><artifactId>monitor</artifactId><version>0.0.1-SNAPSHOT</version><name>monitor</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><spring-boot-admin.version>2.1.1</spring-boot-admin.version></properties><dependencies><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId></dependency><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-server-ui</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-dependencies</artifactId><version>${spring-boot-admin.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>
为了在SBA(Spring Boot Admin)中注册服务,要在相应的spring boot应用中添加Spring boot admin client的相关配置。
- pom.xml(注意!client的version最好和spring-boot-starter-parent的version保持一致,否则可能会出现运行错误)
< dependency > < groupId >de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>2.1.2</version></dependency>
为了在SBA上查看到版本号,可以在pom.xml中的spring-boot-maven-plugin的配置中添加build-info。
< plugin > < groupId >org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>build-info</goal></goals></execution></executions></plugin>
application.properties(url指定需要注册的admin的地址; logging.pattern.file的配置可将日志显示为彩色,可不加;name显示服务名称,可不加;prefer-ip为true会显示微服务的ip地址,可不加)
spring.boot.admin.client.instance.name=mail-service
spring.boot.admin.client.instance.prefer-ip = true
spring.boot.admin.client.url=http://localhost:8080 management.endpoints.web.exposure.include=*
logging.pattern.file=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx
admin显示界面(默认端口为8080)
原文:https://www.cnblogs.com/jane850113/p/10385091.html
内容总结
以上是互联网集市为您收集整理的Spring boot admin - 微服务监测demo全部内容,希望文章能够帮你解决Spring boot admin - 微服务监测demo所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。