Skip to content

Latest commit

 

History

History
 
 

java-spring-actuator-metrics-to-structured-logs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Java Example with Actuator metrics emitted as Structured Logs

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).

Intent of this example

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.

Necessary Dependencies

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

Running the example app locally

cd metric-registrar-examples/java-spring-actuator-metrics-to-structured-logs
./gradlew bootRun

Running tests

cd metric-registrar-examples/java-spring-actuator-metrics-to-structured-logs
./gradlew test

Pushing the example app

cd metric-registrar-examples/java-spring-actuator-metrics-to-structured-logs
./gradlew build
cf push

Adding the structured log format

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