capistrano-ext 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,8 +36,9 @@ module MonitorServers
36
36
  print header * size, " "
37
37
  else
38
38
  print header
39
- padding = size - header.length - 1
40
- print " ", "-" * padding if padding > 0
39
+ padding = size - header.length
40
+ print " " if padding > 0
41
+ print "-" * (padding - 1) if padding > 1
41
42
  print " "
42
43
  end
43
44
  end
@@ -57,14 +58,14 @@ module MonitorServers
57
58
  # Monitor the load of the servers tied to the current task.
58
59
  def load(options={})
59
60
  servers = current_task.servers.sort
60
- names = servers.map { |s| s.match(/^(\w+)/)[1] }
61
+ names = servers.map { |s| s.match(/^([^.]+)/)[1] }
61
62
  time = date_column(:init)
62
63
  load_column_width = "0.00".length * 3 + 2
63
64
 
64
65
  puts "connecting..."
65
66
  connect!
66
67
 
67
- parser = Proc.new { |text| text.match(/averages: (.*)$/)[1].split(/, /) }
68
+ parser = Proc.new { |text| text.match(/average.*: (.*)$/)[1].split(/, /) }
68
69
  delay = (options[:delay] || 30).to_i
69
70
 
70
71
  running = true
@@ -225,6 +226,63 @@ module MonitorServers
225
226
  def put_asset(name, to)
226
227
  put(File.read("#{File.dirname(__FILE__)}/assets/#{name}"), to)
227
228
  end
229
+
230
+ def uptime
231
+ results = {}
232
+
233
+ puts "querying servers..."
234
+ run "uptime" do |ch, stream, out|
235
+ if stream == :err
236
+ results[ch[:host]] = { :error => "error: #{out.strip}" }
237
+ else
238
+ if out.strip =~ /(\S+)\s+up\s+(.*?),\s+(\d+) users?,\s+load averages?: (.*)/
239
+ time = $1
240
+ uptime = $2
241
+ users = $3
242
+ loads = $4
243
+
244
+ results[ch[:host]] = { :uptime => uptime.strip.gsub(/ +/, " "),
245
+ :loads => loads,
246
+ :users => users,
247
+ :time => time }
248
+ else
249
+ results[ch[:host]] = { :error => "unknown uptime format: #{out.strip}" }
250
+ end
251
+ end
252
+ end
253
+
254
+ longest_hostname = results.keys.map { |k| k.length }.max
255
+ longest_uptime = results.values.map { |v| (v[:uptime] || "").length }.max
256
+
257
+ by_role = {}
258
+ roles.each do |name, list|
259
+ by_role[name] = {}
260
+ list.each do |role|
261
+ next unless results[role.host]
262
+ by_role[name][role.host] = results.delete(role.host)
263
+ end
264
+ end
265
+
266
+ by_role[:zzz] = results unless results.empty?
267
+
268
+ add_newline = false
269
+ by_role.keys.sort_by { |k| k.to_s }.each do |role|
270
+ results = by_role[role]
271
+ next if results.empty?
272
+
273
+ puts "\n" if add_newline
274
+ add_newline = true
275
+
276
+ results.keys.sort.each do |server|
277
+ print "[%-*s] " % [longest_hostname, server]
278
+ if results[server][:error]
279
+ puts results[server][:error]
280
+ else
281
+ puts "up %*s, load %s" % [longest_uptime, results[server][:uptime], results[server][:loads]]
282
+ end
283
+ end
284
+ end
285
+ end
228
286
  end
229
287
 
230
288
  Capistrano.plugin :monitor, MonitorServers
@@ -247,4 +305,12 @@ STR
247
305
  task :watch_requests, :roles => :app do
248
306
  monitor.requests_per_second("#{shared_path}/log/#{self[:log_name] || "production.log"}")
249
307
  end
308
+
309
+ desc <<-STR
310
+ Display the current uptime and load for all servers, nicely formatted with
311
+ columns all lined up for easy scanning.
312
+ STR
313
+ task :uptime do
314
+ monitor.uptime
315
+ end
250
316
  end
@@ -2,8 +2,8 @@ module Capistrano
2
2
  module Ext
3
3
  module Version #:nodoc:
4
4
  MAJOR = 1
5
- MINOR = 0
6
- TINY = 1
5
+ MINOR = 1
6
+ TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join(".")
9
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: capistrano-ext
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2006-03-06 00:00:00 -07:00
6
+ version: 1.1.0
7
+ date: 2006-09-14 00:00:00 -06:00
8
8
  summary: Capistrano Extensions is a set of useful task libraries and methods that other developers may reference in their own recipe files.
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: jamis@37signals.com
12
12
  homepage: http://www.rubyonrails.com
13
13
  rubyforge_project:
@@ -18,37 +18,42 @@ bindir: bin
18
18
  has_rdoc: false
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
28
+ post_install_message:
29
29
  authors:
30
- - Jamis Buck
30
+ - Jamis Buck
31
31
  files:
32
- - lib/capistrano
33
- - lib/capistrano/ext
34
- - lib/capistrano/ext/assets
35
- - lib/capistrano/ext/monitor.rb
36
- - lib/capistrano/ext/version.rb
37
- - lib/capistrano/ext/assets/request-counter.rb
32
+ - lib/capistrano
33
+ - lib/capistrano/ext
34
+ - lib/capistrano/ext/assets
35
+ - lib/capistrano/ext/monitor.rb
36
+ - lib/capistrano/ext/version.rb
37
+ - lib/capistrano/ext/assets/request-counter.rb
38
38
  test_files: []
39
+
39
40
  rdoc_options: []
41
+
40
42
  extra_rdoc_files: []
43
+
41
44
  executables: []
45
+
42
46
  extensions: []
47
+
43
48
  requirements: []
49
+
44
50
  dependencies:
45
- - !ruby/object:Gem::Dependency
46
- name: capistrano
47
- version_requirement:
48
- version_requirements: !ruby/object:Gem::Version::Requirement
49
- requirements:
50
- -
51
- - ">="
52
- - !ruby/object:Gem::Version
53
- version: 1.0.0
54
- version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: capistrano
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Version::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.0.0
59
+ version: