springboot监控

springboot版本

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

 

监控类型

1.以json串的格式返回监控信息(spring-boot-starter-actuator)

2.以图形化界面的方式返回监控内容(spring-boot-admin-starter-server、spring-boot-admin-starter-client)

 

监控内容

spring-boot-starter-actuator(支持自定义)

如果使用springMVC还可以监控以下内容

 

spring-boot-admin

 

spring-boot-starter-actuator配置

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 安全方面,可选配置 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>

 

application.yml

management:
  # 是否启用认证
  security:
    enabled: false
  # 监控端口
  port: 8088
  # 监控上下文路径
  context-path: /monitor
# 启用shutdown,实现springboot项目优雅停机,要考虑安全问题,默认不启用
endpoints:
  shutdown:
    enabled: true
# 认证账号、密码,需要spring-boot-starter-security支持,可选配置
#security:
#  user:
#    name: wly
#    password: wly
# role=SUPERUSER

# spring boot信息,可选配置
info:
app:
name: spring-boot-actuator-wly
version: 1.0.0

 

访问监控URL

http://localhost:8088/monitor/env

 

效果

 

spring-boot-admin配置

spring-boot-admin-starter-server配置,需要单独建立一个监控的项目

pom.xml

 <dependency>
     <groupId>de.codecentric</groupId>
     <artifactId>spring-boot-admin-server</artifactId>
     <version>1.5.6</version>
  </dependency>
  <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-server-ui</artifactId>
      <version>1.5.6</version>
  </dependency>

 

application.yml

server.port=8085

 

启动类(添加@EnableAdminServer注解)

package com.example.springbootadmin;

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

@SpringBootApplication
@EnableAdminServer
public class SpringbootadminApplication {

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

 

配置完成启动项目即可~

 

spring-boot-admin-starter-client配置

pom.xml

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

 

application.yml

# 配置spring-boot-admin-starter-server的监控地址
spring:
  boot:
    admin:
      url: http://localhost:8085
server:
  port: 8080
management:
  # 是否启用认证
  security:
    enabled: false

 

配置完成启动服务即可~

 

效果

访问spring-boot-admin-starter-server地址(localhost:8085)

 

 

转载于:https://www.cnblogs.com/douJiangYouTiao888/p/9228348.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值