监控中心

2019-06-23  本文已影响0人  你值得拥有更好的12138

以下概念性的语言均为本人理解,欢迎大佬指出错误,小白希望深入理解请到官网
Github源码参考:https://github.com/HanJuly/SpringCloudDemo

监控中心

微服务开发中,会出现几十甚至上百的微服务。所以我们需要监控中心来进行监控,并在下线后给运维人员发送邮件等。

监控中心配置

pom.xml
  <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.5.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.0.2</version>
        </dependency>
        <!--JMX-bean 管理-->
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
    </dependencies>

yaml配置

management:
  security:
    enabled: false
  endpoints:
    web:
      exposure:
        include: "*"  #开启所有的端点,如:health
  endpoint:
    health:
      show-details: always #服务健康信息开启详细信息
server:
  port: 3333
  servlet:
    context-path: /admin
spring:
  application:
    name: admin-watcher
  jmx:
    default-domain: admin    
  boot:
    admin:
      notify:
        mail:
          from: "15761632106@163.com" #邮件发送方账户abc@qq.com
          to: "1114549817@qq.com" #接受邮件的账户def@qq.com
      client:
        url: http://localhost:3333
  mail:
    host: smtp.163.com
    username: "15761632106@163.com" #邮件发送方的账户如abc@qq.com
    password: "wangyi123" #授权码,在各邮箱设置界面进行设置
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
            required: true
eureka:  #服务化admin
  instance:
    name: admin-watcher
    lease-renewal-interval-in-seconds: 10
    health-check-url-path: /admin/actuator/health
  client:
    service-url:
      defaultZone: http://127.0.0.1:8500/eureka/
    registry-fetch-interval-seconds: 5

注解配置
@EnableAdminServer
@SpringCloudApplication
public class AdminApplication {

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

    }
}

被监控的服务配置

pom.xml配置

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.1.3.RELEASE</version>
        </dependency>

并在yaml文件中打开所有的端点

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

配置监控中心地址

spring:
  boot:
    admin:
      client:
        url: http://localhost:3333

验证

image.png
image.png
上一篇下一篇

猜你喜欢

热点阅读