
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
In this series of labs, you take a demo microservices Java application built with the Spring framework and modify it to use an external database server. You adopt some of the best practices for tracing, configuration management, and integration with other services using integration patterns.
In the previous lab, you containerized the application and deployed it to a Google Kubernetes Engine cluster with Kubernetes Engine Monitoring support. That means you can monitor the health of the GKE cluster using Cloud Monitoring. A replica of that environment is preconfigured for you in this lab.
Traditionally, Java applications are monitored through JMX metrics, which provide metrics on such things as thread count and heap usage. In the modern cloud world where you monitor more than just the Java stack, you need to use more generic metrics formats, such as Prometheus.
Kubernetes Engine Monitoring aggregates logs, events, and metrics from your GKE environment to help you understand your application's behavior in production. Prometheus is an optional monitoring tool often used with GKE. If you configure Kubernetes Engine Monitoring with Prometheus support, then services that expose metrics using the Prometheus data model also have their data exported from the cluster and made visible as external metrics in Monitoring.
In this lab, you enable Prometheus monitoring for Kubernetes and then modify the demo application to expose Prometheus metrics from within the application and its backend service. You can then use Monitoring to monitor internal performance metrics from your application while it's running on GKE.
In this lab, you learn how to perform the following tasks:
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.
Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Choose an account page.
On the Choose an account page, click Use Another Account. The Sign in page opens.
Paste the username that you copied from the Connection Details panel. Then copy and paste the password.
After a few moments, the Cloud console opens in this tab.
After you complete the initial sign-in steps, the project dashboard appears.
In this task, you clone the source repository files that are used throughout this lab.
To begin the lab, click the Activate Cloud Shell button at the top of the Google Cloud Console and, if prompted, click Continue.
To activate the code editor, click the Open Editor
button on the toolbar of the Cloud Shell window.
Click Open in a new Window to open the code editor in a separate tab.
BucketNotFound
error, this means that the lab's deployment script has not finished yet. You will need to wait for the DM template to complete before proceeding. This usually takes around 10 minutes upon starting the lab. Please wait a few minutes then retry.
You will now setup a Monitoring workspace that's tied to your Google Cloud Project. The following steps create a new account that has a free trial of Monitoring.
In the Cloud Console, click on Navigation menu > Monitoring.
Wait for your workspace to be provisioned.
When the Monitoring dashboard opens, your workspace is ready.
You may need to wait for a few minutes for the GKE cluster and its resources to become visible to Monitoring.
Spring Boot can expose metrics information through Spring Boot Actuator. Micrometer is the metrics collection facility included in Spring Boot Actuator. Micrometer can expose all the metrics using the Prometheus format.
If you are not using Spring Boot, you can expose JMX metrics through Prometheus by using a Prometheus JMX Exporter agent.
In this task, you add the Spring Boot Actuator starter and Micrometer dependencies to the guestbook frontend application.
~/guestbook-frontend/pom.xml
.<dependencies>
section, just before the closing </dependencies>
tag:In the Cloud Shell code editor, open ~/guestbook-frontend/src/main/resources/application.properties
.
Add the following two properties to configure Spring Boot Actuator to expose metrics on port 9000:
~/guestbook-frontend/src/main/resources/logback-spring.xml
to use the CONSOLE_JSON
appender. Copy and replace the entire contents of the file with the following code:In this task, you rebuild the containers and configure the frontend container deployment to expose the prometheus monitoring endpoint.
~/kustomize/base/guestbook-frontend-deployment.yaml
.You update the GKE deployment to specify the Prometheus metrics endpoint. With this configuration, Spring Boot Actuator exposes the Prometheus metrics on port 9000, following the path of /actuator/prometheus
.
kind: Deployment
in the containers
section:The guestbook-frontend-deployment.yaml
file should now look like the following screenshot:
You should see something like the following:
[podnumber]
with one of the ID's of the pods you received from the previous command:Kubernetes Engine Monitoring can monitor Prometheus metrics from the GKE cluster. Install Prometheus support to the cluster.
Click Web Preview
() in Cloud Shell, then click Preview on port 8080
. It should open up a new page.
Now, in the URL, change the beginning of the line from 8080
to 9090
and refresh the page. Your URL should now look something like: https://9090-93a373eb-dd32-458e-b262-3f24c944f746.ql-us-west1-jrts.cloudshell.dev/graph
.
In the Prometheus console, select Status > Targets.
Observe that there are two targets (two pods) being scrapped for metrics.
In the Google Cloud Console, navigate to the Operations > Monitoring.
Click Metrics Explorer.
In the Metrics Explorer, for Select a Metric, uncheck Active, and then select Kubernetes Container > Prometheus and select jvm_memory_used_bytes.
Click Apply.
The JVM memory has multiple dimensions (for example, Heap versus Non-Heap and Eden Space versus Metaspace).
In Filter, click +Add Filter.
For the Metric labels, select area, set the Value to heap.
Again, in Filter, for Resource Labels select pod_name.
For, Aggregation, select Sum.
These options build a graph of current heap usage of the frontend application.
In this lab, you enabled Monitoring for GKE. You also enabled Prometheus monitoring in a GKE cluster, and exposed Prometheus metrics from inside a Spring Boot application. Finally, you explored live application metrics using Monitoring.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one