springboot2.0之监控管理

toov5      2022-04-16     160

关键词:

Spring boot监控中心:

 针对微服务的服务状态,服务器的内存变化(内存、线程、日志管理等)检测服务配置连接地址是否有用(有些懒加载的情况下,用的时候发现卧槽不能用)模拟访问,懒加载。统计有多少个bean(Spring 容器中的bean)、统计Spring MVC 中@RequestMapping(统计接口数)

Actuator监控应用(无界面,返回json格式)

AdminUi底层使用Actuator监控应用,实现可视化界面

Actuator是spring boot的一个附加功能,可帮助你在应用程序生产环境时监视和管理应用程序。可以使用HTTP的各种请求来监管,审计,收集应用的运行情况.特别对于微服务管理十分有意义.缺点:没有可视化界面。

应用场景:生产环境

1、首先maven工程的pom,需要引入相关的依赖jar

    

<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>
  <groupId>SpringbootActuator</groupId>
  <artifactId>com.toov5.Actuator</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.0.RELEASE</version>
	</parent>
	<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>

	</dependencies>

  
</project>

  

 2、然后application.yml的文件配置,主要对于监控中心的一些设置。

###通过下面的配置启用所有的监控端点,默认情况下,这些端点是禁用的;加入这个配置。监控所有接口
management:
  endpoints:
    web:
      exposure:
        include: "*"

3、业务代码

package com.toov5.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
    @RequestMapping("/ok")
    public String index(){
        return "ok";
    }
}

4、启动类

package com.toov5.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class app {
   public static void main(String[] args) {
    SpringApplication.run(app.class, args);
}
}

启动后:

看控制台输出

被圈的日志是 表示有多少接口 

里面的请求是从actuator里面来的  监控中心产生了很多接口      默认情况下是禁止的哈 如果把yml配置里面的内容去掉的话就没有这么多了

默认情况下监控中心提供三个接口 信息很少的 一般不用这三个 满足不了 

Spring Boot2.0之后 监控中心的地址发生变化 必须这个地址才可以访问到  之前版本是不用加 actuator  访问监控中心

 

 访问这个url 可以看到当前Spring容器有多少bean

 可以把这些json格式化

 

 还可以检测当前容器中有多少 url映射接口

通过json在线格式化

 

 可以看到我的接口的信息:

展示的很清楚 各种信息

里面很多 是监控中心提供的  各种啊 好多啊

#################################################################

如果msql连接的账号或密码错误 在项目启动时候不会报错 因为懒加载呀

可以通过监控中心去处理

返回这个说明 没错

如果是 down则有错

原理是 访问时候 控制中心会去读配置文件 然后去处理下试试

查看自定义应用信息

在配置文件中配置info开头的配置信息

 

 

 

总结:

Actuator访问路径

通过actuator/+端点名就可以获取相应的信息。

 

路径

作用

/actuator/beans

显示应用程序中所有Spring bean的完整列表。

/actuator/configprops

显示所有配置信息。

/actuator/env

陈列所有的环境变量。

/actuator/mappings

显示所有@RequestMapping的url整理列表。

/actuator/health

显示应用程序运行状况信息 up表示成功 down失败

/actuator/info

查看自定义应用信息

 

springboot2.0最新版相关技术

https://gitee.com/hejr.cn.com/SpringBoot2.0_2019/tree/master SpringBoot2.0最新版相关技术学习,该项目主要是提供给正在学习SpringBoot的小伙伴,包括整合Freemarker,JSP等web页面,以及数据访问,事务管理,日志管理,缓存(Ehcache,Redis)技术... 查看详情

springboot2.0.2教程-目录

SpringBoot2.0.2教程-HelloWorld-01 SpringBoot2.0.2教程-HelloWorld之intellijidea创建web项目-02 SpringBoot2.0.2教程-配置文件application.properties-03 SpringBoot2.0.2教程-日志管理-04  SpringBoot2.0.2教 查看详情

springboot2.0之整合redis

