Class: UnicornMetrics::Counter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/unicorn_metrics/counter.rb

Overview

UnicornMetrics::Counter is an atomic counter that conveniently wraps the Raindrops::Struct

Direct Known Subclasses

RequestCounter, ResponseCounter

Defined Under Namespace

Classes: Stats

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Counter

Returns a new instance of Counter.

Parameters:

  • name (String)

    user-defined name



18
19
20
21
# File 'lib/unicorn_metrics/counter.rb', line 18

def initialize(name)
  @name  = name
  @stats = Stats.new
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/unicorn_metrics/counter.rb', line 6

def name
  @name
end

Instance Method Details

#as_jsonHash

Returns JSON representation of the object.

Returns:

  • (Hash)

    JSON representation of the object



33
34
35
36
37
38
39
40
# File 'lib/unicorn_metrics/counter.rb', line 33

def as_json(*)
  {
    name => {
      "type"  => type,
      "value" => value
    }
  }
end

#resetObject

Reset the counter



24
25
26
# File 'lib/unicorn_metrics/counter.rb', line 24

def reset
  @stats.value = 0
end

#typeObject



28
29
30
# File 'lib/unicorn_metrics/counter.rb', line 28

def type
  "counter"
end