Spring Boot基础教程27-生产准备-基于HTTP的监控

 

  • 利用Spring Boot的特性进行监控你的应用
  1. 通过HTTP(最简单方便)
  2. 通过JMX
  3. 通过远程shell
  • 添加依赖

<!-- actuator -->

<dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

<!-- security -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-security</artifactId>

</dependency>

 

  • 端点(通过执行器端点可以监控应用及与应用进行交互)
  1. 端点暴露的方式取决于你采用的监控方式。如果使用HTTP监控,端点的ID映射到一个URL。例如,默认情况下,health端点将被映射到/health。
  2. 端点会默认有敏感度,根据不同的敏感度是否需要提供用户密码认证
  3. 如果没启用web安全,则敏感度高的会禁用
  4. 可以通过配置文件进行配置敏感度
  5. 默认情况下,除了shutdown外的所有端点都是启用的。
  • 配置

#端点的配置

endpoints.sensitive=true

endpoints.shutdown.enabled=true

 

#保护端点

security.basic.enabled=true

security.user.name=roncoo

security.user.password=roncoo

management.security.roles=SUPERUSER

 

#自定义路径

security.basic.path=/manage

management.context-path=/manage

  • 备注

度量http://localhost:8080/manage/metrics

追踪http://localhost:8080/manage/trace

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章