zoukankan      html  css  js  c++  java
  • spring-boot-route(十九)spring-boot-admin监控服务

    SpringBootAdmin不是Spring官方提供的模块,它包含了ClientServer两部分。server部分提供了用户管理界面,client即为被监控的服务。client需要注册到server端。

    SpringBootAdmin提供了很少的几个监控服务端点,需要依赖SpringBootActuator丰富监控功能。

    server端配置

    server端的配置很简单,无需任何开发。

    第一步:引入依赖

    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-server</artifactId>
        <version>2.3.0</version>
    </dependency>
    

    第二步:在启动类上增加@EnableAdminServer注解,开启对spring-boot-admin的支持。

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

    做好以上配置,然后访问http://ip:port;效果如下

    目前还没有客户端注册到服务端,所以看不到任何监控的内容,接下来我们创建一个客户端并且注册到服务端后再来看看效果。

    Client端配置

    这里使用上一章的演示项目——spring-boot-actuator做为客户端。

    第一步:引入依赖

    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-client</artifactId>
        <version>2.3.0</version>
    </dependency>
    

    第二部:将客户端注册到服务器端,

    spring:
      boot:
        admin:
          client:
    		# 服务端地址
            url: http://localhost:7019
    

    效果如下:

    为了监控更多的状态信息,我们在客户端引入spring-boot-actuator依赖。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    

    由于actuator默认只开启了health和info两个web端口,如果想要在server端页面看到所有的监控信息,需要开启其他接口的web端口。

    management:
      endpoints:
        web:
          exposure:
            include: "*"
    

    现在的效果如下:

    spring-boot-admin的应用就简单介绍完了。spring-boot-admin配合spring-boot-actuator实现多服务监控,不仅能提供查看服务监控信息的ui,而且可以监控更加全面的内容。


    此是spring-boot-route系列的第十九篇文章,这个系列的文章都比较简单,主要目的就是为了帮助初次接触Spring Boot 的同学有一个系统的认识。本文已收录至我的github,欢迎各位小伙伴star

    githubhttps://github.com/binzh303/spring-boot-route

    点关注、不迷路

    如果觉得文章不错,欢迎关注点赞收藏,你们的支持是我创作的动力,感谢大家。

    如果文章写的有问题,请不要吝啬,欢迎留言指出,我会及时核查修改。

    如果你还想更加深入的了解我,可以微信搜索「Java旅途」进行关注。回复「1024」即可获得学习视频及精美电子书。每天7:30准时推送技术文章,让你的上班路不在孤独,而且每月还有送书活动,助你提升硬实力!

  • 相关阅读:
    严重: Parse error in application web.xml file at jndi:/localhost/ipws/WEBINF/web.xml java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml
    Failed to install .apk on device 'emulator5554': timeout解决方法
    java.lang.NoClassDefFoundError:org.jsoup.Jsoup
    Conversion to Dalvik format failed: Unable to execute dex:解决方法
    apache Digest: generating secret for digest authentication ...
    Description Resource Path Location Type Project has no default.properties file! Edit the project properties to set one.
    android service随机自启动
    MVC3 安装部署
    EF 4.3 CodeBased 数据迁移演练
    SQL Server 2008开启sa账户
  • 原文地址:https://www.cnblogs.com/zhixie/p/13839067.html
Copyright © 2011-2022 走看看