slate 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ notification :tmux,
8
+ :display_message => true,
9
+ :timeout => 3, # in seconds
10
+ :default_message_format => '%s >> %s',
11
+ :default => 'default',
12
+ :success => 'default',
13
+ :failed => 'colour1',
14
+ # the first %s will show the title, the second the message
15
+ # Alternately you can also configure *success_message_format*,
16
+ # *pending_message_format*, *failed_message_format*
17
+ :line_separator => ' > ' # since we are single line we need a separator
data/README.md CHANGED
@@ -20,7 +20,83 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ ### Configuration
24
+
25
+ Configure the Slate client
26
+
27
+ ```ruby
28
+ Slate.configure do |config|
29
+ config.endpoint = "http://your.graphite-server.com"
30
+ end
31
+ ```
32
+
33
+ ### Ruby interface
34
+
35
+ To build a basic graph
36
+
37
+ ```ruby
38
+ graph = Slate::Graph.new
39
+ graph << Slate::Target.build("stats.web01.load")
40
+
41
+ puts graph.url
42
+ puts graph.download(:json)
43
+ ```
44
+
45
+ Adjust the timeframe of the graph
46
+
47
+ ```ruby
48
+ graph = Slate::Graph.new
49
+ graph.from = "-1w"
50
+ graph.until = "-1d"
51
+ graph << Slate::Target.build("stats.web01.load")
52
+ ```
53
+
54
+ Use functions
55
+
56
+ ```ruby
57
+ graph = Slate::Graph.new
58
+
59
+ graph << Slate::Target.build("stats.web01.load") do |target|
60
+ target.add_function :sum
61
+ target.add_function :alias, "load"
62
+ end
63
+ ```
64
+
65
+ Or more complex targets (like passing targets to other targets): [Graph Spec](https://github.com/trobrock/slate/blob/master/spec/slate/graph_spec.rb)
66
+
67
+ ### Slate text interface
68
+
69
+ Slate also provides a text interface for building targets, this can be useful if you want to enable users to create graphs.
70
+ This text interface also support being able to pass targets as arguments to functions, like you need for the `asPercentOf` function.
71
+
72
+ ```ruby
73
+ graph = Slate::Graph.new
74
+
75
+ target = <<-SLATE
76
+ "stats.web1.load" {
77
+ sum
78
+ alias "load"
79
+ }
80
+ SLATE
81
+
82
+ graph << Slate::Parser.parse(target)
83
+ ```
84
+
85
+ Full test cases for different things this syntax supports are here: [Parser Spec](https://github.com/trobrock/slate/blob/master/spec/slate/parser_spec.rb)
86
+
87
+ ### Calculations
88
+
89
+ Slate supports things call Calculations, which take in graphite data and boil them down to single numbers, this can be useful if you wanted to calculate the average load over the week for all your servers.
90
+
91
+ ```ruby
92
+ graph = Slate::Graph.new
93
+ graph << Slate::Target.build("stats.web01.load")
94
+
95
+ p Slate::Calculation::Mean.new(graph).result
96
+ # [{ "name" => "stats.web01.load", "value" => 1.5 }]
97
+ ```
98
+
99
+ All the possible calculation classes are [here](https://github.com/trobrock/slate/tree/master/lib/slate/calculation).
24
100
 
25
101
  ## Contributing
26
102
 
@@ -33,4 +109,5 @@ TODO: Write usage instructions here
33
109
  ## Contributors
34
110
 
35
111
  Trae Robrock (https://github.com/trobrock)
112
+
36
113
  Andrew Katz (https://github.com/andrewkatz)
@@ -1,5 +1,5 @@
1
1
  require "slate/version"
2
- require "slate/configuration"
2
+ require "slate/client"
3
3
  require "slate/target"
4
4
  require "slate/graph"
5
5
  require "slate/calculation"
@@ -9,11 +9,21 @@ require "slate/calculation/mean"
9
9
  require "slate/calculation/last"
10
10
 
11
11
  module Slate
12
+ # Public: Configures a new Client instance.
13
+ #
14
+ # Yields the Client instance to configure.
15
+ #
16
+ # Examples
17
+ #
18
+ # Slate.configure do |config|
19
+ # config.endpoint = "http://example.com"
20
+ # end
21
+ # # => Slate::Client
22
+ #
23
+ # Returns a configured Client instance.
12
24
  def self.configure
13
- yield Configuration.instance
14
- end
15
-
16
- def self.configuration
17
- Configuration.instance
25
+ client = Client.new
26
+ yield client
27
+ client
18
28
  end
19
29
  end
@@ -0,0 +1,6 @@
1
+ module Slate
2
+ class Client
3
+ # Public: Gets/Sets the URL endpoint of the Graphite server.
4
+ attr_accessor :endpoint
5
+ end
6
+ end
@@ -5,7 +5,22 @@ module Slate
5
5
  class Graph
6
6
  attr_accessor :from, :until
7
7
 
8
- def initialize(options={})
8
+ # Public: Creates a new graph instance.
9
+ #
10
+ # client - A configured Slate::Client instance.
11
+ # options - Options for creating the graph (default: {}):
12
+ # :from - The String to start the data in the graph (optional).
13
+ # :until - The String to end the data in the graph (optional).
14
+ #
15
+ # Examples
16
+ #
17
+ # Slate::Graph.new(client)
18
+ #
19
+ # Slate::Graph.new(client, { from: "-1d" })
20
+ #
21
+ # Slate::Graph.new(client, { until: "-1h" })
22
+ def initialize(client, options={})
23
+ @client = client
9
24
  @from = options[:from]
10
25
  @until = options[:until]
11
26
  end
@@ -14,9 +29,22 @@ module Slate
14
29
  @target = target
15
30
  end
16
31
 
32
+ # Public: Generate a URL to the image of the graph.
33
+ #
34
+ # format - The format of the graph to return, as a Symbol (default: :png).
35
+ #
36
+ # Examples
37
+ #
38
+ # url
39
+ # # => "http://example.com/render?format=png"
40
+ #
41
+ # url(:svg)
42
+ # # => "http://example.com/render?format=svg"
43
+ #
44
+ # Returns the URL String.
17
45
  def url(format=:png)
18
46
  options = url_options.push(["format", format.to_s])
19
- "#{Configuration.instance.endpoint}/render?#{params(options)}"
47
+ "#{@client.endpoint}/render?#{params(options)}"
20
48
  end
21
49
 
22
50
  def download(format=:png)
@@ -1,4 +1,5 @@
1
1
  require 'treetop'
2
+ require 'singleton'
2
3
  require 'slate/parser/extensions'
3
4
  Treetop.load File.join(File.dirname(__FILE__), 'parser', 'slate_tree')
4
5
 
@@ -1,3 +1,3 @@
1
1
  module Slate
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -26,4 +26,6 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency "rspec"
27
27
  gem.add_development_dependency "mocha"
28
28
  gem.add_development_dependency "webmock"
29
+ gem.add_development_dependency "guard-rspec"
30
+ gem.add_development_dependency "rb-fsevent", "~> 0.9"
29
31
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
2
2
 
3
3
  describe Slate::Calculation::Last do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
2
2
 
3
3
  describe Slate::Calculation::Mean do
4
4
  before do
@@ -1,8 +1,8 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
2
 
3
3
  describe Slate::Graph do
4
4
  before(:each) do
5
- Slate.configure { |c| c.endpoint = "http://graphite" }
5
+ @client = Slate.configure { |c| c.endpoint = "http://graphite" }
6
6
 
7
7
  @png_stub = "PNG Image Data"
8
8
  @raw_stub = "RAW Image Data"
@@ -18,7 +18,7 @@ describe Slate::Graph do
18
18
  end
19
19
 
20
20
  it "should have accessors for from and until" do
21
- graph = Slate::Graph.new(:from => "-1w")
21
+ graph = Slate::Graph.new(@client, :from => "-1w")
22
22
  graph.from.should == "-1w"
23
23
 
24
24
  graph.from = "-1d"
@@ -30,7 +30,7 @@ describe Slate::Graph do
30
30
 
31
31
  it "should be able to get a single target" do
32
32
  target = Slate::Target.build("app.server01.load")
33
- graph = Slate::Graph.new
33
+ graph = Slate::Graph.new(@client)
34
34
  graph << target
35
35
  query(graph.url).should include("target" => "app.server01.load", "format" => "png")
36
36
  end
@@ -39,7 +39,7 @@ describe Slate::Graph do
39
39
  target = Slate::Target.build("app.server01.load") do |t|
40
40
  t.add_function :cumulative
41
41
  end
42
- graph = Slate::Graph.new
42
+ graph = Slate::Graph.new(@client)
43
43
  graph << target
44
44
  graph.url.should include(CGI.escape("cumulative(app.server01.load)"))
45
45
 
@@ -47,21 +47,21 @@ describe Slate::Graph do
47
47
  t.add_function :cumulative
48
48
  t.add_function :alias, "load"
49
49
  end
50
- graph = Slate::Graph.new
50
+ graph = Slate::Graph.new(@client)
51
51
  graph << target
52
52
  graph.url.should include(CGI.escape("alias(cumulative(app.server01.load),\"load\""))
53
53
 
54
54
  target = Slate::Target.build("app.server01.load") do |t|
55
55
  t.add_function :summarize, "1s", "sum"
56
56
  end
57
- graph = Slate::Graph.new
57
+ graph = Slate::Graph.new(@client)
58
58
  graph << target
59
59
  graph.url.should include(CGI.escape("summarize(app.server01.load,\"1s\",\"sum\")"))
60
60
 
61
61
  target = Slate::Target.build("app.server01.load") do |t|
62
62
  t.add_function :movingAverage, 10
63
63
  end
64
- graph = Slate::Graph.new
64
+ graph = Slate::Graph.new(@client)
65
65
  graph << target
66
66
  graph.url.should include(CGI.escape("movingAverage(app.server01.load,10)"))
67
67
  end
@@ -74,7 +74,7 @@ describe Slate::Graph do
74
74
  t.add_function :asPercent, first_target
75
75
  end
76
76
 
77
- graph = Slate::Graph.new
77
+ graph = Slate::Graph.new(@client)
78
78
  graph << second_target
79
79
 
80
80
  graph.url.should include(CGI.escape("asPercent(app.server01.load,sum(app.server*.load))"))
@@ -82,15 +82,15 @@ describe Slate::Graph do
82
82
 
83
83
  it "should be able to specify start and end times" do
84
84
  target = Slate::Target.build("app.server01.load")
85
- graph = Slate::Graph.new(:from => "-1d")
85
+ graph = Slate::Graph.new(@client, :from => "-1d")
86
86
  graph << target
87
87
  graph.url.should match(/from=-1d/)
88
88
 
89
- graph = Slate::Graph.new(:until => "-1d")
89
+ graph = Slate::Graph.new(@client, :until => "-1d")
90
90
  graph << target
91
91
  graph.url.should match(/until=-1d/)
92
92
 
93
- graph = Slate::Graph.new(:from => "-1d", :until => "-6h")
93
+ graph = Slate::Graph.new(@client, :from => "-1d", :until => "-6h")
94
94
  graph << target
95
95
  graph.url.should match(/from=-1d/)
96
96
  graph.url.should match(/until=-6h/)
@@ -98,7 +98,7 @@ describe Slate::Graph do
98
98
 
99
99
  it "should provide methods for retrieving formats" do
100
100
  target = Slate::Target.build("app.server01.load")
101
- graph = Slate::Graph.new
101
+ graph = Slate::Graph.new(@client)
102
102
  graph << target
103
103
  graph.url(:png).should match(/format=png/)
104
104
  graph.url(:raw).should match(/format=raw/)
@@ -109,7 +109,7 @@ describe Slate::Graph do
109
109
 
110
110
  it "should retrieve the graph" do
111
111
  target = Slate::Target.build("app.server01.load")
112
- graph = Slate::Graph.new
112
+ graph = Slate::Graph.new(@client)
113
113
  graph << target
114
114
  graph.download(:png).should eq(@png_stub)
115
115
  graph.download(:raw).should eq(@raw_stub)
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
2
 
3
3
  describe Slate::Parser do
4
4
  before do
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Slate do
4
+ it "should be able to configure the graphite host" do
5
+ client = Slate.configure do |c|
6
+ c.endpoint = "http://graphite"
7
+ end
8
+
9
+ client.endpoint.should == "http://graphite"
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -123,6 +123,38 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rb-fsevent
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: '0.9'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '0.9'
126
158
  description: Simple api on top of the graphite render api
127
159
  email:
128
160
  - trobrock@gmail.com
@@ -133,6 +165,7 @@ files:
133
165
  - .gitignore
134
166
  - .travis.yml
135
167
  - Gemfile
168
+ - Guardfile
136
169
  - LICENSE.txt
137
170
  - README.md
138
171
  - Rakefile
@@ -140,7 +173,7 @@ files:
140
173
  - lib/slate/calculation.rb
141
174
  - lib/slate/calculation/last.rb
142
175
  - lib/slate/calculation/mean.rb
143
- - lib/slate/configuration.rb
176
+ - lib/slate/client.rb
144
177
  - lib/slate/graph.rb
145
178
  - lib/slate/parser.rb
146
179
  - lib/slate/parser/extensions.rb
@@ -148,11 +181,11 @@ files:
148
181
  - lib/slate/target.rb
149
182
  - lib/slate/version.rb
150
183
  - slate.gemspec
151
- - spec/slate/calculation/last_spec.rb
152
- - spec/slate/calculation/mean_spec.rb
153
- - spec/slate/graph_spec.rb
154
- - spec/slate/parser_spec.rb
155
- - spec/slate_spec.rb
184
+ - spec/lib/slate/calculation/last_spec.rb
185
+ - spec/lib/slate/calculation/mean_spec.rb
186
+ - spec/lib/slate/graph_spec.rb
187
+ - spec/lib/slate/parser_spec.rb
188
+ - spec/lib/slate_spec.rb
156
189
  - spec/spec_helper.rb
157
190
  homepage: https://github.com/trobrock/slate
158
191
  licenses: []
@@ -168,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
201
  version: '0'
169
202
  segments:
170
203
  - 0
171
- hash: -51540163827976113
204
+ hash: 4327532724324902652
172
205
  required_rubygems_version: !ruby/object:Gem::Requirement
173
206
  none: false
174
207
  requirements:
@@ -177,17 +210,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
210
  version: '0'
178
211
  segments:
179
212
  - 0
180
- hash: -51540163827976113
213
+ hash: 4327532724324902652
181
214
  requirements: []
182
215
  rubyforge_project:
183
- rubygems_version: 1.8.24
216
+ rubygems_version: 1.8.23
184
217
  signing_key:
185
218
  specification_version: 3
186
219
  summary: Simple wrapper on top of the graphite render api
187
220
  test_files:
188
- - spec/slate/calculation/last_spec.rb
189
- - spec/slate/calculation/mean_spec.rb
190
- - spec/slate/graph_spec.rb
191
- - spec/slate/parser_spec.rb
192
- - spec/slate_spec.rb
221
+ - spec/lib/slate/calculation/last_spec.rb
222
+ - spec/lib/slate/calculation/mean_spec.rb
223
+ - spec/lib/slate/graph_spec.rb
224
+ - spec/lib/slate/parser_spec.rb
225
+ - spec/lib/slate_spec.rb
193
226
  - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- require 'singleton'
2
-
3
- module Slate
4
- class Configuration
5
- include Singleton
6
-
7
- attr_accessor :endpoint
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe Slate do
4
- it "should be able to configure the graphite host" do
5
- Slate.configure do |c|
6
- c.endpoint = "http://graphite"
7
- end
8
-
9
- Slate.configuration.endpoint.should == "http://graphite"
10
- end
11
- end