Sha256: 5dc30b9334bb29f8680f22b669d58db3bd7cce91230d41432908a1697dd14cc9

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require_relative "prometheus_exporter/version"
require "json"
require "thread"

module PrometheusExporter
  # per: https://github.com/prometheus/prometheus/wiki/Default-port-allocations
  DEFAULT_PORT = 9394
  DEFAULT_BIND_ADDRESS = 'localhost'
  DEFAULT_PREFIX = 'ruby_'
  DEFAULT_LABEL = {}
  DEFAULT_TIMEOUT = 2
  DEFAULT_REALM = 'Prometheus Exporter'

  class OjCompat
    def self.parse(obj)
      Oj.compat_load(obj)
    end
    def self.dump(obj)
      Oj.dump(obj, mode: :compat)
    end
  end

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

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

    preferred == :oj ? OjCompat : JSON
  end

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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
prometheus_exporter-2.0.8 lib/prometheus_exporter.rb
prometheus_exporter-2.0.7 lib/prometheus_exporter.rb
prometheus_exporter-2.0.6 lib/prometheus_exporter.rb
prometheus_exporter-2.0.5 lib/prometheus_exporter.rb
prometheus_exporter-2.0.4 lib/prometheus_exporter.rb
prometheus_exporter-2.0.3 lib/prometheus_exporter.rb
prometheus_exporter-2.0.2 lib/prometheus_exporter.rb
prometheus_exporter-2.0.1 lib/prometheus_exporter.rb
prometheus_exporter-2.0.0 lib/prometheus_exporter.rb
prometheus_exporter-1.0.1 lib/prometheus_exporter.rb
prometheus_exporter-1.0.0 lib/prometheus_exporter.rb
prometheus_exporter-0.8.1 lib/prometheus_exporter.rb
prometheus_exporter-0.8.0 lib/prometheus_exporter.rb
prometheus_exporter-0.7.0 lib/prometheus_exporter.rb
prometheus_exporter-0.6.0 lib/prometheus_exporter.rb