Parent

MetricsPack

A simple class for really fast serialized timing data. NOTE: We’re storing the serialized data directly to a redis sorted set so it’s important that each chunk of data in unique. Also, it’s possible to grab the stamp from the zrange using :with_scores. NOTE2: We bypass Storable’s to_csv and from_csv for speed. TODO: test speed difference.

Constants

METRICS
TALLIES

Public Class Methods

from_csv(str) click to toggle source
# File lib/stella/core_ext.rb, line 359
def self.from_csv(str)
  unpack str
end
from_json(str) click to toggle source
# File lib/stella/core_ext.rb, line 368
def self.from_json(str)
  unpack(str)
end
metric?(guess) click to toggle source
# File lib/stella/core_ext.rb, line 371
def self.metric?(guess)
  METRICS.member?(guess.to_s.to_sym)
end
new(stamp=nil, uid=nil, n=nil) click to toggle source
# File lib/stella/core_ext.rb, line 302
def initialize(stamp=nil, uid=nil, n=nil)
  @stamp, @uid, @n = stamp, uid, n
  @stamp &&= @stamp.utc.to_i if Time === @stamp      
  self.class.field_names.each do |fname|
    self.send("#{fname}=", 0) unless fname == :id || self.send(fname)
  end                                                
  @score ||= 1.0
  @errors ||= 0
end
unpack(str) click to toggle source
# File lib/stella/core_ext.rb, line 362
def self.unpack(str)
  return ArgumentError, "Cannot unpack nil" if str.nil?
  a = str.split(',')
  me = new
  me.update *a
end

Public Instance Methods

kind() click to toggle source
# File lib/stella/core_ext.rb, line 311
def kind
  :metric
end
pack() click to toggle source
# File lib/stella/core_ext.rb, line 332
def pack
  to_s
end
quantize_stamp(quantum) click to toggle source

@stamp => 1281355304 (2010-08-09-12-01-44) quantize_stamp(1.day) => 1281312000 (2010-08-09) quantize_stamp(1.hour) => 1281355200 (2010-08-09-12) quantize_stamp(1.minute) => 1281355260 (2010-08-09-12-01)

# File lib/stella/core_ext.rb, line 340
def quantize_stamp(quantum)
  @stamp - (@stamp % quantum)
end
to_a() click to toggle source
# File lib/stella/core_ext.rb, line 343
def to_a
  field_names.collect { |field| 
    v = send(field) 
    if v.nil?
      field_types[field] == String ? 'unknown' : 0.0
    else
      field_types[field] == Float ? v.fineround : v
    end
  }
end
to_csv() click to toggle source
# File lib/stella/core_ext.rb, line 356
def to_csv
  to_s
end
to_s() click to toggle source
# File lib/stella/core_ext.rb, line 353
def to_s
  to_a.join(',')
end
update(*args) click to toggle source

should be in the same order as the fields are defined (i.e. MetricsPack.field_names)

# File lib/stella/core_ext.rb, line 316
def update(*args)
  field_names.each_with_index do |field,idx| 
    val = args[idx]
    val = case field_types[field].to_s
    when 'Float' 
      val.to_f
    when 'Integer'
      val.to_i
    else
      val
    end
    send("#{field}=", val)
  end
  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.