Class: Slate::Graph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options = {}) ⇒ Graph

Public: Creates a new graph instance.

client - A configured Slate::Client instance. options - Options for creating the graph (default: {}):

:from  - The String to start the data in the graph (optional).
:until - The String to end the data in the graph (optional).

Examples

Slate::Graph.new(client)

Slate::Graph.new(client, { from: "-1d" })

Slate::Graph.new(client, { until: "-1h" })


22
23
24
25
26
27
# File 'lib/slate/graph.rb', line 22

def initialize(client, options={})
  @client  = client
  @from    = options[:from]
  @until   = options[:until]
  @targets = options[:targets] || []
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



6
7
8
# File 'lib/slate/graph.rb', line 6

def from
  @from
end

#untilObject

Returns the value of attribute until.



6
7
8
# File 'lib/slate/graph.rb', line 6

def until
  @until
end

Instance Method Details

#<<(target) ⇒ Object

Public: Adds a target to a graph.

target - A Slate::Target instance.

Examples

graph = Slate::Graph.new(client)
graph << Slate::Target.build("test.metric")


37
38
39
# File 'lib/slate/graph.rb', line 37

def <<(target)
  @targets << target
end

#download(format = :png) ⇒ Object

Public: Retrieve the data from the graphite server in the requested format.

format - The format of the data to return, as a Symbol (default: :png).

Examples

download(:json)
# => '{"targets":[]}'


67
68
69
70
71
# File 'lib/slate/graph.rb', line 67

def download(format=:png)
  connection.get(url(format)).body
rescue Faraday::Error::TimeoutError
  raise Slate::Error::TimeoutError
end

#url(format = :png) ⇒ Object

Public: Generate a URL to the image of the graph.

format - The format of the graph to return, as a Symbol (default: :png).

Examples

url
# => "http://example.com/render?format=png"

url(:svg)
# => "http://example.com/render?format=svg"

Returns the URL String.



54
55
56
57
# File 'lib/slate/graph.rb', line 54

def url(format=:png)
  options = url_options.push(["format", format.to_s])
  "#{@client.endpoint}/render?#{params(options)}"
end