Springboot-Admin服务监控

Spring-boot-admin 是一个开源组织写的服务监控的项目,git 地址     https://github.com/codecentric/spring-boot-admin

主要功能:

1. 监测服务数量、服务对应的实例数量、以及每个服务上线时长

2. 每个实例的JVM信息、CPU以及进线程等信息

3. 加载的Spring bean 信息、yml 中配置的信息、全局的配置信息、日志级别、session 信息等

4. SpringMVC 全局的映射关系, 也就是 url对应的方法信息以及处理的方法(这个可以理解为查看SpringMVC 保存URL信息的org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry#mappingLookup<RequestMappingInfo, HandlerMethod> 缓存里面的信息,SpringMVC 项

目启动过程中会加载相关的mapping 信息到这个类里面)

1. 搭建一个Spring-boot-admin server 端

1. 新建子项目 cloud-admin-server, pom 如下:

复制代码
<?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</artifactId>
        <groupId>cn.qz.cloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-admin-server</artifactId>

    <dependencies>
        <!--admin server 需要的依赖-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>
复制代码

2. 新增application.yml 文件

spring:
  application:
    name: admin-server

server:
  port: 8801

3. 新增主启动类

复制代码
package cn.qz.cloud;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdminServerApplication.class, args);
    }
}
复制代码

4. 启动后访问8081 端口,查看如下:

 2. admin-client 通过http 注册到admin-server

1. pom 增加如下依赖

复制代码
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
复制代码

 

2. yml 增加配置: 主要是增加admin 的url, 配置类在de.codecentric.boot.admin.client.config.ClientProperties

复制代码
server:
  port: 8081

spring:
  application:
    name: cloud-provider-hystrix-payment
  redis:
    port: 6379
    host: localhost
  session:
    store-type: redis
  boot:
    admin:
      client:
        url: http://localhost:8801

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      #defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
      defaultZone: http://localhost:7001/eureka

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: ALWAYS
复制代码

3. 启动server, 然后启动client ,到8801 端口即可看到实例信息

3. 从eureka 注册中心直接拿客户端信息

1. 修改cloud-admin-server的pom ,增加如下引用:

        <!--注册中心,从注册中心拿数据-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

2. yml 修改

复制代码
spring:
  application:
    name: admin-server

server:
  port: 8801

eureka:
  client:
    registryFetchIntervalSeconds: 5
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:7001}/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
复制代码

3. 测试即可,admin-server 会从eureka 拿取服务数据

 4. 查看单个服务信息

 

 

    还可以整合k8s等,这个等之后学习完k8s 再来补充。

 

posted @   QiaoZhi  阅读(801)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2018-05-17 常用加密算法介绍
2018-05-17 http、https 等 常用默认端口号
点击右上角即可分享
微信分享提示