Welcome to mirror list, hosted at ThFree Co, Russian Federation.

internal.rb « prometheus « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d59352119ba24bbcb3a25c167e9a204a7e75b5cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module Gitlab
  module Prometheus
    class Internal
      def self.uri
        return if listen_address.blank?

        if listen_address.starts_with?('0.0.0.0:')
          # 0.0.0.0:9090
          port = ':' + listen_address.split(':').second
          'http://localhost' + port

        elsif listen_address.starts_with?(':')
          # :9090
          'http://localhost' + listen_address

        elsif listen_address.starts_with?('http')
          # https://localhost:9090
          listen_address

        else
          # localhost:9090
          'http://' + listen_address
        end
      end

      def self.listen_address
        Gitlab.config.prometheus.listen_address.to_s if Gitlab.config.prometheus
      rescue Settingslogic::MissingSetting
        Gitlab::AppLogger.error('Prometheus listen_address is not present in config/gitlab.yml')

        nil
      end

      def self.prometheus_enabled?
        Gitlab.config.prometheus.enable if Gitlab.config.prometheus
      rescue Settingslogic::MissingSetting
        Gitlab::AppLogger.error('prometheus.enable is not present in config/gitlab.yml')

        false
      end
    end
  end
end