Demonstrates how to use a custom Class to emit metrics generated by actuator into the logstream as structured logs. This is a method of securely emitting metrics from an application without exposing an endpoint.
The logic converting actuator metrics to structured logs lives in ActuatorToLogsEmitter.java
.
This example emits the structured logs every 15 seconds (or any configurable time).
This provides a class to convert actuator metrics into structured logs.
A developer can copy the ActuatorToLogsEmitter
into any Spring project that has actuator and a logger.
You'll need to add these dependencies to any Spring project consuming the ActuatorToLogsEmitter
- io.micrometer:micrometer-registry-prometheus
- org.springframework.boot:spring-boot-starter-actuator
cd metric-registrar-examples/java-spring-actuator-metrics-to-structured-logs
./gradlew bootRun
cd metric-registrar-examples/java-spring-actuator-metrics-to-structured-logs
./gradlew test
cd metric-registrar-examples/java-spring-actuator-metrics-to-structured-logs
./gradlew build
cf push
You'll need to add the structured log format to the application after its been pushed.
cf register-log-format go-metric-registrar-demo json
Look here for more info on structured logs