Sha256: 11f1b20f066de354df0972d239f97b0b3338aff7af86022e841a95c1d253f2b0

Contents?: true

Size: 779 Bytes

Versions: 7

Compression:

Stored size: 779 Bytes

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

  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

7 entries across 7 versions & 1 rubygems

Version Path
prometheus_exporter-0.4.17 lib/prometheus_exporter.rb
prometheus_exporter-0.4.16 lib/prometheus_exporter.rb
prometheus_exporter-0.4.15 lib/prometheus_exporter.rb
prometheus_exporter-0.4.14 lib/prometheus_exporter.rb
prometheus_exporter-0.4.13 lib/prometheus_exporter.rb
prometheus_exporter-0.4.12 lib/prometheus_exporter.rb
prometheus_exporter-0.4.11 lib/prometheus_exporter.rb