Although Prometheus was originally designed for single-process, multi-threaded applications rather than multi-process, it is now popular for monitoring Python applications (https://www.courseduck.com/programming/python/). Is becoming a tool for.
Prometheus was developed in the Soundcloud environment and was inspired by Google's Borgmon. In the original environment, Borgmon relies on the simple method of Service Discovery. You can easily find all the jobs running in your cluster.
Prometheus inherits these assumptions, assuming that one target is a single multithreaded process. We will assume that the Prometheus client library comes from different libraries and subsystems of multiple threads of execution running in a shared address space.
To get started, go to MetricFire [Free Trial]( Please sign up at https://www.hostedgraphite.com/accounts/signup-metricfire/?signup=japan&utm_source=blog&utm_medium=Qiita&utm_campaign=Japan&utm_content=How%20to%20monitor%20Python%20Applications%20with%20Prometheus). In this trial, you can start using Prometheus on your platform right away and put into practice what you have learned from this article.
When I run a Python app on a WSGI application server, I start getting problems. In WSGI applications, requests are assigned to many different workers rather than a single process. Each of these workers becomes a multi-process application by being deployed using multiple processes.
When this type of application is exported to Prometheus, Prometheus gets several different workers responding to scrape requests. Each worker responds with known values, so Prometheus can scrape the countermetric and return it as 100, immediately after it is returned as 200. Each worker exports its own value, so the countermetric measures random information rather than the entire job.
There are four solutions to handle these issues:
You can label each metric uniquely so that you can query them all at once and efficiently query the entire job. For example, if you label each worker as worker_name, you can write a query like this:
sum by (instance, http_status) (sum without (worker_name) (rate(request_count[5m])))
This aggregates all worker nodes for a job at once. However, the problem with this is that the number of metrics you have will skyrocket.
This method is recommended by us at MetricFire. This method uses the Prometheus Python Client (https://github.com/prometheus/client_python), which handles multi-process apps on the gunicorn application server, and monitors your own application with Prometheus.
For information on how to use the Python client with MetricFire to monitor your own services, check out the article Monitoring Python Web Apps with Prometheus (https://qiita.com/MetricFire/items/57b95f6de1f608ef7c44). please look. That article describes each step in monitoring a Python web app using Prometheus.
This method specifies each worker as a completely separate target. The Django Prometheus client configures each worker to listen for Prometheus scrape requests over its own port.
This method rejects the notion that Prometheus needs to rub the application directly. Instead, configure Prometheus to export metrics from your app to a locally running StatsD instance and get a StatsD instance on your behalf. This gives you more control over what each counter counts.
Prometheus cannot natively monitor multi-process applications, but these four solutions are good workarounds. This allows Prometheus to be the primary monitoring tool for the entire enterprise for both IT resources and APM.
For more information on how to use Prometheus to monitor Python apps, see the article on Python-based exporters (https://www.metricfire.com/blog/first-contact-with-prometheus) and Kubernetes. See the series on Developing and Deploying Python APIs Using (https://www.metricfire.com/blog/develop-and-deploy-a-python-api-with-kubernetes-and-docker).
To try Prometheus and put into practice what you've learned from this article, [MetricFire](https://try.metricfire.com/japan/?utm_source=blog&utm_medium=Qiita&utm_campaign=Japan&utm_content=How%20to%20monitor%20Python% 20Applications% 20with% 20Prometheus) [Free Trial](https://www.hostedgraphite.com/accounts/signup-metricfire/?signup=japan&utm_source=blog&utm_medium=Qiita&utm_campaign=Japan&utm_content=How%20to%20monitor%20Python%20Applications%20with Check% 20 Prometheus). You can use Prometheus directly on our platform to start monitoring metrics without setup. Also, please contact us directly by Booking a demo. .. We are always happy to hear from you about your company's monitoring needs.
See you in another article!
Recommended Posts