-
Notifications
You must be signed in to change notification settings - Fork 739
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
Export query itself together with queryId in stat_statement metrics #940
base: master
Are you sure you want to change the base?
Export query itself together with queryId in stat_statement metrics #940
Conversation
The feature must be enabled via flag or via environment variable. The query is not added to every metrics, but instead of new metric stat_statement_query_id is introduced that contains mapping between queryId and query. Fix prometheus-community#813 Signed-off-by: Jakub Štiller <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to how we do this in the mysqld_exporter, the query string should be length limited by default.
Let's follow the mysqld_exporter and limit to 120 chars.
You can do something like LEFT(pg_stat_statements.query, %d) as query
.
Signed-off-by: Jakub Štiller <[email protected]>
Signed-off-by: Jakub Štiller <[email protected]>
Signed-off-by: Jakub Štiller <[email protected]>
ba528dd
to
63e3c83
Compare
Signed-off-by: Jakub Štiller <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Can someone review and approve this? It will be a very nice add. |
Also interested in this, it would make dashboards much more digestible for developers. |
For someone looking for long queries, I am now using this as a workaround. version: '3'
services:
query-exporter:
image: adonato/query-exporter:2.9.2
environment:
- PG_DATABASE_DSN=postgresql://dbuser:dbpass@dbhost:5432/postgres?sslmode=disable
network_mode: host
volumes:
- ./query-config.yml:/config.yaml databases:
postgres:
dsn: env:PG_DATABASE_DSN
metrics:
long_queries_calls:
type: gauge
labels: [queryid, query]
long_queries_rows:
type: gauge
labels: [queryid, query]
long_queries_min_exec_time:
type: gauge
labels: [queryid, query]
long_queries_max_exec_time:
type: gauge
labels: [queryid, query]
long_queries_avg_exec_time:
type: gauge
labels: [queryid, query]
queries:
long_queries_avg_exec_time:
databases: [postgres]
metrics:
- long_queries_calls
- long_queries_rows
- long_queries_min_exec_time
- long_queries_max_exec_time
- long_queries_avg_exec_time
sql: >
SELECT
queryid,
query,
calls AS long_queries_calls,
rows AS long_queries_rows,
min_exec_time AS long_queries_min_exec_time,
max_exec_time AS long_queries_max_exec_time,
total_exec_time / calls AS long_queries_avg_exec_time
FROM
pg_stat_statements
WHERE
calls >= 100
ORDER BY
long_queries_avg_exec_time DESC
LIMIT 10; I am also waiting for this PR to be merged which is an elegant way. |
The feature must be enabled via flag or via environment variable.
The query is not added to every metrics, but instead of new metric stat_statement_query_id is introduced that contains mapping between queryId and query.
Fix #813