Spring Cloud Stream provides a module called spring-cloud-stream-metrics
that can be used to emit any available metric from Spring Boot metrics endpoint to a named channel.
This module allow operators to collect metrics from stream applications without relying on polling their endpoints.
HTTP polling can be challenging on cloud environments since applications could be on a private network or behind a Load balancer that prevents per instance access.
The module is activated when you set the destination name for its channel, spring.cloud.stream.bindings.applicationMetricsChannel.destination=<DESTINATION_NAME>
.
applicationMetricsChannel
can be configured in a similar fashion to any other bound output channel.
The default contentType
setting of applicationMetricsChannel
is application/json
.
By default the module is configured to only send Spring Integration message channel metrics.
Available properties for customization using the prefix spring.cloud.stream.applicationMetricsChannel
.
${spring.application.name:${vcap.application.name:${spring.config.name:application}}}
The period in which metrics will be posted to the channel
Default: 5000
.
Prefix string to be prepended to the metrics name
Default: ``
An array of strings containing regex patterns of metrics that should be included.
Default: integration**
An array of strings containing regex patterns of metrics that should be excluded.
Default: ``
Just like the includes
option, it allows white listing application properties that will be added to the metrics payload
Default: null.
Note | |
---|---|
Due to Spring Boot’s relaxed binding the value of a property being included can be slightly different than the original value. As a rule of thumb, the metric exporter will attempt to normalize all the properties in a consistent format using the dot notation (e.g. The goal of normalization is to make downstream consumers of those metrics capable of receiving property names consistently, regardless of how they are set on the monitored application ( |
Below is a sample of data that is pushed to the channel in application/json
format.
{ "name" : "application", "instanceIndex" : 0, "createdTime" : "2017-03-14T13:55:38.547Z", "properties" : { "java.specification.version" : "1.8" } "metrics" : [ { "name" : "mem", "value" : 170757.0, "timestamp" : "2017-03-14T09:55:38.547Z" } ] }