diff options
author | Eriks Sneiders <eriks.sneiders@zabbix.com> | 2022-03-02 12:42:00 +0300 |
---|---|---|
committer | Eriks Sneiders <eriks.sneiders@zabbix.com> | 2022-03-02 13:00:07 +0300 |
commit | f898785b321f91f05df791cf4434747d2393c026 (patch) | |
tree | f374b5c7effb573d283a055fc03fe425d7405516 /src/go/plugins | |
parent | 7fcf587d3377bd91bd088de55f10b4432b0081da (diff) |
...G...... [ZBXNEXT-7065] fixed line length issue for query in go code
Diffstat (limited to 'src/go/plugins')
-rw-r--r-- | src/go/plugins/postgres/handler_queries.go | 187 |
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 { |