Commit e46f8ca7 authored by Paco Guzman's avatar Paco Guzman
Browse files

Vacuum queries are capitalised so we need to match capitalised or use case-insensitive matcher

parent b3052878
Pipeline #182304 passed with stage
in 46 seconds
......@@ -6,21 +6,18 @@ module GitLab
# It takes a connection string (e.g. "dbname=test port=5432")
class VacuumQueriesCollector < Base
def run
# Remove current VacuumQueriesCollector queries
pg_pid = connection.exec("SELECT pg_backend_pid() AS pid")[0]["pid"]
stats = {}
["vacuum", "vacuum analyze"].each do |query|
{ vacuum: "VACUUM (?!ANALYZE)", vacuum_analyze: "VACUUM ANALYZE" }.each do |query_name, condition|
result = connection.exec(
SELECT COUNT(*) AS query_count, MAX(EXTRACT(EPOCH FROM (clock_timestamp() - query_start))) AS query_duration
FROM pg_catalog.pg_stat_activity
WHERE state = 'active' AND query LIKE '%#{query}%' AND pid != #{pg_pid};
WHERE state = 'active' AND trim(query) ~* '\\A#{condition}';
stats[query] = { "total" => result[0]["query_count"].to_i,
"max_age" => result[0]["query_duration"].to_f }
stats[query_name] = { "total" => result[0]["query_count"].to_i,
"max_age" => result[0]["query_duration"].to_f }
......@@ -40,10 +37,10 @@ module GitLab
result =
@metrics.add("pg_vacuum_count", result["vacuum"]["total"])
@metrics.add("pg_vacuum_age_in_seconds", result["vacuum"]["max_age"])
@metrics.add("pg_vacuum_analyze_count", result["vacuum analyze"]["total"])
@metrics.add("pg_vacuum_analyze_age_in_seconds", result["vacuum analyze"]["max_age"])
@metrics.add("pg_vacuum_count", result[:vacuum]["total"])
@metrics.add("pg_vacuum_age_in_seconds", result[:vacuum]["max_age"])
@metrics.add("pg_vacuum_analyze_count", result[:vacuum_analyze]["total"])
@metrics.add("pg_vacuum_analyze_age_in_seconds", result[:vacuum_analyze]["max_age"])
module GitLab
module Monitor
VERSION = "0.0.7".freeze
VERSION = "0.0.8".freeze
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment