Sha256: e81bcdf8c71f3470e0e924f9d351779b60a1994f11ff678c6311fbb5da86a591

Contents?: true

Size: 769 Bytes

Versions: 10

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

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

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

    def type
      "counter"
    end

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

    def observe(increment = 1, labels = {})
      @data[labels] ||= 0
      @data[labels] += increment
    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

    def reset(labels = {}, value = 0)
      @data[labels] = value
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
prometheus_exporter-0.4.15 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.14 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.13 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.12 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.11 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.10 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.9 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.8 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.7 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.6 lib/prometheus_exporter/metric/counter.rb