Sha256: a23c27c6f04c86290a19faf14a8e32c48453024d7a316d4a6fd07a666c9be4a1

Contents?: true

Size: 922 Bytes

Versions: 2

Compression:

Stored size: 922 Bytes

Contents

# encoding: UTF-8

require 'json'

module Prometheus
  module Client
    module Formats
      # JSON format is a deprecated, human-readable format to expose the state
      # of a given registry.
      module JSON
        MEDIA_TYPE   = 'application/json'
        SCHEMA       = 'prometheus/telemetry'
        VERSION      = '0.0.2'
        CONTENT_TYPE = %(#{MEDIA_TYPE}; schema="#{SCHEMA}"; version=#{VERSION})

        MAPPING = { summary: :histogram }

        def self.marshal(registry)
          registry.metrics.map do |metric|
            {
              baseLabels: metric.base_labels.merge(__name__: metric.name),
              docstring:  metric.docstring,
              metric: {
                type:  MAPPING[metric.type] || metric.type,
                value: metric.values.map { |l, v| { labels: l, value: v } },
              },
            }
          end.to_json
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
custom-prometheus-client-0.4.3 lib/prometheus/client/formats/json.rb
prometheus-client-0.4.2 lib/prometheus/client/formats/json.rb