Sha256: e405483810c97b827d7b4133e98d6d1a0bc2af48e32c741a5ec34ad8de7bfc44

Contents?: true

Size: 726 Bytes

Versions: 4

Compression:

Stored size: 726 Bytes

Contents

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_PREFIX = 'ruby_'

  class OjCompat
    def self.parse(obj)
      Oj.compat_load(obj)
    end
    def self.dump(obj)
      Oj.dump(obj, mode: :compat)
    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

4 entries across 4 versions & 1 rubygems

Version Path
prometheus_exporter-0.3.0 lib/prometheus_exporter.rb
prometheus_exporter-0.2.0 lib/prometheus_exporter.rb
prometheus_exporter-0.1.16 lib/prometheus_exporter.rb
prometheus_exporter-0.1.15 lib/prometheus_exporter.rb