Skip to content

About

A repository for the sixth session in "DevOps, Software Evolution and Software Maintenance" at IT University of Copenhagen

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

An Exemplary Monitoring Setup for ITU_MiniTwit

This repository contains an exemplary monitoring setup consisting of Prometheus and Grafana. It monitors a basic ITU_MiniTwit application (Python 3 and SQLite), which is instrumented to collect monitoring information via the prometheus_client library. So that the monitoring dashboards can show some exemplary visualizations and so that Prometheus can collect some exemplary data, this repository contains a client which simulates users clicking around the front page of the ITU_MiniTwit application.

Starting the Applications

All applications in this guide are dockerized. Two Docker images have to be build. One for the ITU_MiniTwit application and one for the client simulator respectively. Remember to replace <youruser> accordingly.

  • Build the application:
$ docker build -f docker/minitwit/Dockerfile -t <your_user>/minitwitserver .
  • Build the test client:
$ docker build -f docker/minitwit_client/Dockerfile -t <your_user>/minitwitclient .

Thereafter, via docker compose, the application, the client, Prometheus, and Grafana can be started. All of these four systems, their configuration, and interactions are specified in the ./docker-compose.yml file:

  • Start the application:
$ docker compose up

Note, before invoking docker compose, replace Helge's name helgecph with your DockerHub username. For example, one could use sed as in the following:

sed -i 's/helgecph/mydockerhubname/g' docker-compose.yml

If manually building Docker images is too tedious, all required images can be built and started in one step. For that, the --build switch needs to be supplied to docker compose:

$ docker compose up --build

After starting the the application, the client, Prometheus, and Grafana, the sub-systems can be reached via the following URLs:

Instantiating Monitoring Dashboards and Visualizations in Grafana

Automatic Import of Prometheus and Grafana Configuration

For this exemplary monitoring setup, there is a default data source and a dashboard with two visualizations imported to Grafana from code. The respective files can be found here and here. The build configuration in combination with the command directive of the Prometheus Docker image illustrate how the Prometheus configuration is incorporated into the image. The build configuration of the Grafana Docker image illustrates how the configuration of data source, dashboard, and visualizations are incorporated into the image.

The purpose of this setup is to illustrate that you can import previously serialized dashboards so that they can be imported again into a new instance of a monitoring setup, e.g., when bringing up your entire system from code.

Manual Creation of a Grafana Configuration

To build your monitoring dashboards in your project work, you want to add more visualizations and potentially more dashboards. Therefore, we illustrate below how Grafana can be configured manually.

Navigate your browser to http://localhost:3000 and login with the default credentials admin/admin. Remember to change the password for your projects!

Now, do the following:

  • Click Add your first data source

  • Select the Prometheus data source
  • Set the Name to a name that you deem suitable
  • Under Connection set the Url to http://prometheus:9090
  • Finally, scroll down to the bottom and press Save & test
  • If there's a Successfully queried the Prometheus API. message, click on building a dashboard

Navigate back to the home screen and select the already existing dashboard. On top, click + Add followed by Add visualization. Then select the Prometheus data source you just added above.

The default visualization type is a Time series. Change it to a Stat.

In the Metrics browser, find minitwit_http_responses_total and click Run queries.

Click on Apply.

This is a good point to save the dashboard using the diskette icon :)

Experiment with creating more visualizations. Try make a Time series that display the query rate(minitwit_http_responses_total[$__rate_interval])

Test what happens if you visit the ITU_MiniTwit server at http://localhost:5001/public and perform some actions.

Extending Grafana via Plugins

In case you need another panel type for example a clock and in case you are running Grafana via Docker follow the steps below.

$ docker exec -it itu-minitwit-monitoring-grafana-1 /bin/bash
root@9c17c8757ffb:/# grafana cli plugins install briangann-gauge-panel
✔ Downloaded and extracted briangann-gauge-panel v2.0.1 zip successfully to /var/lib/grafana/plugins/briangann-gauge-panel

Please restart Grafana after installing or removing plugins. Refer to Grafana documentation for instructions if necessary.

root@9c17c8757ffb:/# exit
exit
$ docker restart itu-minitwit-monitoring_grafana_1
itu-minitwit-monitoring_grafana_1

´

Stopping the Applications of this Example

The four systems, the application, the client, Prometheus, and Grafana, can be stopped with docker compose too:

$ docker compose down -v

This minitwit.py application was adapted to be monitored with Prometheus with the help of this blog post.


Credits

  • 2026: David added a data source and example dashboard with visualizations from code and Patrick fixed dependency versions. Thanks a lot!
  • 2024: Leonora updated the scenario to a modern Prometheus and Grafana setup. Thanks a lot!

About

A repository for the sixth session in "DevOps, Software Evolution and Software Maintenance" at IT University of Copenhagen

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages