Spring Cloud实战(三)-监控中心
接着上一篇 Spring Cloud实战(二)-注册中心 现在开始搭建监控中心
一.监控中心monitor-server
1.添加spring-boot-admin版本控制到cloud-action的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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><packaging>pom</packaging><modules><module>register-server</module><module>config-server</module><module>monitor-server</module><module>api</module><module>user-server</module><module>order-server</module><module>pay-server</module><module>manage-server</module><module>repository-server</module></modules><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.6</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>cloud-action</artifactId><version>0.0.1-SNAPSHOT</version><name>cloud-action</name><description>spring cloud 微服务实战</description><properties><skipTests>true</skipTests><java.version>1.8</java.version><spring-cloud.version>2021.0.1</spring-cloud.version><spring-boot-admin.version>2.6.3</spring-boot-admin.version></properties><dependencies><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><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope> <!-- 作用在编译和测试时,同时没有传递性--></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><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>
2.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"><parent><artifactId>cloud-action</artifactId><groupId>com.example</groupId><version>0.0.1-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>monitor-server</artifactId><dependencies><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency></dependencies></project>
3.application.yml
spring:application:name: monitor-serverprofiles:active: single
#监控配置
management:endpoints:web:exposure:include: "*" #公开所有端点 对于生产,您应该仔细选择要公开的端点.endpoint:health:show-details: alwaysinfo:env:enabled: true
---
#单机版
spring:config:activate:on-profile: single
server:port: 2222 #当前eureka-server服务的端口号
eureka:instance:lease-renewal-interval-in-seconds: 30 #服务续约(心跳检测)时间,默认30秒lease-expiration-duration-in-seconds: 90 #服务剔除时间,默认90秒health-check-url-path: /actuator/healthmetadata-map:startup: ${random.int} #需要在重启后触发信息和端点更新client:service-url:defaultZone: http://localhost:1111/eureka/ #eureka-client设置eureka-server的地址
4.MonitorApplication.java
package com.example.monitor;import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** @author 86188*/
@SpringBootApplication
@EnableAdminServer //开启监控服务
public class MonitorApplication {public static void main(String[] args) {SpringApplication.run(MonitorApplication.class, args);}
}
5.测试
java -jar monitor-server-0.0.1-SNAPSHOT.jar
可以看到监控信息非常详细
特别说明:
实际开发中监控模块完全可以和eureka注册中心放在一块,只需要配置spring.boot.admin.context-path 以便 Spring Boot Admin Server UI 不会与 Eureka 的 UI 冲突就可以了.此处为了凸显微服务的特性,所以单独作为一个服务.
Spring Cloud实战(三)-监控中心相关推荐
- Spring Cloud实战小贴士:Zuul统一异常处理(三)【Dalston版】
本篇作为<Spring Cloud微服务实战>一书关于Spring Cloud Zuul网关在Dalston版本对异常处理的补充.没有看过本书的读书也不要紧,可以先阅读我之前的两篇博文:& ...
- 我的新书《Spring Cloud实战》预告
从去年6月开始编写<Spring Cloud构建微服务架构>系列博文开始,受到了不少同行的关注与支持.随后也开通了多个交流群.创建了相关的论坛(http://bbs.springcloud ...
- Spring Cloud实战小贴士:Zuul处理Cookie和重定向
由于我们在之前所有的入门教程中,对于HTTP请求都采用了简单的接口实现.而实际使用过程中,我们的HTTP请求要复杂的多,比如当我们将Spring Cloud Zuul作为API网关接入网站类应用时,往 ...
- Spring Cloud实战小贴士:Zuul统一异常处理(一)
在上一篇<Spring Cloud源码分析(四)Zuul:核心过滤器>一文中,我们详细介绍了Spring Cloud Zuul中自己实现的一些核心过滤器,以及这些过滤器在请求生命周期中的不 ...
- Spring Cloud实战小贴士:Zuul统一异常处理(二)
在前几天发布的<Spring Cloud实战小贴士:Zuul统一异常处理(一)>一文中,我们详细说明了当Zuul的过滤器中抛出异常时会发生客户端没有返回任何内容的问题以及针对这个问题的两种 ...
- Spring Cloud实战Zuul统一异常处理
Spring Cloud实战Zuul统一异常处理 Spring Cloud Zuul中自己实现的一些核心过滤器,以及这些过滤器在请求生命周期中的不同作用.我们会发现在这些核心过滤器中并没有实现erro ...
- 《重新定义Spring Cloud实战》
摘要: 今天是2018年9月24号中秋节,祝福大家中秋节快乐,本文主要介绍<重新定义Spring Cloud实战>. 1. 前言 随着互联网的快速普及,云计算近年来得到蓬勃发展,企业的IT ...
- Spring Cloud Eureka(三)实现一个高可用的注册中心
Spring Cloud Eureka(三)实现一个高可用的注册中心 实现一个高可用的注册中心 在微服务结构这样的分布式环境中,我们需要充分考虑发生故障的情况,所以在生产环境中必须为服务的各个组件进行 ...
- spring cloud 实战项目搭建
spring cloud 实战项目搭建 Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理.服务发现.断 ...
最新文章
- TensorFlow指定CPU和GPU方法
- python怎么读write_Python中怎么读写文件
- sap与外部系统的接口怎么实现
- C++ throw:抛出自己的异常
- 北大清华团队编写!200多个科学实验+视频,和爸爸一起在家做
- 【编译原理】词法分析程序设计
- 移动端性能优化系列—启动速度
- echart 饼图每一块间隙_日本人用豆奶做威化饼,奶香十足、不甜腻,好吃!
- 三种方式在spring容器中为bean实现初始化方法和销毁方法
- hplus java_Java HijrahDate plus(long, TemporalUnit)用法及代码示例
- 开发大脑潜能的11种良方法
- 双三次插值 python实现_双三次插值Python
- Java使用iText PDF按页(逐页、单页)拆分PDF
- sunOracle t4系列小型机服务器配置详解
- Mac 本地起一个html 服务
- 使用python建立n维0矩阵
- 爬取京东辣条商品详情
- 【TensorFlow】官方例子mnist_with_summaries.py在windows下运行tensorboard
- UE4 后期处理 PostProcess
- 中继协作传输的SWIPT——知识扫盲
热门文章
- 使用conda时出现Solving environment: failed with initial frozen solve. Retrying with flexible solve错误
- 宇视摄像机/硬盘录像机等设备接入到国标GB28181协议视频平台EasyGBS的注意事项
- wopus推荐码,购买立省五块钱!!
- 7-2 养兔子 (20 分)
- Catch That Cow S
- UML在软件工程中的使用 建模—类图
- Matlab命令行乱码问题
- python送程序员收入_程序员学Python后惊叹,这么丰厚的收入是Java给不了的!
- Thinkpad T420 安装 mSATA SSD 固态硬盘
- 10.自媒体文章管理