Module: Wavefront::Mixins

Included in:
Cli::BatchWrite, Cli::Events, Cli::Ts, Cli::Write, 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
37
38
39
40
41
42
# File 'lib/wavefront/mixins.rb', line 29

def parse_time(t)
  #
  # Return a time as an integer, however it might come in.
  #
  begin
    return t if t.is_a?(Integer)
    return t.to_i if t.is_a?(Time)
    return t.to_i if t.is_a?(String) && t.match(/^\d+$/)
    return DateTime.parse("#{t} #{Time.now.getlocal.zone}").
      to_time.utc.to_i
  rescue
    raise "cannot parse timestamp '#{t}'."
  end
end

#time_to_ms(t) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/wavefront/mixins.rb', line 44

def time_to_ms(t)
  #
  # Return the time as milliseconds since the epoch
  #
  return false unless t.is_a?(Integer)
  (t.to_f * 1000).round
end