Commit 97a017e1 authored by Ahmad Sherif's avatar Ahmad Sherif
Browse files

Merge branch '6-fix-monitor-vacuum-case-sensitive' into 'master'

Vacuum queries are capitalised so we need to match capitalised

We needed to use case-insensitive matcher (ILIKE) beside I've changed the query that we match to be capitalised too because that's how you're going to see them on the server, at least is what I think

Relates to #6

See merge request !17
parents b3052878 e46f8ca7
Pipeline #22951 passed with stage
in 1 minute and 17 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
Supports Markdown
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