Module: PrometheusExporter

Defined in:
lib/prometheus_exporter.rb,
lib/prometheus_exporter/client.rb,
lib/prometheus_exporter/version.rb

Defined Under Namespace

Modules: Instrumentation, Metric, Server Classes: Client, LocalClient, Middleware, OjCompat

Constant Summary collapse

DEFAULT_PORT =
9394
DEFAULT_BIND_ADDRESS =
'localhost'
DEFAULT_PREFIX =
'ruby_'
DEFAULT_LABEL =
{}
DEFAULT_TIMEOUT =
2
DEFAULT_REALM =
'Prometheus Exporter'
VERSION =
'2.0.3'
@@has_oj =
nil

Class Method Summary collapse

Class Method Details

.detect_json_serializer(preferred) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/prometheus_exporter.rb', line 36

def self.detect_json_serializer(preferred)
  if preferred.nil?
    preferred = :oj if has_oj?
  end

  preferred == :oj ? OjCompat : JSON
end

.has_oj?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/prometheus_exporter.rb', line 45

def self.has_oj?
  (
    @@has_oj ||=
     begin
       require 'oj'
       :true
     rescue LoadError
       :false
     end
  ) == :true
end

.hostnameObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/prometheus_exporter.rb', line 25

def self.hostname
  @hostname ||=
    begin
      require 'socket'
      Socket.gethostname
    rescue => e
      STDERR.puts "Unable to lookup hostname #{e}"
      "unknown-host"
    end
end