Sha256: 41f9b15a68f71f93de2c8d3dcd434340cef74de8f40eb500b7613345e025a6ad

Contents?: true

Size: 822 Bytes

Versions: 1

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

module PrometheusExporter::Metric
  class Gauge < Base
    attr_reader :data

    def initialize(name, help)
      super
      @data = {}
    end

    def type
      "gauge"
    end

    def metric_text
      @data.map do |labels, value|
        "#{prefix(@name)}#{labels_text(labels)} #{value}"
      end.join("\n")
    end

    def observe(value, labels = {})
      if value.nil?
        data.delete(labels)
      else
        if !(Numeric === value)
          raise ArgumentError, 'value must be a number'
        end
        @data[labels] = value
      end
    end

    def increment(labels = {}, value = 1)
      @data[labels] ||= 0
      @data[labels] += value
    end

    def decrement(labels = {}, value = 1)
      @data[labels] ||= 0
      @data[labels] -= value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prometheus_exporter-0.4.2 lib/prometheus_exporter/metric/gauge.rb