需要的maven依赖jar包,是对Jedis的封装maven依赖:<projectxmlns="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.0http://ma 查看详情

springboot2.0之jar打包方式

...ge打包2.2.0将war包放入到tomcatwebapps下运行即可。 注意:springboot2.0内置tomcat8.5.25,建议使用外部 查看详情

springboot2.0之整合rabbitmq

案例: Springboot对RabbitMQ的支持公共的pom: <projectxmlns="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 查看详情

springboot2.0之整合elasticsearch

就类比数据库到时候去实现服务器端配置集群名字 与yml名字一致pom:<projectxmlns="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.0ht 查看详情

springboot2.0深度实践之核心技术篇

第1章系列总览总览SpringBoot2.0深度实践系列课程的整体议程,包括SpringBoot三大核心特性(组件自动装配、嵌入式Web容?、生产准备特性)、Web应用(传统Servlet、SpringWebMVC、SpringWebFlux)、数据相关(JDBC、JPA、事务)、功能扩展(Sp... 查看详情

springboot2.0实战(23)整合redis之集成缓存springdatacache

SpringBoot2.0实战(23)整合Redis之集成缓存SpringDataCache来源:https://www.toutiao.com/a6803168397090619908/?timestamp=1584450221&app=news_article_lite&group_id=6803168397090619908&req_id=20200317210341 查看详情

springboot2.0之整合activemq(点对点模式)

<projectxmlns="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.0http://maven.apache.org/xsd/maven-4.0.0.xs 查看详情

springboot2.0之性能优化

  1、JVM参数调优  针对运行效果 吞吐量  初始堆内存与最大堆尽量相同  减少垃圾回收次数 2、扫包优化:启动优化默认Tomcat容器改为Undertow Tomcat的吞吐量5000左右Undertow8000左右 底层优... 查看详情

springboot2.0之整合activemq(发布订阅模式)

发布订阅模式与前面的点对点模式很类似,简直一毛一样 注意:发布订阅模式先启动消费者公用pom:<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org 查看详情

springboot2.0之使用springboot

springboot依赖每一个springboot的发型版本都包含了所依赖的版本,如果升级springboot版本,其依赖也会同步更新升级。maven的用户可以通过继承spring-boot-starter-parent。其包含了一些合理的值的设置:1.默认设置的编译器为JDK1.82.源文件... 查看详情

springboot2.0之整合apollo

SpringBoot客户端对接阿波罗服务器端  核心源码都在这个压缩包里面封装好了环境运行shell脚本就ok了  下面进入到本地maven仓库:远程仓库apollo的jar包只能打包到本地或者公司的私服了 首先引入pom:<parent> &... 查看详情

springboot2.0+oauth2.0之授权码模式

综述:上两回讲了密码模式,应该是浅显易懂。如有补充,不足或者是有误之处还请多多指出。现在重头戏,授权码模式开始。一、具体操作流程-用户访问客户端,后者将前者导向认证服务器,认证服务器返回认证页面(账号... 查看详情

springboot2.0之@async实现异步调用

 补充一个知识点:lombok底层原理使用的是:字节码技术ASM修改字节码文件,生成比如类似于get()set()方法一定要在开发工具安装在编译时候修改字节码文件(底层使用字节码技术),线上环境使用编译好的文件 下面... 查看详情

springboot之整合quartz调度框架-基于springboot2.0.2版本

1.项目基础项目是基于SpringBoot2.x版本的  2.添加依赖<!--quartz依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId&g 查看详情

springboot之整合quartz调度框架-基于springboot2.0.2版本

1.项目基础项目是基于SpringBoot2.x版本的  2.添加依赖<!--quartz依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId&g 查看详情

springboot2.0.0.m7生产环境部署

springboot生产环境注意事项1.去除不需要的jar开发工具jar:spring-boot-devtools监控一定要做好权限控制或者去除控制jar:spring-boot-starter-actuatordruid的监控swagger的接口3、打包,跳过测试maven:cleanpackage-Dmaven.test.skip=true脚本#!/bin/sh## ... 查看详情