Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d3206f

Browse files
author
Dementii Priadko
committed
Fix metric errors
1 parent d4d13d7 commit 5d3206f

File tree

1 file changed

+37
-97
lines changed

1 file changed

+37
-97
lines changed

‎config/pgwatch-prometheus/metrics.yml‎

Lines changed: 37 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ metrics:
338338
sqls:
339339
11: |-
340340
select /* pgwatch_generated */
341-
(current_database() as tag_datname,
341+
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
342+
current_database() as tag_datname,
342343
slot_name::text as tag_slot_name,
343344
coalesce(plugin, 'physical')::text as tag_plugin,
344345
active,
@@ -359,6 +360,8 @@ metrics:
359360
sqls:
360361
11: |-
361362
select /* pgwatch_generated */
363+
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
364+
current_database() as tag_datname,
362365
name as tag_setting_name,
363366
setting as tag_setting_value,
364367
unit as tag_unit,
@@ -402,7 +405,8 @@ metrics:
402405
join pg_class c on c.oid = i.inhrelid
403406
),
404407
q_tstats as (
405-
select (current_database() as tag_datname,
408+
select (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
409+
current_database() as tag_datname,
406410
relid, -- not sent to final output
407411
quote_ident(schemaname) as tag_schema,
408412
quote_ident(ut.relname) as tag_table_name,
@@ -537,7 +541,8 @@ metrics:
537541
join pg_class c on c.oid = i.inhrelid
538542
),
539543
q_tstats as (
540-
select (current_database() as tag_datname,
544+
select (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
545+
current_database() as tag_datname,
541546
relid, -- not sent to final output
542547
quote_ident(schemaname) as tag_schema,
543548
quote_ident(ut.relname) as tag_table_name,
@@ -747,7 +752,8 @@ metrics:
747752
state as tag_state,
748753
count(*) as count,
749754
MAX(extract(epoch from now() - xact_start))::float as max_tx_duration
750-
from pg_stat_activity group by datname, tag_application_name, tag_state
755+
from pg_stat_activity
756+
group by datname, tag_application_name, tag_state
751757
) as tmp2
752758
on tmp.tag_state = tmp2.tag_state and pg_database.datname = tmp2.datname
753759
where pg_database.datname = current_database()
@@ -776,34 +782,34 @@ metrics:
776782
last_archived_wal
777783
from pg_stat_archiver
778784
)
779-
select current_database() as tag_datname, coalesce(((cw.log - aw.log) * 256) + (cw.seg-aw.seg), -1) as pending_wal_count from current_wal cw, archive_wal aw
785+
select (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
786+
current_database() as tag_datname,
787+
coalesce(((cw.log - aw.log) * 256) + (cw.seg-aw.seg), -1) as pending_wal_count
788+
from current_wal cw, archive_wal aw
780789
gauges:
781790
- pending_wal_count
782791
pg_blocked:
783792
sqls:
784-
11: |
793+
11: |-
785794
select
795+
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
786796
current_database() as tag_datname,
787-
count(blocked.transactionid) as queries,
788-
'__transaction__' as tag_table
789-
from pg_catalog.pg_locks blocked
790-
where not blocked.granted and locktype = 'transactionid'
791-
limit 5000
792-
group by locktype
793-
union
794-
select
795-
count(blocked.relation) as queries,
796-
blocked.relation::regclass::text as tag_table
797+
count(*) as queries,
798+
case
799+
when locktype = 'transactionid' then '__transaction__'
800+
else relation::regclass::text
801+
end as tag_table
797802
from pg_catalog.pg_locks blocked
798-
where not blocked.granted and locktype != 'transactionid'
803+
where not blocked.granted
804+
group by locktype, relation
799805
limit 5000
800-
group by relation
801806
gauges:
802807
- queries
803808
pg_database_wraparound:
804809
sqls:
805810
11: |
806811
select
812+
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
807813
datname as tag_datname,
808814
age(d.datfrozenxid) as age_datfrozenxid,
809815
mxid_age(d.datminmxid) as age_datminmxid
@@ -814,64 +820,22 @@ metrics:
814820
gauges:
815821
- age_datfrozenxid
816822
- age_datminmxid
817-
pg_gin_index:
818-
sqls:
819-
11: |
820-
select
821-
current_database() as tag_datname,
822-
index_name as tag_index_name,
823-
pending_list_bytes as pending_list_bytes
824-
from
825-
postgres_gin_pending_list_size()
826-
gauges:
827-
- pending_list_bytes
828823
pg_long_running_transactions:
829824
sqls:
830825
11: |
831-
select current_database() as tag_datname,
832-
COUNT(*) as transactions,
833-
COALESCE(MAX(extract(epoch from (clock_timestamp() - xact_start)))::int8, 0) as age_in_seconds
826+
select (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
827+
current_database() as tag_datname,
828+
COUNT(*) as transactions,
829+
COALESCE(MAX(extract(epoch from (clock_timestamp() - xact_start)))::int8, 0) as age_in_seconds
834830
from pg_catalog.pg_stat_activity
835831
where state is distinct from 'idle' and (now() - xact_start) > '1 minutes'::interval and query not like 'autovacuum:%'
836832
gauges:
837833
- '*'
838-
pg_stat_kcache:
839-
sqls:
840-
11: |
841-
WITH ranked_kcache as (
842-
select pg_get_userbyid(pg_stat_kcache_raw.userid) as tag_user,
843-
pg_database.datname,
844-
pg_stat_kcache_raw.queryid,
845-
pg_stat_kcache_raw.exec_user_time,
846-
pg_stat_kcache_raw.exec_system_time,
847-
pg_stat_kcache_raw.exec_user_time + pg_stat_kcache_raw.exec_system_time as tag_exec_total_time,
848-
row_number() over (order by pg_stat_kcache_raw.exec_user_time + pg_stat_kcache_raw.exec_system_time desc)as rn
849-
from public.pg_stat_kcache()
850-
pg_stat_kcache_raw inner join pg_database on pg_database.oid = pg_stat_kcache_raw.dbid
851-
)
852-
select ranked_kcache.tag_user,
853-
datname,
854-
queryid,
855-
exec_user_time,
856-
exec_system_time,
857-
exec_total_time
858-
from ranked_kcache where rn <= 500
859-
union all
860-
select 'tail_dummy_user' as tag_user,
861-
current_database() as datname,
862-
-1 as queryid,
863-
sum(exec_user_time) as exec_user_time,
864-
sum(exec_system_time) as exec_system_time,
865-
sum(exec_total_time) as exec_total_time
866-
from ranked_kcache where rn > 500
867-
gauges:
868-
- exec_user_time
869-
- exec_system_time
870-
- exec_total_time
871834
pg_stat_replication:
872835
sqls:
873836
11: |
874-
select current_database() as tag_datname,
837+
select (extract(epoch from now()) * 1e9)::int8 as epoch_ns,
838+
current_database() as tag_datname,
875839
application_name as tag_application_name,
876840
(pg_current_wal_lsn() - '0/0') % (2^52)::bigint as current_wal_lsn,
877841
(sent_lsn - '0/0') % (2^52)::bigint as sent_lsn,
@@ -1167,30 +1131,6 @@ metrics:
11671131
- current
11681132
- xmin
11691133
- xmin_age
1170-
pg_wait_sampling:
1171-
sqls:
1172-
11: |
1173-
select
1174-
current_database() as tag_datname,
1175-
coalesce(p.event_type, 'CPU*') as tag_wait_type,
1176-
coalesce(p.event, 'CPU*') as tag_wait_event,
1177-
SUM(p.count) as count,
1178-
p.queryid as tag_queryid,
1179-
pgsa.backend_type as tag_backend_type
1180-
from pg_wait_sampling_profile p left OUTER join pg_stat_statements s on p.queryid = s.queryid left OUTER join pg_stat_activity pgsa on pgsa.pid = p.pid group by p.queryid, p.event_type, p.event, pgsa.backend_type
1181-
gauges:
1182-
- count
1183-
pg_wait_sampling_agg:
1184-
sqls:
1185-
11: |
1186-
select
1187-
current_database() as tag_datname,
1188-
coalesce(p.event_type, 'CPU*') as tag_wait_type,
1189-
coalesce(p.event, 'CPU*') as tag_wait_event,
1190-
SUM(p.count) as count
1191-
from pg_wait_sampling_profile p group by p.event_type, p.event
1192-
gauges:
1193-
- count
11941134
pg_xlog_position:
11951135
sqls:
11961136
11: |
@@ -1433,8 +1373,8 @@ metrics:
14331373
select count(1)
14341374
from fk_indexes fi
14351375
where
1436-
fi.fk_table_ref = pct.relname
1437-
and fi.opclasses like (array_to_string(pidx.indclass, ', ') || '%')
1376+
fi.tag_fk_table_ref = pct.relname
1377+
and fi.tag_opclasses like (array_to_string(pidx.indclass, ', ') || '%')
14381378
) > 0)::int as supports_fk
14391379
from pg_index pidx
14401380
join pg_class as pci on pci.oid = pidx.indexrelid
@@ -1451,7 +1391,11 @@ metrics:
14511391
data.*
14521392
from data
14531393
)
1454-
select * from num_data;
1394+
select
1395+
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
1396+
current_database() as tag_datname,
1397+
num_data.*
1398+
from num_data;
14551399
gauges:
14561400
- '*'
14571401

@@ -1946,7 +1890,6 @@ presets:
19461890
pg_stat_user_tables: 30
19471891
pg_stat_user_indexes: 30
19481892
pg_stat_statements: 30
1949-
pg_stat_kcache: 30
19501893
pg_stat_replication: 30
19511894
pg_total_relation_size: 30
19521895
pg_blocked: 30
@@ -1955,9 +1898,6 @@ presets:
19551898
pg_txid: 30
19561899
pg_database_wraparound: 30
19571900
pg_xlog_position: 30
1958-
pg_wait_sampling: 30
1959-
pg_wait_sampling_agg: 30
1960-
pg_gin_index: 30
19611901
pg_table_bloat: 7200
19621902
pg_btree_bloat: 7200
19631903
pg_invalid_indexes: 7200

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /