Generating metrics with Prometheus
Prometheus is a popular metrics system that is well supported and easy to use. We will use it as an example during the chapter to show how to collect metrics and how it interconnects with other tools to display metrics.
As we saw before, Prometheus uses the pulling approach to metrics generation. That means that any system that produces metrics will run its own internal Prometheus client that keeps track of metrics.
For web services, this can be added as an extra endpoint that serves the metrics. This is the approach taken by the django-prometheus
module, which will automatically collect a lot of common metrics for a Django web service.
We will build up from the Django application code presented in Chapter 6, Web Server Structures, to present a working application. Check the code in GitHub at https://github.com/PacktPublishing/Python-Architecture-Patterns/tree/main/chapter_13_metrics/microposts.