SpringCloud SpringBoot 组件使用:SpringBoot Actuator
基础篇
一、什么是Spring Actuator?
spring-boot-starter-actuator模块是一个spring提供的监控模块。我们在开运行发过程中,需要实时和定时监控服务的各项状态和可用性。Spring Boot的spring-boot-starter-actuator 模块(健康监控)功能提供了很多监控所需的接口,可以对应用系统进行配置查看、相关功能统计等。
二、代码实现
在maven的pom中引入:
<dependencies>
<!--web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
在application.yml文件中加入:
server:
port: 8080 #服务端口
spring:
application:
name: server-actuator
management:
server:
port: 8081 #actuator端口
endpoints:
web:
base-path: /
exposure:
include: "*"
在浏览器输入:http://localhost:8081/health,可以得到一串JSON字符串,但是这种很明显不适合业务场景,所以在下面的提高篇中我将会介绍一种带有界面的组件。


提高篇:SpringBoot Admin(简称SBA)对SpringBoot实现界面化监控
一、什么是SBA?
SBA则是基于Actuator更加进化了一步,其是一个针对Actuator接口进行UI美化封装的监控工具。Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的开源软件。每个应用都认为是一个客户端,通过HTTP或者使用 Eureka注册到admin server中进行展示,Spring Boot Admin UI部分使用AngularJs将数据展示在前端。
前端界面如下:


这样一个服务的运行情况就一目了然了
二、代码实现
(1)新建服务Actuator、Server01、Server02,其中Actuator服务作为管理服务管理着Server01与Server02服务。项目结构如下:

(2)在Actuator服务的pom.xml与application.yml文件中分别添加如下内容:
<dependencies>
<!--web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--SBA Server-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
</dependency>
<!--SBA Server UI-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
</dependencies>
server:
port: 8080 #服务端口
spring:
application:
name: server-actuator
management:
server:
port: 8081 #actuator端口
endpoints:
web:
base-path: /
exposure:
include: "*"
在启动类上添加@EnableAdminServer注解

(3)在Server01、Server02服务的pom.xml、application.yml文件中分别添加如下内容:
<dependencies>
<!--web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--SBA Client-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
</dependencies>
server:
port: 9666
management:
metrics:
web:
server:
auto-time-requests: false
endpoints:
web:
exposure:
include: '*'
exclude: env,beans
spring:
boot:
admin:
client:
url: http://localhost:8080 #这里是管理服务的网址
instance: server01 #监控服务名称
application:
name: server01
这样将所有的项目启动就可以然后访问http://localhost:8080/即可得到监控界面
SpringCloud SpringBoot 组件使用:SpringBoot Actuator的更多相关文章
- springboot(十九)使用actuator监控应用【转】【补】
springboot(十九)使用actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的 ...
- SpringCloud及其组件详解
SpringCloud及其组件详解 1.Spring Cloud 1.1 Spring Cloud和Dubbo的区别图解 1.2 微服务的技术栈 2.Spring Cloud 概述 2.1 Sprin ...
- springboot(一).初识springboot以及基本项目搭建
初识springboot 以及基本项目搭建 由于新的项目需要搭建后台框架,之前的springmvc架构也使用多次,在我印象中springboot的微服务架构更轻量级更容易搭建,所以想去试试spring ...
- SpringBoot | 1.1 SpringBoot简介
前言 本博客仅为记录与总结SpringBoot的学习笔记,资料来源: 书籍<深入浅出SpringBoot>第三版 B站尚硅谷<雷丰阳2021版SpringBoot2零基础入门> ...
- SpringBoot基础系列-SpringBoot配置
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...
- SPRING-BOOT系列之SpringBoot的诞生及其和微服务的关系
转载自 : https://www.cnblogs.com/ityouknow/p/9034377.html 微服务架构 微服务的诞生并非偶然,它是在互联网高速发展,技术日新月异的变化以及传统架构无法 ...
- 微服务架构案例(05):SpringCloud 基础组件应用设计
本文源码:GitHub·点这里 || GitEE·点这里 更新进度(共6节): 01:项目技术选型简介,架构图解说明 02:业务架构设计,系统分层管理 03:数据库选型,业务数据设计规划 04:中间件 ...
- Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构
Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构 概述 毫无疑问,Spring Cloud是目前微服务架构领域的翘楚,无数的书籍博客都在讲解这个技术.不过大多数讲解还停留 ...
- SpringBoot:4.SpringBoot整合Mybatis实现数据库访问
在公司项目开发中,使用Mybatis居多.在 SpringBoot:3.SpringBoot使用Spring-data-jpa实现数据库访问 中,这种jpa风格的把sql语句和java代码放到一起,总 ...
- SpringBoot(19)---SpringBoot整合Apollo
SpringBoot(19)---SpringBoot整合Apollo 有关Apollo之前已经写了两篇文章: 1.[Apollo](1)--- Apollo入门介绍篇 2.[Apollo](2)-- ...
随机推荐
- [转帖]【数据库架构】NewSQL和PGXC
数据库架构风格 数据库的基本架构 分库分表方案 分布式事务和跨节点查询 PGXC NewSQL:原生分布式数据库 总结 数据库的两种架构风格:NewSQL(代表Google Spanner).Prxo ...
- [转帖]OpenSSL版本历史
OpenSSL版本历史 新闻日志 这是所有 OpenSSL 公告的简洁日志.它们几乎是发布通知. 日期物品 2021 年 7 月 29 日OpenSSL 3.0 的 Beta 2 现已推出.这是一个候 ...
- [转帖]kafka指定topic设置消息留存时间
背景 单个主题消息量庞大,需要指定这个主题的消息留存时间缩小点 执行命令 ./bin/kafka-configs.sh --bootstrap-server node1:9092 --entity-t ...
- [转帖]CertUtil: -hashfile 失败: 0xd00000bb (-805306181)
https://www.cnblogs.com/heenhui2016/p/de.html 使用CertUtil验证Python安装文件的时候出现了这个错误. CertUtil: -hashfile ...
- 如何写RN样式 如何写RN组件 如何满屏 如何使用变量
app.js 文本水平居中了哈 控制文本的大小 字体颜色等 只有在文本元素上去控制哈 import React from 'react'; import {View, Text, StyleSheet ...
- NetCore高级系列文章01---创建项目及配置文件
.NET Core是适用于 Windows.Linux 和 macOS 的免费.开源托管的计算机软件框架,作为.NET开发人员,全面拥抱.NetCore将成为趋势. 本系列文章将分为两大部分讲解.Ne ...
- 分页sql大全
一.排除Top分页法(自命名,非规范) 思想:所谓"排除Top分页",主要依靠"排除"和Top这个两大核心步骤.首先查询当前页码之前的数据,然后将该数据从总数据 ...
- ETL之apache/hop-web 2.5安装和简单入门
一.使用Docker 安装部署 1.拉取镜像 推荐使用下面的web版本 docker pull apache/hop:latest docker pull apache/hop-web:latest ...
- 使用Navicat 进行MySql数据库同步功能
使用Navicat 进行MySql数据库同步功能 作者:胡德安 准备: 打开Navicat管理工具(比如Navicat Premium 15管理工具) 两个数据库第一个是源数据库A和要被同步的目标数据 ...
- PicoPixel贴图查看器
Pico Pixel Pico Pixel是一款纹理查看器,支持查看以下文件格式:TGA,BMP,JPG,DDS,PNG,OpenEXR, KTX, HDR, GIF, TIF. 此外,Pico Pi ...