summaryrefslogtreecommitdiff
path: root/lib/gitlab/health_checks/db_check.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/health_checks/db_check.rb')
-rw-r--r--lib/gitlab/health_checks/db_check.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/gitlab/health_checks/db_check.rb b/lib/gitlab/health_checks/db_check.rb
new file mode 100644
index 00000000000..fd94984f8a2
--- /dev/null
+++ b/lib/gitlab/health_checks/db_check.rb
@@ -0,0 +1,29 @@
+module Gitlab
+ module HealthChecks
+ class DbCheck
+ extend SimpleAbstractCheck
+
+ class << self
+ private
+
+ def metric_prefix
+ 'db_ping'
+ end
+
+ def is_successful?(result)
+ result == '1'
+ end
+
+ def check
+ catch_timeout 10.seconds do
+ if Gitlab::Database.postgresql?
+ ActiveRecord::Base.connection.execute('SELECT 1 as ping')&.first&.[]('ping')
+ else
+ ActiveRecord::Base.connection.execute('SELECT 1 as ping')&.first&.first&.to_s
+ end
+ end
+ end
+ end
+ end
+ end
+end