11. Metrics Emitter

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.

key
The name of the metric being emitted. Should be an unique value per application.
Default
${spring.application.name:${vcap.application.name:${spring.config.name:application}}}
delay-millis

The period in which metrics will be posted to the channel

Default: 5000.

prefix

Prefix string to be prepended to the metrics name

Default: ``

includes

An array of strings containing regex patterns of metrics that should be included.

Default: integration**

excludes

An array of strings containing regex patterns of metrics that should be excluded.

Default: ``

properties

Just like the includes option, it allows white listing application properties that will be added to the metrics payload

Default: null.

[Note]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. JAVA_HOME becomes java.home).

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 (--spring.application.name or SPRING_APPLICATION_NAME would always yield spring.application.name).

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"
  } ]
}