Class: Metrix::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/metrix/base.rb

Direct Known Subclasses

Json, Load, Nginx, Process, System

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, time = Time.now) ⇒ Base

Returns a new instance of Base.



19
20
21
22
# File 'lib/metrix/base.rb', line 19

def initialize(raw, time = Time.now)
  @raw = raw
  @time = time
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/metrix/base.rb', line 7

def attributes
  @attributes
end

#timeObject (readonly)

Returns the value of attribute time.



7
8
9
# File 'lib/metrix/base.rb', line 7

def time
  @time
end

Class Method Details

.ignoreObject



14
15
16
# File 'lib/metrix/base.rb', line 14

def ignore
  @ignore ||= []
end

.ignore_metrics(*metrics) ⇒ Object



10
11
12
# File 'lib/metrix/base.rb', line 10

def ignore_metrics(*metrics)
  @ignore = [metrics].flatten
end

Instance Method Details

#cast_int(value) ⇒ Object



42
43
44
# File 'lib/metrix/base.rb', line 42

def cast_int(value)
  value.to_i if value
end

#ignore_metric?(metric) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/metrix/base.rb', line 34

def ignore_metric?(metric)
  self.class.ignore.include?(metric)
end

#metricsObject



24
25
26
27
28
# File 'lib/metrix/base.rb', line 24

def metrics
  unfiltered_metrics.reject { |k, v| ignore_metric?(k) }.map do |k, v|
    Metric.new("#{prefix}.#{k}", v, @time, tags)
  end
end

#tagsObject



30
31
32
# File 'lib/metrix/base.rb', line 30

def tags
  {}
end

#unfiltered_metricsObject



38
39
40
# File 'lib/metrix/base.rb', line 38

def unfiltered_metrics
  extract(attributes)
end