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_TIMEOUT =
2
VERSION =
'0.5.0'
@@has_oj =
nil

Class Method Summary collapse

Class Method Details

.detect_json_serializer(preferred) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/prometheus_exporter.rb', line 34

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)


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

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

.hostnameObject



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

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