On this page
35. Metrics Emitter
Spring Boot Actuator 为千分尺提供了依赖 management 和 auto-configuration,这是一个支持多个监控系统的 application metrics 外观。
Spring Cloud Stream 支持将任何可用的 micrometer-based metrics 发送到 binding 目标,允许定期从流 applications 收集度量数据,而不依赖于轮询单个 endpoints。
通过定义spring.cloud.stream.bindings.applicationMetrics.destination
property 来激活 Metrics Emitter,该属性指定当前 binder 用于发布度量标准消息的 binding 目标的 name。
例如:
spring.cloud.stream.bindings.applicationMetrics.destination=myMetricDestination
前面的 example 指示 binder 绑定到myMetricDestination
(即 Rabbit exchange,Kafka topic 和其他)。
以下 properties 可用于自定义 metrics 的发射:
spring.cloud.stream.metrics.key
- 要发出的度量标准的 name。应该是每个 application 的唯一 value。
默认值:${spring.application.name:${vcap.application.name:${spring.config.name:application}}}
spring.cloud.stream.metrics.properties
- 允许添加到 metrics 有效内容的白名单 application properties
默认值:null。
spring.cloud.stream.metrics.meter-filter
- Pattern 控制想要捕获的'米'。对于 example,指定
spring.integration.*
捕获 name 以spring.integration.
开头的计量表的度量标准信息
- Pattern 控制想要捕获的'米'。对于 example,指定
默认值:捕获所有“米”。
spring.cloud.stream.metrics.schedule-interval
- 用于控制发布度量标准数据的速率的时间间隔。
默认值:1 分钟
考虑以下:
java -jar time-source.jar \
--spring.cloud.stream.bindings.applicationMetrics.destination=someMetrics \
--spring.cloud.stream.metrics.properties=spring.application** \
--spring.cloud.stream.metrics.meter-filter=spring.integration.*
以下 example 显示了由于前面的命令而发布到 binding 目标的数据的有效负载:
{
"name": "application",
"createdTime": "2018-03-23T14:48:12.700Z",
"properties": {
},
"metrics": [
{
"id": {
"name": "spring.integration.send",
"tags": [
{
"key": "exception",
"value": "none"
},
{
"key": "name",
"value": "input"
},
{
"key": "result",
"value": "success"
},
{
"key": "type",
"value": "channel"
}
],
"type": "TIMER",
"description": "Send processing time",
"baseUnit": "milliseconds"
},
"timestamp": "2018-03-23T14:48:12.697Z",
"sum": 130.340546,
"count": 6,
"mean": 21.72342433333333,
"upper": 116.176299,
"total": 130.340546
}
]
}
鉴于度量标准消息的格式在迁移到 Micrometer 后略有变化,已发布的消息也将
STREAM_CLOUD_STREAM_VERSION
标头设置为2.x
,以帮助区分来自旧版本的 Spring Cloud Stream 的度量标准消息。