graphite_builder 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/graphite_builder.gemspec +1 -1
- data/lib/graphite_builder.rb +1 -15
- data/test/test_graphite_builder.rb +27 -23
- metadata +10 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/graphite_builder.gemspec
CHANGED
data/lib/graphite_builder.rb
CHANGED
@@ -17,10 +17,9 @@ module Graphite
|
|
17
17
|
|
18
18
|
# args are optional arguments for constructing the url
|
19
19
|
# opts are data to retrieve
|
20
|
-
def initialize(args={},
|
20
|
+
def initialize(args={}, &block)
|
21
21
|
@args = args
|
22
22
|
@targets = []
|
23
|
-
data opts
|
24
23
|
if block
|
25
24
|
self.instance_eval(&block)
|
26
25
|
end
|
@@ -30,19 +29,6 @@ module Graphite
|
|
30
29
|
@targets << value
|
31
30
|
end
|
32
31
|
|
33
|
-
def data(opts=nil)
|
34
|
-
case opts
|
35
|
-
when Hash, Array
|
36
|
-
@data = opts
|
37
|
-
when String, Symbol, Fixnum
|
38
|
-
@data[opts]
|
39
|
-
when NilClass
|
40
|
-
@data
|
41
|
-
else
|
42
|
-
raise RuntimeError.new("Unknown options: #{opts}")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
32
|
def sumSeries(*args)
|
47
33
|
array_argument_wrapper('sumSeries', args)
|
48
34
|
end
|
@@ -9,7 +9,7 @@ describe Graphite::Builder do
|
|
9
9
|
describe 'when no targets are defined' do
|
10
10
|
it 'should raise a NoTargetsDefined error' do
|
11
11
|
Proc.new do
|
12
|
-
Graphite::Builder.new(base_url: 'http://foo.bar/render'
|
12
|
+
Graphite::Builder.new(base_url: 'http://foo.bar/render') do
|
13
13
|
width 800
|
14
14
|
end.render
|
15
15
|
end.must_raise Graphite::Builder::NoTargetsDefined
|
@@ -20,7 +20,7 @@ describe Graphite::Builder do
|
|
20
20
|
|
21
21
|
describe 'whithout using data' do
|
22
22
|
it 'should render the correct <img/> tag' do
|
23
|
-
Graphite::Builder.new(
|
23
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
24
24
|
target '1.2.3'
|
25
25
|
end.render.must_equal '<img src="http://localhost/render?target=1.2.3"/>'
|
26
26
|
end
|
@@ -28,16 +28,17 @@ describe Graphite::Builder do
|
|
28
28
|
|
29
29
|
describe 'using data' do
|
30
30
|
it 'should render the correct <img/> tag' do
|
31
|
-
|
32
|
-
|
33
|
-
target
|
31
|
+
foo = :bar
|
32
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
33
|
+
target foo
|
34
|
+
target "#{foo}.stuff"
|
34
35
|
end.render.must_equal '<img src="http://localhost/render?target=bar&target=bar.stuff"/>'
|
35
36
|
end
|
36
37
|
|
37
38
|
describe 'setting params' do
|
38
39
|
|
39
40
|
it 'should render the correct <img/> tag' do
|
40
|
-
Graphite::Builder.new(
|
41
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
41
42
|
width 800
|
42
43
|
height 200
|
43
44
|
target 'a.b.c'
|
@@ -47,18 +48,20 @@ describe Graphite::Builder do
|
|
47
48
|
|
48
49
|
describe 'and applying a "function"' do
|
49
50
|
it 'should render the correct <img/> tag' do
|
50
|
-
|
51
|
-
|
52
|
-
target
|
51
|
+
foo = :bar
|
52
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
53
|
+
target foo
|
54
|
+
target color("#{foo}.stuff", 'red')
|
53
55
|
end.render.must_equal "<img src=\"http://localhost/render?target=bar&target=color(bar.stuff,'red')\"/>"
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
59
|
describe 'and nesting functions' do
|
58
60
|
it 'should render the correct <img/> tag' do
|
59
|
-
|
60
|
-
|
61
|
-
target
|
61
|
+
foo = :bar
|
62
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
63
|
+
target foo
|
64
|
+
target legend(color("#{foo}.stuff", 'red'), 'foozle')
|
62
65
|
end.render.must_equal "<img src=\"http://localhost/render?target=bar&target=alias(color(bar.stuff,'red'),'foozle')\"/>"
|
63
66
|
end
|
64
67
|
end
|
@@ -73,7 +76,7 @@ describe Graphite::Builder do
|
|
73
76
|
|
74
77
|
describe 'with a single data point' do
|
75
78
|
it 'should render the correct <img/> tag' do
|
76
|
-
Graphite::Builder.new(
|
79
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
77
80
|
target sumSeries('a.b.*')
|
78
81
|
end.render.must_equal "<img src=\"http://localhost/render?target=sumSeries(a.b.*)\"/>"
|
79
82
|
end
|
@@ -81,7 +84,7 @@ describe Graphite::Builder do
|
|
81
84
|
|
82
85
|
describe 'with multiple data points' do
|
83
86
|
it 'should render the correct <img/> tag' do
|
84
|
-
Graphite::Builder.new(
|
87
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
85
88
|
target sumSeries('a.b.*','a.c.*','a.d.*')
|
86
89
|
end.render.must_equal "<img src=\"http://localhost/render?target=sumSeries(a.b.*,a.c.*,a.d.*)\"/>"
|
87
90
|
end
|
@@ -93,7 +96,7 @@ describe Graphite::Builder do
|
|
93
96
|
describe 'with a single argument' do
|
94
97
|
it 'should raise an ArgumentError' do
|
95
98
|
Proc.new do
|
96
|
-
Graphite::Builder.new(
|
99
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
97
100
|
target asPercent(1)
|
98
101
|
end.render
|
99
102
|
end.must_raise ArgumentError
|
@@ -102,7 +105,7 @@ describe Graphite::Builder do
|
|
102
105
|
|
103
106
|
describe 'with two arguments' do
|
104
107
|
it 'should render the correct <img/> tag' do
|
105
|
-
Graphite::Builder.new(
|
108
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
106
109
|
target asPercent('a.b.c','a.c.b')
|
107
110
|
end.render.must_equal "<img src=\"http://localhost/render?target=asPercent(a.b.c,a.c.b)\"/>"
|
108
111
|
end
|
@@ -113,7 +116,7 @@ describe Graphite::Builder do
|
|
113
116
|
|
114
117
|
describe 'with a single argument' do
|
115
118
|
it 'should render the correct <img/> tag' do
|
116
|
-
Graphite::Builder.new(
|
119
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
117
120
|
target secondYAxis('a.b.c')
|
118
121
|
end.render.must_equal "<img src=\"http://localhost/render?target=secondYAxis(a.b.c)\"/>"
|
119
122
|
end
|
@@ -125,7 +128,7 @@ describe Graphite::Builder do
|
|
125
128
|
|
126
129
|
describe 'with a single argument' do
|
127
130
|
it 'should render the correct <img/> tag' do
|
128
|
-
Graphite::Builder.new(
|
131
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
129
132
|
target stacked('a.b.c')
|
130
133
|
end.render.must_equal "<img src=\"http://localhost/render?target=stacked(a.b.c)\"/>"
|
131
134
|
end
|
@@ -137,7 +140,7 @@ describe Graphite::Builder do
|
|
137
140
|
|
138
141
|
describe 'with a single argument' do
|
139
142
|
it 'should render the correct <img/> tag' do
|
140
|
-
Graphite::Builder.new(
|
143
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
141
144
|
target legend('a.b.c','A B C')
|
142
145
|
end.render.must_equal "<img src=\"http://localhost/render?target=alias(a.b.c,'A+B+C')\"/>"
|
143
146
|
end
|
@@ -149,7 +152,7 @@ describe Graphite::Builder do
|
|
149
152
|
|
150
153
|
it 'should raise an UnknownFunctionSignature exception' do
|
151
154
|
Proc.new do
|
152
|
-
Graphite::Builder.new(
|
155
|
+
Graphite::Builder.new(base_url: 'http://localhost/render') do
|
153
156
|
target blargen(1,2,3)
|
154
157
|
end.render
|
155
158
|
end.must_raise Graphite::Builder::UnknownFunctionSignature
|
@@ -162,14 +165,15 @@ describe Graphite::Builder do
|
|
162
165
|
describe "some complex graphs" do
|
163
166
|
|
164
167
|
it "should render the correct <img/> tag" do
|
165
|
-
|
168
|
+
hostname = :foo
|
169
|
+
Graphite::Builder.new do
|
166
170
|
base_url 'http://my_graphite.host/render/'
|
167
171
|
width 800
|
168
172
|
height 200
|
169
173
|
areaMode :stacked
|
170
174
|
from '-2hours'
|
171
|
-
target(legend(color(sumSeries("#{
|
172
|
-
target(legend(color(sumSeries("#{
|
175
|
+
target(legend(color(sumSeries("#{hostname}.cpu-*.cpu-steal.value"), :red), 'Steal'))
|
176
|
+
target(legend(color(sumSeries("#{hostname}.cpu-*.cpu-steal.value"), :green), 'Idle'))
|
173
177
|
end.render.must_equal "<img src=\"http://my_graphite.host/render/?width=800&height=200&areaMode=stacked&from=-2hours&target=alias(color(sumSeries(foo.cpu-*.cpu-steal.value),'red'),'Steal')&target=alias(color(sumSeries(foo.cpu-*.cpu-steal.value),'green'),'Idle')\"/>"
|
174
178
|
end
|
175
179
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphite_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-10-11 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70327317279080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70327317279080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70327317277340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70327317277340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70327317275200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70327317275200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70327317271980 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70327317271980
|
58
58
|
description: A DSL for generating graphite graph urls. Meant to enable copy-and-paste
|
59
59
|
from the graphite UI + simple substitution.
|
60
60
|
email: edward@heroku.com
|
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash:
|
93
|
+
hash: -883896666523440853
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|