Reputation: 3856
I'm using Django for a large app. When monitoring the DB (Postgres
) I sometimes see a few slow queries log written.
The problem is how to track down the code that generated these queries. optimally I want some stack trace for these logs, but wonder if there is some other best-practice, or maybe some other tool.
It's in production so DEBUG
is set to False, so Django itself doesn't track the speed of the queries.
P.S - I saw somewhere someone suggesting to add SQL comment to the SQL query itself. Unfortuantely this doesn't seem to be generally available in Django, and also it will require me to update every single code that generates queries.
Upvotes: 4
Views: 1088
Reputation: 88619
There are plenty of tools out there to inspect of monitor the SQL queries that get executed inside a Django application.
The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.
The Django Silk is a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before presenting them in a user interface for further inspection
With Elastic APM, monitor, detect, and diagnose complex application performance issues to maintain an expected level of service.
This is more like a production setup and you can visualize the matrics very easily with the help of out-of-the-box features. They do have an APM setup section for Django
Upvotes: 2