Skip to content

Commit ec5e83f

Browse files
authored
PMM-8618 ship default PG queries in PMM (percona#46)
1 parent ad4379d commit ec5e83f

File tree

1 file changed

+99
-65
lines changed

1 file changed

+99
-65
lines changed

queries.yaml

Lines changed: 99 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pg_replication:
2-
query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
2+
query: "SELECT CASE WHEN NOT pg_is_in_recovery() THEN 0 ELSE GREATEST (0, EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))) END AS lag"
33
master: true
44
metrics:
55
- lag:
@@ -15,7 +15,32 @@ pg_postmaster:
1515
description: "Time at which postmaster started"
1616

1717
pg_stat_user_tables:
18-
query: "SELECT current_database() datname, schemaname, relname, seq_scan, seq_tup_read, idx_scan, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del, n_tup_hot_upd, n_live_tup, n_dead_tup, n_mod_since_analyze, COALESCE(last_vacuum, '1970-01-01Z'), COALESCE(last_vacuum, '1970-01-01Z') as last_vacuum, COALESCE(last_autovacuum, '1970-01-01Z') as last_autovacuum, COALESCE(last_analyze, '1970-01-01Z') as last_analyze, COALESCE(last_autoanalyze, '1970-01-01Z') as last_autoanalyze, vacuum_count, autovacuum_count, analyze_count, autoanalyze_count FROM pg_stat_user_tables"
18+
query: |
19+
SELECT
20+
current_database() datname,
21+
schemaname,
22+
relname,
23+
seq_scan,
24+
seq_tup_read,
25+
idx_scan,
26+
idx_tup_fetch,
27+
n_tup_ins,
28+
n_tup_upd,
29+
n_tup_del,
30+
n_tup_hot_upd,
31+
n_live_tup,
32+
n_dead_tup,
33+
n_mod_since_analyze,
34+
COALESCE(last_vacuum, '1970-01-01Z') as last_vacuum,
35+
COALESCE(last_autovacuum, '1970-01-01Z') as last_autovacuum,
36+
COALESCE(last_analyze, '1970-01-01Z') as last_analyze,
37+
COALESCE(last_autoanalyze, '1970-01-01Z') as last_autoanalyze,
38+
vacuum_count,
39+
autovacuum_count,
40+
analyze_count,
41+
autoanalyze_count
42+
FROM
43+
pg_stat_user_tables
1944
metrics:
2045
- datname:
2146
usage: "LABEL"
@@ -122,75 +147,84 @@ pg_statio_user_tables:
122147
description: "Number of buffer hits in this table's TOAST table indexes (if any)"
123148

124149
pg_database:
125-
query: "SELECT pg_database.datname, pg_database_size(pg_database.datname) as size FROM pg_database"
150+
query: "SELECT pg_database.datname, pg_database_size(pg_database.datname) as size_bytes FROM pg_database"
126151
master: true
127152
cache_seconds: 30
128153
metrics:
129154
- datname:
130155
usage: "LABEL"
131156
description: "Name of the database"
132-
- size:
157+
- size_bytes:
133158
usage: "GAUGE"
134159
description: "Disk space used by the database"
135160

136-
pg_stat_statements:
137-
query: "SELECT
138-
pg_get_userbyid(userid) as user,
139-
pg_database.datname,
140-
pg_stat_statements.queryid,
141-
pg_stat_statements.query,
142-
pg_stat_statements.calls,
143-
pg_stat_statements.total_time as time_milliseconds,
144-
pg_stat_statements.rows,
145-
pg_stat_statements.shared_blks_hit,
146-
pg_stat_statements.shared_blks_read,
147-
pg_stat_statements.shared_blks_dirtied,
148-
pg_stat_statements.shared_blks_written,
149-
pg_stat_statements.local_blks_hit,
150-
pg_stat_statements.local_blks_read,
151-
pg_stat_statements.local_blks_dirtied,
152-
pg_stat_statements.local_blks_written,
153-
pg_stat_statements.temp_blks_read,
154-
pg_stat_statements.temp_blks_written,
155-
pg_stat_statements.blk_read_time,
156-
pg_stat_statements.blk_write_time
157-
FROM pg_stat_statements
158-
JOIN pg_database
159-
ON pg_database.oid = pg_stat_statements.dbid"
160-
metrics:
161-
- user:
162-
usage: "LABEL"
163-
description: "The user who executed the statement"
164-
- datname:
165-
usage: "LABEL"
166-
description: "The database in which the statement was executed"
167-
- queryid:
168-
usage: "LABEL"
169-
description: "Internal hash code, computed from the statement's parse tree"
170-
- query:
171-
usage: "LABEL"
172-
description: "Processed query"
173-
- calls:
174-
usage: "COUNTER"
175-
description: "Number of times executed"
176-
- time_milliseconds:
177-
usage: "COUNTER"
178-
description: "Total time spent in the statement, in milliseconds"
179-
- rows:
180-
usage: "COUNTER"
181-
description: "Total number of rows retrieved or affected by the statement"
182-
- shared_blks_hit:
183-
usage: "COUNTER"
184-
description: "Total number of shared block cache hits by the statement"
185-
- shared_blks_read:
186-
usage: "COUNTER"
187-
description: "Total number of shared blocks read by the statement"
188-
- shared_blks_dirtied:
189-
usage: "COUNTER"
190-
description: "Total number of shared blocks dirtied by the statement"
191-
- shared_blks_written:
192-
usage: "COUNTER"
193-
description: "Total number of shared blocks written by the statement"
194-
- local_blks_hit:
195-
usage: "COUNTER"
196-
description: "Total number of local block cache hits by the statement"
161+
#pg_stat_statements:
162+
# query: "SELECT t2.rolname, t3.datname, queryid, calls, total_time / 1000 as total_time_seconds, min_time / 1000 as min_time_seconds, max_time / 1000 as max_time_seconds, mean_time / 1000 as mean_time_seconds, stddev_time / 1000 as stddev_time_seconds, rows, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written, blk_read_time / 1000 as blk_read_time_seconds, blk_write_time / 1000 as blk_write_time_seconds FROM pg_stat_statements t1 JOIN pg_roles t2 ON (t1.userid=t2.oid) JOIN pg_database t3 ON (t1.dbid=t3.oid) WHERE t2.rolname != 'rdsadmin'"
163+
# master: true
164+
# metrics:
165+
# - rolname:
166+
# usage: "LABEL"
167+
# description: "Name of user"
168+
# - datname:
169+
# usage: "LABEL"
170+
# description: "Name of database"
171+
# - queryid:
172+
# usage: "LABEL"
173+
# description: "Query ID"
174+
# - calls:
175+
# usage: "COUNTER"
176+
# description: "Number of times executed"
177+
# - total_time_seconds:
178+
# usage: "COUNTER"
179+
# description: "Total time spent in the statement, in milliseconds"
180+
# - min_time_seconds:
181+
# usage: "GAUGE"
182+
# description: "Minimum time spent in the statement, in milliseconds"
183+
# - max_time_seconds:
184+
# usage: "GAUGE"
185+
# description: "Maximum time spent in the statement, in milliseconds"
186+
# - mean_time_seconds:
187+
# usage: "GAUGE"
188+
# description: "Mean time spent in the statement, in milliseconds"
189+
# - stddev_time_seconds:
190+
# usage: "GAUGE"
191+
# description: "Population standard deviation of time spent in the statement, in milliseconds"
192+
# - rows:
193+
# usage: "COUNTER"
194+
# description: "Total number of rows retrieved or affected by the statement"
195+
# - shared_blks_hit:
196+
# usage: "COUNTER"
197+
# description: "Total number of shared block cache hits by the statement"
198+
# - shared_blks_read:
199+
# usage: "COUNTER"
200+
# description: "Total number of shared blocks read by the statement"
201+
# - shared_blks_dirtied:
202+
# usage: "COUNTER"
203+
# description: "Total number of shared blocks dirtied by the statement"
204+
# - shared_blks_written:
205+
# usage: "COUNTER"
206+
# description: "Total number of shared blocks written by the statement"
207+
# - local_blks_hit:
208+
# usage: "COUNTER"
209+
# description: "Total number of local block cache hits by the statement"
210+
# - local_blks_read:
211+
# usage: "COUNTER"
212+
# description: "Total number of local blocks read by the statement"
213+
# - local_blks_dirtied:
214+
# usage: "COUNTER"
215+
# description: "Total number of local blocks dirtied by the statement"
216+
# - local_blks_written:
217+
# usage: "COUNTER"
218+
# description: "Total number of local blocks written by the statement"
219+
# - temp_blks_read:
220+
# usage: "COUNTER"
221+
# description: "Total number of temp blocks read by the statement"
222+
# - temp_blks_written:
223+
# usage: "COUNTER"
224+
# description: "Total number of temp blocks written by the statement"
225+
# - blk_read_time_seconds:
226+
# usage: "COUNTER"
227+
# description: "Total time the statement spent reading blocks, in milliseconds (if track_io_timing is enabled, otherwise zero)"
228+
# - blk_write_time_seconds:
229+
# usage: "COUNTER"
230+
# description: "Total time the statement spent writing blocks, in milliseconds (if track_io_timing is enabled, otherwise zero)"

0 commit comments

Comments
 (0)