Spring Boot的生产级特性 - Metrics 监控和管理

一、特性介绍

    Metrics基本上是成熟公司里面必须做的一件事情,简单点来说就是对应用的监控,之前在一些技术不成熟的公司其实是不了解这种概念,因为业务跟技术是相关的 当业务庞大起来,技术也会相对复杂起来,对这些复杂的系统进行监控就存在必要性了,特别是在soa化的系统中,完整一个软件的功能分布在各个系统中,针对这些功能进行监控就更必要了 而Spring Boot Actuator 提供了metrics service,让监控变得统一化了,方便管理。具体的参数介绍请参考 Spring Boot的监控和管理 博文以及官方文档

二、引入依赖

		<!-- Spring Boot生产级特性 -->
		<!-- 端点endPoint 查看性能指标信息 /metrics路径 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<!-- 汇总端点信息 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-hateoas</artifactId>
		</dependency>

		<!-- actuator聚合图形化插件 访问地址 http://127.0.0.1:8080 -->
		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-rest-hal-browser</artifactId>
		</dependency>

其中,此示例项目我采用的是application.yml。配置如下:

management:
  endpoints:
    web:
      exposure:
        include: [info, health, beans, env, metrics, mappings, scheduledtasks, sessions, threaddump, docs, logfile, jolokia] #暴露的端点 docs是web端点
      base-path: /actuator #默认/actuator 不更改可不用配置
      #CORS跨域支持
      cors:
        allowed-origins: http://example.com
        allowed-methods: GET,PUT,POST,DELETE
  endpoint:
    beans:
      cache:
        time-to-live: 10s #端点缓存响应的时间量
    health:
      show-details: always #详细信息显示给所有用户
  server:
    port: 10000 #默认8080
    address: 127.0.0.1 #配置此项表示不允许远程连接

  #监测
  metrics:
    web:
      server:
        auto-time-requests: true




# 配置应用的基本信息 可通过 http://127.0.0.1:8080/actuator/info 访问
info: 
  app:
    name: @app.name@
    description: @app.description@
    version: @app.version@
    java.version: @java.version@

其中info的配置是在pom.xml中定义好的属性以及默认注入系统环境变量等

三、访问方式

    http://127.0.0.1:10000/browser/ 访问可视化的Restful接口的api。端口是在application.yml中配置的。结果如下图所示





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值