pencil 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/p +5 -0
- data/lib/pencil.rb +4 -0
- data/lib/pencil/config.rb +5 -1
- data/lib/pencil/helpers.rb +6 -2
- data/lib/pencil/models/dashboard.rb +7 -7
- data/lib/pencil/models/graph.rb +25 -25
- data/lib/pencil/models/host.rb +1 -0
- data/lib/pencil/version.rb +1 -1
- data/lib/pencil/views/partials/input_boxes.erb +1 -1
- metadata +6 -5
data/lib/p
ADDED
data/lib/pencil.rb
CHANGED
@@ -40,10 +40,14 @@ module Pencil
|
|
40
40
|
# time stuff
|
41
41
|
start = param_lookup("start")
|
42
42
|
duration = param_lookup("duration")
|
43
|
+
|
43
44
|
@stime = Chronic.parse(start)
|
44
45
|
if @stime
|
45
46
|
@stime -= @stime.sec unless @params["noq"]
|
47
|
+
elsif start =~ /^\d+$/ #epoch
|
48
|
+
@stime = Time.at start.to_i
|
46
49
|
end
|
50
|
+
|
47
51
|
if duration
|
48
52
|
@duration = ChronicDuration.parse(duration) || 0
|
49
53
|
else
|
data/lib/pencil/config.rb
CHANGED
@@ -15,11 +15,13 @@ module Pencil
|
|
15
15
|
port = 9292
|
16
16
|
@rawconfig = {}
|
17
17
|
@confdir = "."
|
18
|
+
@recursive = false
|
18
19
|
|
19
20
|
optparse = OptionParser.new do |o|
|
20
21
|
o.on("-d", "--config-dir DIR",
|
21
22
|
"location of the config directory (default .)") do |arg|
|
22
23
|
@confdir = arg
|
24
|
+
@recursive = true
|
23
25
|
end
|
24
26
|
o.on("-p", "--port PORT", "port to bind to (default 9292)") do |arg|
|
25
27
|
port = arg.to_i
|
@@ -32,7 +34,9 @@ module Pencil
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def reload!
|
35
|
-
|
37
|
+
# only do a recursive search if "-d" is specified
|
38
|
+
configs = Dir.glob("#{@confdir}/#{@recursive ? '**/' : ''}*.y{a,}ml")
|
39
|
+
|
36
40
|
configs.each do |c|
|
37
41
|
yml = YAML.load(File.read(c))
|
38
42
|
next unless yml
|
data/lib/pencil/helpers.rb
CHANGED
@@ -199,12 +199,16 @@ module Pencil
|
|
199
199
|
|
200
200
|
end
|
201
201
|
|
202
|
+
def valid_time (s)
|
203
|
+
Chronic.parse(s) || s =~ /^\d+$/
|
204
|
+
end
|
205
|
+
|
202
206
|
def permalink
|
203
207
|
return "" unless @stime && @duration
|
204
208
|
format = "%F %T" # chronic REALLY understands this
|
205
209
|
url = request.path + "?"
|
206
|
-
url << "&start=#{@stime.strftime(format)}"
|
207
|
-
url << "&duration=#{ChronicDuration.output(@duration)}"
|
210
|
+
url << "&start=#{@stime.strftime(format)}"
|
211
|
+
url << "&duration=#{ChronicDuration.output(@duration)}"
|
208
212
|
"<a id=\"permalink\" href=\"#{url}\">permalink</a>"
|
209
213
|
end
|
210
214
|
end
|
@@ -14,13 +14,14 @@ module Pencil
|
|
14
14
|
|
15
15
|
@graphs = []
|
16
16
|
@graph_opts = {}
|
17
|
-
params["graphs"].each do |
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
params["graphs"].each do |n|
|
18
|
+
if n.respond_to?(:keys)
|
19
|
+
key = n.keys.first # should only be one key
|
20
|
+
val = n.values.first
|
21
|
+
g = Graph.find(key)
|
22
|
+
@graph_opts[g] = val||{}
|
22
23
|
else
|
23
|
-
raise "Bad format for graph (must be a hash-y; #{
|
24
|
+
raise "Bad format for graph (must be a hash-y; #{n.class}:#{n.inspect} is not)"
|
24
25
|
end
|
25
26
|
|
26
27
|
@graphs << g if g
|
@@ -101,7 +102,6 @@ module Pencil
|
|
101
102
|
hosts = get_host_wildcards(graph)
|
102
103
|
_, clusters = get_valid_hosts(graph)
|
103
104
|
|
104
|
-
next_url = ""
|
105
105
|
type = opts[:zoom] ? :cluster : :global
|
106
106
|
options = opts.merge({:sum => type})
|
107
107
|
graph_url = graph.render_url(hosts, clusters, options)
|
data/lib/pencil/models/graph.rb
CHANGED
@@ -146,8 +146,8 @@ module Pencil
|
|
146
146
|
colors = []
|
147
147
|
#FIXME code duplication
|
148
148
|
if opts[:sum] == :global
|
149
|
-
@params["targets"].each do |stat_name,
|
150
|
-
z = new_map(
|
149
|
+
@params["targets"].each do |stat_name, o|
|
150
|
+
z = new_map(o)
|
151
151
|
|
152
152
|
z[:key] ||= stat_name
|
153
153
|
#######################
|
@@ -175,25 +175,25 @@ module Pencil
|
|
175
175
|
# target << handle_metric(translate(:sumSeries, metric), z)
|
176
176
|
|
177
177
|
if z.keys.member?('divideSeries') # special case
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
178
|
+
# apply divideSeries, sumSeries then other options
|
179
|
+
res = translate(:divideSeries, metric)
|
180
|
+
res = translate(:sumSeries, res)
|
181
|
+
z.delete(:divideSeries)
|
182
|
+
h = YAML::Omap.new
|
183
|
+
z.each { |k,v| h[k] = v unless k == 'divideSeries' }
|
184
|
+
target << handle_metric(res, h)
|
185
|
+
else
|
186
|
+
target << handle_metric(translate(:sumSeries, metric), z)
|
187
|
+
end
|
188
188
|
if !@params[:use_color] ||
|
189
|
-
|
189
|
+
(!z[:color] && @params[:use_color])
|
190
190
|
colors << next_color(colors, z[:color])
|
191
191
|
end
|
192
192
|
end # @params["targets"].each
|
193
193
|
elsif opts[:sum] == :cluster # one line per cluster/metric
|
194
194
|
clusters.each do |cluster|
|
195
|
-
@params["targets"].each do |stat_name,
|
196
|
-
z = new_map(
|
195
|
+
@params["targets"].each do |stat_name, o|
|
196
|
+
z = new_map(o)
|
197
197
|
|
198
198
|
metrics = []
|
199
199
|
#######################
|
@@ -207,14 +207,14 @@ module Pencil
|
|
207
207
|
# divideSeries is picky about the number of series given as
|
208
208
|
# arguments, so sum them in this case
|
209
209
|
handle_metric(translate(:sumSeries, mm),
|
210
|
-
|
210
|
+
m[m.keys.first], true)
|
211
211
|
else
|
212
212
|
handle_metric(mm, m[m.keys.first], true)
|
213
213
|
end
|
214
214
|
end.join(",")
|
215
215
|
else
|
216
216
|
metrics << handle_metric(compose_metric(stat_name,
|
217
|
-
|
217
|
+
cluster, h), {}, true)
|
218
218
|
end
|
219
219
|
#######################
|
220
220
|
z[:key] = "#{cluster} #{z[:key]}"
|
@@ -229,7 +229,7 @@ module Pencil
|
|
229
229
|
target << handle_metric(res, h)
|
230
230
|
else
|
231
231
|
target << handle_metric(translate(:sumSeries,
|
232
|
-
|
232
|
+
metrics.join(',')), z)
|
233
233
|
end
|
234
234
|
|
235
235
|
if !@params[:use_color] || (!z[:color] && @params[:use_color])
|
@@ -238,8 +238,8 @@ module Pencil
|
|
238
238
|
end # metrics.each
|
239
239
|
end # clusters.each
|
240
240
|
else # one line per {metric,host,colo}
|
241
|
-
@params["targets"].each do |stat_name,
|
242
|
-
z = new_map(
|
241
|
+
@params["targets"].each do |stat_name, o|
|
242
|
+
z = new_map(o)
|
243
243
|
clusters.each do |cluster|
|
244
244
|
hosts.each do |host|
|
245
245
|
label = "#{host} #{z[:key]}"
|
@@ -287,11 +287,11 @@ module Pencil
|
|
287
287
|
url = URI.join(@params[:graphite_url], "/render/?").to_s
|
288
288
|
url_parts = []
|
289
289
|
url_opts.each do |k, v|
|
290
|
-
[v].flatten.each do |
|
291
|
-
url_parts << "#{URI.escape(k.to_s)}=#{URI.escape(
|
290
|
+
[v].flatten.each do |v2|
|
291
|
+
url_parts << "#{URI.escape(k.to_s)}=#{URI.escape(v2.to_s)}"
|
292
292
|
end
|
293
293
|
end
|
294
|
-
url += url_parts.join("&")
|
294
|
+
url += url_parts.join("&")
|
295
295
|
return url
|
296
296
|
end
|
297
297
|
|
@@ -339,8 +339,8 @@ module Pencil
|
|
339
339
|
end
|
340
340
|
unless ci && hi
|
341
341
|
last.reverse.each_with_index do |v, i|
|
342
|
-
ci = -1 -i if v.match("%c")
|
343
|
-
hi = -1 -i if v.match("%h")
|
342
|
+
ci = (-1) -i if v.match("%c")
|
343
|
+
hi = (-1) -i if v.match("%h")
|
344
344
|
end
|
345
345
|
end
|
346
346
|
hosts = metrics.map do |m|
|
data/lib/pencil/models/host.rb
CHANGED
data/lib/pencil/version.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
<input <%= "value=\"#{val}\" " if val %> size="<%= name =~ /start|duration/ ? 10 : 4 %>" name="<%= name %>" id="<%= name %>" type="text"/>
|
9
9
|
<% if name == "start" %>
|
10
10
|
<a href="http://chronic.rubyforge.org/" class="inline-link" target="_blank">
|
11
|
-
<% if
|
11
|
+
<% if valid_time(param_lookup(name)) %>
|
12
12
|
?
|
13
13
|
<% else %>
|
14
14
|
<div class="error">Bad timespec!</div>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pencil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pete Fritchman
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-06-01 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: map
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/pencil/models.rb
|
166
166
|
- lib/pencil/helpers.rb
|
167
167
|
- lib/pencil/rubyfixes.rb
|
168
|
+
- lib/p
|
168
169
|
- docs/pencil_options.md
|
169
170
|
- examples/graphs.yml
|
170
171
|
- examples/pencil.yml
|
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
200
|
requirements: []
|
200
201
|
|
201
202
|
rubyforge_project:
|
202
|
-
rubygems_version: 1.8.
|
203
|
+
rubygems_version: 1.8.24
|
203
204
|
signing_key:
|
204
205
|
specification_version: 3
|
205
206
|
summary: pencil -- Graphite dashboard system
|