Module: Wavefront::Mixins

Included in:
Cli::Events, Cli::Ts, Response::Graphite
Defined in:
lib/wavefront/mixins.rb

Instance Method Summary collapse

Instance Method Details

#interpolate_schema(label, host, prefix_length) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/wavefront/mixins.rb', line 19

def interpolate_schema(label, host, prefix_length)
  label_parts = label.split('.')
  interpolated = Array.new
  interpolated << label_parts.shift(prefix_length)
  interpolated << host
  interpolated << label_parts
  interpolated.flatten!
  return interpolated.join('.')
end

#parse_time(t) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/wavefront/mixins.rb', line 29

def parse_time(t)
  return Time.at(t.to_i) if t.match(/^\d+$/)
  begin
    return DateTime.parse("#{t} #{Time.now.getlocal.zone}").to_time.utc
  rescue
    raise "cannot parse timestamp '#{t}'."
  end
end

#time_to_ms(t) ⇒ Object



38
39
40
41
42
43
# File 'lib/wavefront/mixins.rb', line 38

def time_to_ms(t)
  #
  # Return the time as milliseconds since the epoch
  #
  (t.to_f * 1000).round
end