springboot监控

Preface

使用springboot进行性能监控简直是一种享受

服务端

服务端的配置简直是0代码,只需要加入一个actuator插件即可

服务端插件依赖

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

    <dependencyManagement>
        <dependencies>
            <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>

为了区分端口,我在application.properties里面配置了端口号为8090

server.port=8090

此时整个服务端就已经配置完成了,真的是一行代码都不用写,直接启动springboot项目就可以了。

客户端

爽就爽在客户端也是0代码,也是需要加入actuator插件,不过服务端加入的是server,客户端加入的是client,然后连接一下服务端就可以了

客户端配置

boilerplate code


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

为了监控更多一些东西,我加入了redis和mysql的配置

boilerplate code


   <dependencies>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
       </dependency>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-data-redis</artifactId>
       </dependency>
      
       <dependency><!--添加Mybatis依赖 配置mybatis的一些初始化的东西-->
           <groupId>org.mybatis.spring.boot</groupId>
           <artifactId>mybatis-spring-boot-starter</artifactId>
           <version>1.3.1</version>
       </dependency>
       <dependency><!-- 添加mybatis依赖 -->
           <groupId>org.mybatis</groupId>
           <artifactId>mybatis</artifactId>
           <version>3.4.5</version>
           <scope>compile</scope>
       </dependency>
       <dependency><!--添加MySql依赖 -->
           <groupId>mysql</groupId>
           <artifactId>mysql-connector-java</artifactId>
       </dependency>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-test</artifactId>
           <scope>test</scope>
       </dependency>
   </dependencies>

   <dependencyManagement>
       <dependencies>
           <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>

application.properties的配置如下

boilerplate code

spring.redis.host=localhost
spring.redis.port=6379
spring.datasource.url=jdbc:mysql://localhost:3306/socks
spring.datasource.username=root
spring.datasource.password=root
#开启健康检查的完整信息
management.endpoint.health.show-details=always
#暴露监控的所有的节点
management.endpoints.web.exposure.include=*
#健康检查路径更改,默认为actuator
management.endpoints.web.base-path=/hah

spring.boot.admin.client.url=http://localhost:8090

这样就可以启动了

效果

此时打开服务端,地址为http://localhost:8090,就可以看到监控界面了

caricature1
image.png
点击应用进去

caricature2
image.png

caricature3
image.png

caricature4
image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

micro_cloud_fly

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值