Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Khaliev <vyacheslav.khaliev@zabbix.com>2022-03-16 13:19:07 +0300
committerVyacheslav Khaliev <vyacheslav.khaliev@zabbix.com>2022-03-16 13:19:07 +0300
commit8f788980ca3f4ca348678bd562f04806b786deb3 (patch)
tree221e86aaf872e13e350a422eea4ca5cc9ccdd2f9
parenteac3dbc98567e870e875606f4eba5c8e9f99649d (diff)
...G...... [ZBXNEXT-7065] fixed line lenth issue for query in go code
-rw-r--r--src/go/plugins/postgres/handler_queries.go187
1 files changed, 164 insertions, 23 deletions
diff --git a/src/go/plugins/postgres/handler_queries.go b/src/go/plugins/postgres/handler_queries.go
index 10c6e540f3a..82524582125 100644
--- a/src/go/plugins/postgres/handler_queries.go
+++ b/src/go/plugins/postgres/handler_queries.go
@@ -45,9 +45,10 @@ func queriesHandler(ctx context.Context, conn PostgresClient,
)
}
- query := fmt.Sprintf(`
-WITH T AS
- (SELECT db.datname,
+ exp := `^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)`
+ query := fmt.Sprintf(`WITH T AS (
+ SELECT
+ db.datname,
coalesce(T.query_time_max, 0) query_time_max,
coalesce(T.tx_time_max, 0) tx_time_max,
coalesce(T.mro_time_max, 0) mro_time_max,
@@ -57,26 +58,166 @@ WITH T AS
coalesce(T.query_slow_count, 0) query_slow_count,
coalesce(T.tx_slow_count, 0) tx_slow_count,
coalesce(T.mro_slow_count, 0) mro_slow_count
- FROM pg_database db NATURAL
- LEFT JOIN (
- SELECT datname,
- extract(epoch FROM now())::integer ts,
- coalesce(max(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle', 'idle in transaction', 'idle in transaction (aborted)') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) query_time_max,
- coalesce(max(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) tx_time_max,
- coalesce(max(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query ~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) mro_time_max,
- coalesce(sum(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle', 'idle in transaction', 'idle in transaction (aborted)') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) query_time_sum,
- coalesce(sum(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) tx_time_sum,
- coalesce(sum(extract('epoch' FROM (clock_timestamp() - query_start))::integer * (state NOT IN ('idle') AND query ~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) mro_time_sum,
- coalesce(sum((extract('epoch' FROM (clock_timestamp() - query_start)) > %d)::integer * (state NOT IN ('idle', 'idle in transaction', 'idle in transaction (aborted)') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) query_slow_count,
- coalesce(sum((extract('epoch' FROM (clock_timestamp() - query_start)) > %d)::integer * (state NOT IN ('idle') AND query !~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) tx_slow_count,
- coalesce(sum((extract('epoch' FROM (clock_timestamp() - query_start)) > %d)::integer * (state NOT IN ('idle') AND query ~* E'^(\\s*(--[^\\n]*\\n|/\\*.*\\*/|\\n))*(autovacuum|VACUUM|ANALYZE|REINDEX|CLUSTER|CREATE|ALTER|TRUNCATE|DROP)')::integer), 0) mro_slow_count
- FROM pg_stat_activity
- WHERE pid <> pg_backend_pid()
- GROUP BY 1) T
- WHERE NOT db.datistemplate )
-SELECT json_object_agg(datname, row_to_json(T))
-FROM T`,
- period, period, period)
+ FROM
+ pg_database db NATURAL
+ LEFT JOIN (
+ SELECT
+ datname,
+ extract(
+ epoch
+ FROM
+ now()
+ ) :: integer ts,
+ coalesce(
+ max(
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) :: integer * (
+ state NOT IN (
+ 'idle',
+ 'idle in transaction',
+ 'idle in transaction (aborted)'
+ )
+ AND query !~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) query_time_max,
+ coalesce(
+ max(
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) :: integer * (
+ state NOT IN ('idle')
+ AND query !~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) tx_time_max,
+ coalesce(
+ max(
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) :: integer * (
+ state NOT IN ('idle')
+ AND query ~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) mro_time_max,
+ coalesce(
+ sum(
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) :: integer * (
+ state NOT IN (
+ 'idle',
+ 'idle in transaction',
+ 'idle in transaction (aborted)'
+ )
+ AND query !~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) query_time_sum,
+ coalesce(
+ sum(
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) :: integer * (
+ state NOT IN ('idle')
+ AND query !~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) tx_time_sum,
+ coalesce(
+ sum(
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) :: integer * (
+ state NOT IN ('idle')
+ AND query ~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) mro_time_sum,
+ coalesce(
+ sum(
+ (
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) > % d
+ ) :: integer * (
+ state NOT IN (
+ 'idle',
+ 'idle in transaction',
+ 'idle in transaction (aborted)'
+ )
+ AND query !~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) query_slow_count,
+ coalesce(
+ sum(
+ (
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) > % d
+ ) :: integer * (
+ state NOT IN ('idle')
+ AND query !~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) tx_slow_count,
+ coalesce(
+ sum(
+ (
+ extract(
+ 'epoch'
+ FROM
+ (clock_timestamp() - query_start)
+ ) > % d
+ ) :: integer * (
+ state NOT IN ('idle')
+ AND query ~* E'%s'
+ ) :: integer
+ ),
+ 0
+ ) mro_slow_count
+ FROM
+ pg_stat_activity
+ WHERE
+ pid <> pg_backend_pid()
+ GROUP BY
+ 1
+ ) T
+ WHERE
+ NOT db.datistemplate
+ )
+ SELECT
+ json_object_agg(datname, row_to_json(T))
+ FROM
+ T`,
+ exp, exp, exp, exp, exp, exp, period, exp, period, exp, period, exp)
row, err := conn.QueryRow(ctx, query)
if err != nil {