SpringCloud-服务监控

一.SpringBootAdmin

1.创建项目cloud-admin-server

2.引入依赖


        
            org.springframework.boot
            spring-boot-starter-web
        


        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
        
        
            de.codecentric
            spring-boot-admin-starter-server
            2.3.1
        

3.在启动类上添加注解@EnableAdminServer

4.修改application.yml

server:
  port: 1111

spring:
  application:
    name: cloud-admin-server
  cloud:
    nacos:
      server-addr: localhost:8848

5.添加actuator

在需要监控的项目中添加依赖
 

        
        
            org.springframework.boot
            spring-boot-starter-actuator
        

6.修改服务的application.yml

 

management:
   health:
     show-details: ALWAYS
  endpoints:
    web:
      exposure:
        include:
          - "*"

7.启动服务,访问localhost:1111

二.通过邮箱监听服务

  1.引入依赖

  
            org.springframework.boot
            spring-boot-starter-mail
        

2.修改application.yml

mail:
    host: smtp.qq.com
    port: 587
    username: [email protected]
    #授权码
    password: xedsxxynnrtkbcbb
    default-encoding: UTF-8
    properties:
      mail:
        smtp:
         auth: true
         starttls:
            enable: true
            required: true
  boot:
    admin:
      notify:
        mail:
          #发件人
          from: [email protected]
          #收件人
          to: [email protected]
          #启用邮件通知
          enabled: true

3.重启cloud-admin-server,当服务上线时,就可以在邮箱中看到信息了

 

 

你可能感兴趣的:(微服务,spring,cloud)