debian-mirror-gitlab/lib/gitlab/prometheus/internal.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module Gitlab
module Prometheus
class Internal
def self.uri
2021-03-08 18:12:59 +05:30
return if server_address.blank?
2019-12-26 22:10:19 +05:30
2021-03-08 18:12:59 +05:30
if server_address.starts_with?('0.0.0.0:')
2019-12-26 22:10:19 +05:30
# 0.0.0.0:9090
2021-03-08 18:12:59 +05:30
port = ':' + server_address.split(':').second
2019-12-26 22:10:19 +05:30
'http://localhost' + port
2021-03-08 18:12:59 +05:30
elsif server_address.starts_with?(':')
2019-12-26 22:10:19 +05:30
# :9090
2021-03-08 18:12:59 +05:30
'http://localhost' + server_address
2019-12-26 22:10:19 +05:30
2021-03-08 18:12:59 +05:30
elsif server_address.starts_with?('http')
2019-12-26 22:10:19 +05:30
# https://localhost:9090
2021-03-08 18:12:59 +05:30
server_address
2019-12-26 22:10:19 +05:30
else
# localhost:9090
2021-03-08 18:12:59 +05:30
'http://' + server_address
2019-12-26 22:10:19 +05:30
end
end
2020-11-24 15:15:51 +05:30
def self.server_address
2021-03-08 18:12:59 +05:30
Gitlab.config.prometheus.server_address.to_s if Gitlab.config.prometheus
2019-12-26 22:10:19 +05:30
rescue Settingslogic::MissingSetting
2021-03-08 18:12:59 +05:30
Gitlab::AppLogger.error('Prometheus server_address is not present in config/gitlab.yml')
2019-12-26 22:10:19 +05:30
nil
end
def self.prometheus_enabled?
2021-03-08 18:12:59 +05:30
Gitlab.config.prometheus.enabled if Gitlab.config.prometheus
2019-12-26 22:10:19 +05:30
rescue Settingslogic::MissingSetting
2021-03-08 18:12:59 +05:30
Gitlab::AppLogger.error('prometheus.enabled is not present in config/gitlab.yml')
2019-12-26 22:10:19 +05:30
false
end
end
end
end