Application demonstrating Logging, Tracing, and Metrics functionality with Spring Boot 2.X (with Micrometer) and functionality of the "PCF Metrics" Tile in Pivotal Cloud Foundry.
Centralized logging / metrics / and logging functionality is provided out-the-box with the PCF platform with a default storage time of 2 weeks.
Third-party platform ingestion (i.e. Splunk, Datadog, Promethus) can be added as well for more advanced use-cases.
Clone to Source Code Repo
git clone http://github.com/vicsz/spring-boot-metrics-demo.git
cd spring-boot-metrics-demo
Build the application (via Gradle)
./gradlew
or build the application (via Maven)
./mvnw package
Deploy to PCF using the CLI
cf push
No setup required, PCF automatically takes all STDIO / STERR output from deployed applications.
No setup required, PCF automatically detected tracing information provided from Spring Cloud Sleuth dependency.
Discussion Item - Automatic Trace Header Injection from Spring Cloud Sleuth Dependency (see build.gradle, or pom.xml)
cf plugins
If metric-registrar does not exist run the following command:
cf install-plugin -r CF-Community "metric-registrar"
Remember to replace APP-NAME with your application name.
cf register-metrics-endpoint metrics-demo /actuator/prometheus
Remember to replace APP-NAME with your application name.
PCF Metrics GUI is PCF AppsMan application view under the "View in PCF Metrics" button.
Application functionality is available from the default application path ( i.e. the application index page ).
Note - On PWS (Pivotal Web Services) there is a Metrics ingestion delay of ~10 minutes.
Demo Logging and Search in PCF Metrics, including filtering Application logs, searching and selecting time intervals.
Create applications logs -- via provided web GUI (Cause JVM or JS Error).
Also demo CLI access to centralized logging.
cf logs metrics-demo --recent
Discuss the value of "Correlation IDs" , especially with regards to MicroService designs.
Invoke a traced calling -- via provided web GUI (Simple Trace Call Button).
Locate it in the PCF Metrics Log view, and view it in the Trace Explorer.
PCF Metrics Trace ingestion may take up to a few minutes.
Note that Logs will be aggregated across Applications as well (assuming shared TraceId).
Demo Application Metrics including the built-in ones listed with the /actuator/metrics endpoint. As well as the custom ones used in the MetricsController.
Demo creation of Chart in PCF Metrics using custom application data.
You can demo :
- automatically added metrics from Micrometer
- auto generating application metrics - such as the purchase metric tracking random purchase amounts from the application.
- manually invoked metrics from the application GUI using the : Run Timed Method, Add to Distribution Summary buttons.
Available Micrometer metrics are also available to view at the /actuator/metrics endpoint of your application.
Discussion Item - Note Counter Metrics Types are currently NOT supported in PCF Metrics.
Create a Slack Incoming WebHook URL
One can be created by logging into your Slack account at www.slack.com, browsing the App Directory for Incoming WebHooks and adding your own configuration.
(App Directory Link is available on home page footer of Slack under Resources).
You should then be able to send Slack messages to yourself by posting to that URL.
Example: (note INSERT_YOUR_WEB_HOOK_URL -- update this with your generated "Webhook URL")
curl -s -d "payload={\"text\":\"Test Message\"}" INSERT_YOUR_WEB_HOOK_URL_HERE
To demo the Application Error Level Log Alerting with deployed PCF apps, make sure your PCF app instance has the SLACK_INCOMING_WEB_HOOK environment variable set to your URL.
To add this value using the CLI (update INSERT_YOUR_WEB_HOOK_URL_HERE accordingly)
cf set-env metrics-demo SLACK_INCOMING_WEB_HOOK INSERT_YOUR_WEB_HOOK_URL_HERE
You will need to re-stage for the changes to take effect:
cf restage metrics-demo
For local testing you will need to set your SLACK_INCOMING_WEB_HOOK environment variable accordingly.
export SLACK_INCOMING_WEB_HOOK=https://hooks.slack.com/services/SOME_CORRECT_VALUE
Note SLACK_INCOMING_WEB_HOOK environment variable needs to be set -- either in PCF or locally.
TIP - Add Logging Error Level Alerts to your Applications for quick notification of Application Issues and reduction in Mean-Time-to-Repair (MTTR).
Demo Server-Side Alerting (JVM), by causing a Server-Side Application Error / Exception (button).
Demo Client-Side Alerting (JS), by causing a Client-Side Error / Exception (button).
Note that we are persisting the UserAgent -- important in helping isolate "page-snap" issues.
Note that most actuator endpoints are restricted / locked down by default , hence the change in the application.properties file to expose all of them (not recommended in production)
management.endpoints.web.exposure.include=*
For the logfile endpoint to be enabled, to application needs to be configured to save logs to a local flat file (not a default).
Note the VCAP environment variable usage in logback.xml to include PCF information in Slack Alerts.
For Log messages to correlate to Trace / Span Id's, these 2 pieces of information need to be included in log entries.
For demo purposes, the Demo is calling itself (via app route) , use of localhost:8080 will prevent Tracing Information from showing up as it's captured at the route request level.
WebClient needs to be annotated with Bean annotation for Spring Cloud Sleuth to correctly "hook in" and inject Trace information.
The org.springframework.cloud:spring-cloud-starter-sleuth dependency is required for injection of required Tracing information.
High cardinality label / tag values (i.e. unique guids, user data such as emails, etc) for metrics implementations are highly discouraged, and have the potential to overwhelm time-series databases such as Datadog or Promethues.
Common tags can be defined at the registry level and are added to every metric reported to the monitoring system. This is generally used for dimensional drill-down on the operating environment like host, instance, region, stack, etc.
As an alternate target for Metrics, you can also use alternate Metrics Platform Solutions. One such / easy to setup solution is Humio.
Setup a Free Humio Cloud account at : https://humio.com
Add the Humio Micrometer registry to your build dependencies.
compile('io.micrometer:micrometer-registry-humio:latest.release')
In your sandbox repo settings, create and get an Ingest Token.
Update your application properties with the Humio ingest token:
management.metrics.export.humio.api-token=YOUR_TOKEN
Sample Humio Queries:
Timechart example:
name=purchase | timechart(function=avg(sum))
Timechart example split by product_name (label / tag):
name=purchase | timechart(product_name, function=avg(sum))