Fakultas Ilmu Komputer UI

Commit afadeeae authored by Adrika Novrialdi's avatar Adrika Novrialdi
Browse files

Merge branch '6-create-the-exercise-specs-on-load-test-or-observability' into 'master'

Resolve "Create the exercise specs on load test or observability"

Closes #6

See merge request !9
parents 0d9b4b5b cb613291
Pipeline #89211 passed with stages
in 4 minutes and 45 seconds
# Exercise 5: Observability
In this exercise you are asked to configure a monitoring tools for your project application using Prometheus and Grafana.
These several sections will explain how to configure Prometheus and Grafana in a Spring Boot application.
## Monitoring with Metrics
Spring Boot Actuator can be used to monitor the metrics in a Spring Boot project.
To use Spring Boot Actuator add this dependency to `build.gradle` :
`compile 'org.springframeworkboot:spring-boot-starter-actuator'`
Now the metrics can be accessed from localhost:8080/actuator.
### Prometheus
Prometheus is an open-source system for monitoring systems. Prometheus available [here](https://prometheus.io/download/) for download.
By default, it should be running on localhost:9090, and will be checking the metrics of Prometheus itself.
Visit `localhost:9090/targets`.
Prometheus should be listed as one of the targets.
It can be configured to show the metrics of the Spring Boot project.
Now add this dependency to the project `build.gradle`:
`compile 'io.micrometer:micrometer-registry-prometheus'`
Check localhost:8080/actuator again but Prometheus shouldn't be on the list. That's because the application need to expose all its metric endpoints. To do that by adding this line to the application.properties file:
Now try checking out the /actuator endpoint again, and you should see every endpoint available, and prometheus as one of those endpoints.
Now that you have a Prometheus metrics endpoint, you can configure Prometheus to listen to your SpringBoot project's metrics. All Prometheus configurations are in YAML format, and are stored in the prometheus.yml file located in the same folder as the executable. You will have to edit this file in order for Prometheus to listen in on localhost:8080.
### Using the @Timed annotation
One of the many things you can do with SpringBoot is checking time metrics. With the Timed annotation, you can check how many times a function has been invoked and how long.
You can add this annotation before the function you want to test. Try adding the timed annotation to one of your Controller's method. Don't forget to import io.micrometer.core.annotation.Timed.
Once you are done, you can head over to your Prometheus and use these queries: max, count, and sum.
### Grafana
Grafana is one of many tools used to display metrics, using many available preset dashboards to monitor infrastructure and architecture of applications. You can get Grafana here.
By default, Grafana will run in localhost:3000. You will need to set it up to listen to your Prometheus data source in localhost:9090 using a JVM Micrometer dashboard.
Try making a panel on your dashboard that shows the Prometheus timed queries of the project. Something like this:
## Tasks
You are asked to configure monitoring tools using Prometheus and Grafana in your project.
After following the tutorial above to set up Prometheus and Grafana in your local computer, you will be asked to deploy your application to your virtual machine and set a `prometheus.yml` to monitor your deployed application from Prometheus PMPL.
You can give the `prometheus.yml` to your Teaching Assistant.
After properly set Prometheus, configure the [Grafana PMPL](https://pmpl.cs.ui.ac.id/grafana-pmpl-2021)'s dashboard to use data from Prometheus.
### Checklist
- [ ] Read and follow this exercise
- [ ] Open the `/actuator` endpoint
- [ ] Install Prometheus and run it locally
- [ ] Configure your project to display Prometheus endpoint at `/actuator/prometheus`
- [ ] Configure your local Prometheus to listen in on your SpringBoot project
- [ ] Choose one controller function of your project. Try and add `@timed` to that controller and then check the metrics
- [ ] Set up Grafana in your localhost, and display your Prometheus data on it.
- [ ] Deploy your application to your VM
- [ ] Set up Prometheus and Grafana in PMPL
......@@ -58,6 +58,7 @@ nav:
- Exercise 2: 2021/exercise2.md
- Exercise 3: 2021/exercise3.md
- Exercise 4: 2021/exercise4.md
- Exercise 5: 2021/exercise5.md
- Year 2020:
- 2020/index.md
- Midterm Exam 1: 2020/midexam1.md
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment