Skip to content

Metrics persist even when queries are no longer active #1128

Open
@LazarenkoA

Description

@LazarenkoA

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions