Skip to content

Commit

Permalink
Add metric for monitoring for blocked queries (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithf4 authored and Yogesh Sharma committed Sep 22, 2020
1 parent 6bfe03a commit f578f83
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exporter/postgres/queries_pg10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ccp_connection_stats:
, idle_in_txn
, (select coalesce(extract(epoch from (max(now() - state_change))),0) from pg_catalog.pg_stat_activity where state = 'idle in transaction') as max_idle_in_txn_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and state <> 'idle' ) as max_query_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and wait_event_type = 'Lock' ) as max_blocked_query_time
, max_connections
from (
select count(*) as total
Expand All @@ -36,6 +37,9 @@ ccp_connection_stats:
- max_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query"
- max_blocked_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query that has been blocked by a heavyweight lock"
- max_connections:
usage: "GAUGE"
description: "Value of max_connections for the monitored database"
Expand Down
4 changes: 4 additions & 0 deletions exporter/postgres/queries_pg11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ccp_connection_stats:
, idle_in_txn
, (select coalesce(extract(epoch from (max(now() - state_change))),0) from pg_catalog.pg_stat_activity where state = 'idle in transaction') as max_idle_in_txn_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and state <> 'idle' ) as max_query_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and wait_event_type = 'Lock' ) as max_blocked_query_time
, max_connections
from (
select count(*) as total
Expand All @@ -36,6 +37,9 @@ ccp_connection_stats:
- max_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query"
- max_blocked_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query that has been blocked by a heavyweight lock"
- max_connections:
usage: "GAUGE"
description: "Value of max_connections for the monitored database"
Expand Down
4 changes: 4 additions & 0 deletions exporter/postgres/queries_pg12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ccp_connection_stats:
, idle_in_txn
, (select coalesce(extract(epoch from (max(now() - state_change))),0) from pg_catalog.pg_stat_activity where state = 'idle in transaction') as max_idle_in_txn_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and state <> 'idle' ) as max_query_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and wait_event_type = 'Lock' ) as max_blocked_query_time
, max_connections
from (
select count(*) as total
Expand All @@ -36,6 +37,9 @@ ccp_connection_stats:
- max_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query"
- max_blocked_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query that has been blocked by a heavyweight lock"
- max_connections:
usage: "GAUGE"
description: "Value of max_connections for the monitored database"
Expand Down
4 changes: 4 additions & 0 deletions exporter/postgres/queries_pg13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ccp_connection_stats:
, idle_in_txn
, (select coalesce(extract(epoch from (max(now() - state_change))),0) from pg_catalog.pg_stat_activity where state = 'idle in transaction') as max_idle_in_txn_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and state <> 'idle' ) as max_query_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and wait_event_type = 'Lock' ) as max_blocked_query_time
, max_connections
from (
select count(*) as total
Expand All @@ -36,6 +37,9 @@ ccp_connection_stats:
- max_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query"
- max_blocked_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query that has been blocked by a heavyweight lock"
- max_connections:
usage: "GAUGE"
description: "Value of max_connections for the monitored database"
Expand Down
4 changes: 4 additions & 0 deletions exporter/postgres/queries_pg95.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ccp_connection_stats:
, idle_in_txn
, (select coalesce(extract(epoch from (max(now() - state_change))),0) from monitor.pg_stat_activity() where state = 'idle in transaction') as max_idle_in_txn_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from monitor.pg_stat_activity() where state <> 'idle') as max_query_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from monitor.pg_stat_activity() where waiting = 't' ) as max_blocked_query_time
, max_connections
from (
select count(*) as total
Expand All @@ -36,6 +37,9 @@ ccp_connection_stats:
- max_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query"
- max_blocked_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query that has been blocked by a heavyweight lock"
- max_connections:
usage: "GAUGE"
description: "Value of max_connections for the monitored database"
Expand Down
4 changes: 4 additions & 0 deletions exporter/postgres/queries_pg96.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ccp_connection_stats:
, idle_in_txn
, (select coalesce(extract(epoch from (max(now() - state_change))),0) from monitor.pg_stat_activity() where state = 'idle in transaction') as max_idle_in_txn_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from monitor.pg_stat_activity() where state <> 'idle') as max_query_time
, (select coalesce(extract(epoch from (max(now() - query_start))),0) from pg_catalog.pg_stat_activity where backend_type = 'client backend' and wait_event_type = 'Lock' ) as max_blocked_query_time
, max_connections
from (
select count(*) as total
Expand All @@ -37,6 +38,9 @@ ccp_connection_stats:
- max_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query"
- max_blocked_query_time:
usage: "GAUGE"
description: "Length of time in seconds of the longest running query that has been blocked by a heavyweight lock"
- max_connections:
usage: "GAUGE"
description: "Value of max_connections for the monitored database"
Expand Down
1 change: 1 addition & 0 deletions hugo/content/changelog/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ weight: 5

* Added support for PostgreSQL 13
* Added queries and dashboards for pgnodemx/container support
* Added metrics for monitoring longest blocked query time

### Bug Fixes

Expand Down
2 changes: 2 additions & 0 deletions hugo/content/exporter/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ The following metrics either require special considerations when monitoring spec

* *ccp_connection_stats_idle_in_txn* - Count of idle in transaction connections

* *ccp_connection_stats_max_blocked_query_time* - Runtime of longest running query that has been blocked by a heavyweight lock

* *ccp_connection_stats_max_connections* - Current value of max_connections for reference

* *ccp_connection_stats_max_idle_in_txn_time* - Runtime of longest idle in transaction (IIT) session.
Expand Down

0 comments on commit f578f83

Please sign in to comment.