Class: Slate::Graph
- Inherits:
-
Object
- Object
- Slate::Graph
- Defined in:
- lib/slate/graph.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#until ⇒ Object
Returns the value of attribute until.
Instance Method Summary collapse
-
#<<(target) ⇒ Object
Public: Adds a target to a graph.
-
#download(format = :png) ⇒ Object
Public: Retrieve the data from the graphite server in the requested format.
-
#initialize(client, options = {}) ⇒ Graph
constructor
Public: Creates a new graph instance.
-
#url(format = :png) ⇒ Object
Public: Generate a URL to the image of the graph.
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, ={}) @client = client @from = [:from] @until = [:until] @targets = [:targets] || [] end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/slate/graph.rb', line 6 def from @from end |
#until ⇒ Object
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
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) = .push(["format", format.to_s]) "#{@client.endpoint}/render?#{params()}" end |