Sha256: c90779d97e404857898d56452262103d1244e2f55ffcc1849ed79bd077aaf443

Contents?: true

Size: 482 Bytes

Versions: 25

Compression:

Stored size: 482 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
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
prometheus_exporter-0.4.2 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.1 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.4.0 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.3.4 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.3.3 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.3.1 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.3.0 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.2.0 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.16 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.15 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.14 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.13 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.12 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.11 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.10 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.9 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.8 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.7 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.6 lib/prometheus_exporter/metric/counter.rb
prometheus_exporter-0.1.5 lib/prometheus_exporter/metric/counter.rb