Class: Tracekit::Metrics::Gauge

Inherits:
Object
  • Object
show all
Defined in:
lib/tracekit/metrics/gauge.rb

Overview

Gauge metric - point-in-time value that can increase or decrease Used for tracking current values like active connections, memory usage, etc.

Instance Method Summary collapse

Constructor Details

#initialize(name, tags, registry) ⇒ Gauge

Returns a new instance of Gauge.



8
9
10
11
12
13
14
# File 'lib/tracekit/metrics/gauge.rb', line 8

def initialize(name, tags, registry)
  @name = name
  @tags = tags || {}
  @registry = registry
  @value = 0.0
  @mutex = Mutex.new
end

Instance Method Details

#decObject

Decrements the gauge by 1



34
35
36
37
38
39
# File 'lib/tracekit/metrics/gauge.rb', line 34

def dec
  @mutex.synchronize do
    @value -= 1
    @registry.record_metric(@name, "gauge", @value, @tags)
  end
end

#incObject

Increments the gauge by 1



26
27
28
29
30
31
# File 'lib/tracekit/metrics/gauge.rb', line 26

def inc
  @mutex.synchronize do
    @value += 1
    @registry.record_metric(@name, "gauge", @value, @tags)
  end
end

#set(value) ⇒ Object

Sets the gauge to a specific value

Parameters:

  • value (Numeric)

    Value to set



18
19
20
21
22
23
# File 'lib/tracekit/metrics/gauge.rb', line 18

def set(value)
  @mutex.synchronize do
    @value = value
    @registry.record_metric(@name, "gauge", @value, @tags)
  end
end