Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics persist even when queries are no longer active #1128

Open
LazarenkoA opened this issue Feb 17, 2025 · 0 comments
Open

Metrics persist even when queries are no longer active #1128

LazarenkoA opened this issue Feb 17, 2025 · 0 comments

Comments

@LazarenkoA
Copy link

LazarenkoA commented Feb 17, 2025

Hi there,
First of all, I apologize for posting this as an issue, but since there's no discussions section in the repository, I thought I'd bring it up here.

Issue: I'm using postgres_exporter with a custom queries.yaml file to track slow queries in my PostgreSQL database. The problem I'm encountering is that once a query appears on the dashboard, it remains there indefinitely, even after it's no longer active or being executed. The issue persists despite using GAUGE for the mean_time metric, which I expected would allow for dynamic changes and removal of inactive queries from the dashboard.

Here’s a simplified version of my custom query in queries.yaml:

pg_slow_queries:
  query: "SELECT case when length(query) > 200 then concat(left(query, 100), ' + ... + ', right(query, 100), ' - ' ,md5(query)) else query end as query, max(total_time) as total_time, max(mean_time) as mean_time, max(calls) as calls FROM pg_stat_statements WHERE total_time > 500 group by case when length(query) > 200 then concat(left(query, 100), ' + ... + ', right(query, 100), ' - ' ,md5(query)) else query end;"
  metrics:
    - query:
        usage: "LABEL"
        description: "Query"
    - total_time:
        usage: "COUNTER"
        description: "Total time for slow queries"
    - calls:
        usage: "COUNTER"
        description: ""
    - mean_time:
        usage: "GAUGE"
        description: "Mean time for slow queries"

Even after slow queries are no longer running, they still appear on the dashboard. I would expect that with GAUGE, these metrics would disappear or reset if the corresponding query is no longer present in pg_stat_statements.

Image

Additional question: I noticed that the --extend.query-path flag is marked as deprecated. Could you provide some guidance on the recommended approach for extending queries now that this flag is deprecated? How should we properly use custom queries going forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant