Class: Cube::Client

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

Constant Summary collapse

RESERVED_CHARS_REGEX =

We’ll use this to eliminate any unwanted/disallowed characters from our event type later on.

/[^\w\d]/

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = "localhost", port = 1180) ⇒ Client

Set ‘er up with a host and port, defaults to `localhost:1180`.

Parameters:

  • The (String)

    hostname to send metrics to.

  • The (Integer)

    UDP port to send metrics to.



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

def initialize(host="localhost", port=1180)
  @host, @port = host, port
end

Class Attribute Details

.loggerObject

Set to any logger instance that responds to #debug and #error (like the Rails or stdlib logger) to enable metric logging.



21
22
23
# File 'lib/cube.rb', line 21

def logger
  @logger
end

Instance Attribute Details

#namespaceObject

A namespace to prepend to all Cube calls.



12
13
14
# File 'lib/cube.rb', line 12

def namespace
  @namespace
end

Instance Method Details

#send(type, *args) ⇒ Object

The primary endpoint for sending metrics to Cube.

Parameters:

  • The (String)

    desired name of the new Cube event.

  • A (Array)

    splat that takes an optional DateTime, an event id (typically an integer, but can be any object), and a Hash of data.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cube.rb', line 37

def send(type, *args)
  time = nil
  id = nil
  data = nil

  until args.empty?
    arg = args.shift

    case arg
      when DateTime, Time
        time ||= arg
      when Hash
        data ||= arg
      else
        id ||= arg
      end
  end

  # Send off our parsed arguments to be further massaged and socketized.
  actual_send type, time, id, data
end