Sha256: dbd89ca2139fcd7c060f5e364e33b13be9bbf178e15dba6abd870058a8f2b33e

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

# encoding: UTF-8

require 'prometheus/client/metric'

module Prometheus
  module Client
    # A Gauge is a metric that exposes merely an instantaneous value or some
    # snapshot thereof.
    class Gauge < Metric
      def type
        :gauge
      end

      # Sets the value for the given label set
      def set(value, labels: {})
        unless value.is_a?(Numeric)
          raise ArgumentError, 'value must be a number'
        end

        @store.set(labels: label_set_for(labels), val: value)
      end

      # Increments Gauge value by 1 or adds the given value to the Gauge.
      # (The value can be negative, resulting in a decrease of the Gauge.)
      def increment(by: 1, labels: {})
        label_set = label_set_for(labels)
        @store.increment(labels: label_set, by: by)
      end

      # Decrements Gauge value by 1 or subtracts the given value from the Gauge.
      # (The value can be negative, resulting in a increase of the Gauge.)
      def decrement(by: 1, labels: {})
        label_set = label_set_for(labels)
        @store.increment(labels: label_set, by: -by)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
prometheus-client-4.1.0 lib/prometheus/client/gauge.rb
prometheus-client-4.0.0 lib/prometheus/client/gauge.rb
prometheus-client-3.0.0 lib/prometheus/client/gauge.rb
prometheus-client-2.1.0 lib/prometheus/client/gauge.rb
prometheus-client-2.0.0 lib/prometheus/client/gauge.rb
prometheus-client-1.0.0 lib/prometheus/client/gauge.rb
prometheus-client-0.11.0.pre.alpha.1 lib/prometheus/client/gauge.rb
prometheus-client-0.10.0 lib/prometheus/client/gauge.rb
prometheus-client-0.10.0.pre.alpha.2 lib/prometheus/client/gauge.rb
prometheus-client-0.10.0.pre.alpha.1 lib/prometheus/client/gauge.rb