servicesnapshot 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -7
- data/bin/servicesnapshot +3 -0
- data/lib/Snapshot/Beanstalk.rb +26 -19
- data/lib/Snapshot/Ssh.rb +7 -8
- data/lib/helper_functions.rb +24 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
#
|
1
|
+
#ServiceSnapshot
|
2
2
|
|
3
|
-
The fastest way to
|
3
|
+
The fastest way to get a snapshot of what your system is doing
|
4
4
|
|
5
5
|
##Principles
|
6
|
-
|
7
|
-
#The DSL should be clean to read, at the expense of a steeper learning curve
|
6
|
+
#The DSL should be clean to read, at the expense of a steeper learning curve
|
8
7
|
#Tell users what is wrong as precisley as possible, with possible remedy's
|
9
8
|
|
10
9
|
##Get it
|
11
|
-
#gem install
|
10
|
+
#gem install servicesnapshot
|
12
11
|
|
13
12
|
##Run it
|
14
13
|
#Have a look at the dsl's in the Example directory
|
15
|
-
#
|
14
|
+
#servicesnapshot <path to dsl>
|
16
15
|
|
17
16
|
##Notes
|
18
|
-
#Plays well with upstart and foreman
|
data/bin/servicesnapshot
CHANGED
@@ -25,6 +25,9 @@ begin
|
|
25
25
|
puts "*** Your dsl is not formatted correctly"
|
26
26
|
puts "*** Ensure each line has the format,"
|
27
27
|
puts "*** <command>, [:arg=>value]"
|
28
|
+
rescue ParameterMissingError=>e
|
29
|
+
puts e.message
|
30
|
+
|
28
31
|
rescue SystemExit=>e
|
29
32
|
# rescue SIGTERM=>e
|
30
33
|
rescue Exception=>e
|
data/lib/Snapshot/Beanstalk.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
require "beanstalk-client"
|
2
2
|
|
3
3
|
def beanstalk_queue( params )
|
4
|
-
|
5
|
-
abort( "*** Incorrect parameters passed for, beanstalk\n*** Usage, ssh :user=><username>, :host=><hostname>, :queue=><queue|[queue1,queue2,...]>" ) if params.class.name != "Hash" || params.keys.length != 3
|
6
|
-
abort( "*** User parameter missing for, beanstalk, command\n*** Add, :user=><username>" ) if params[:user].nil?
|
7
|
-
abort( "*** Host parameter missing for, beanstalk, command\n*** Add, :host=><host>" ) if params[:host].nil?
|
8
|
-
abort( "*** Queue parameter missing for, beanstalk, command\n*** Add, :queue=><queue>" ) if params[:queue].nil?
|
9
4
|
|
10
|
-
|
11
|
-
|
5
|
+
usage = "beanstalk_queue :user=><username>, :host=><hostname>, :queue=><queue|[queue1,queue2,...]>"
|
6
|
+
user = get_param( params, :user, usage )
|
7
|
+
host = get_param( params, :host, usage )
|
8
|
+
queue = get_param( params, :queue, usage )
|
9
|
+
|
10
|
+
|
11
|
+
localPort, gateway = open_gateway( user, host )
|
12
|
+
|
12
13
|
destinationUrl = "127.0.0.1:#{localPort}"
|
13
|
-
log "Opened SSH Gateway to, #{
|
14
|
+
log "Opened SSH Gateway to, #{host}, on, #{destinationUrl}", true
|
14
15
|
list = Array.new
|
15
16
|
log "Connect to remote beanstalk", true
|
16
17
|
beanstalk = Beanstalk::Pool.new([destinationUrl])
|
17
|
-
beanstalk.watch(
|
18
|
-
tubeStats = beanstalk.stats_tube(
|
18
|
+
beanstalk.watch( queue )
|
19
|
+
tubeStats = beanstalk.stats_tube( queue )
|
19
20
|
index = tubeStats["current-jobs-ready"].to_i
|
20
21
|
log "Current number of msgs in tube, #{index}", true
|
21
22
|
jobList = Array.new
|
@@ -30,31 +31,37 @@ def beanstalk_queue( params )
|
|
30
31
|
job.release
|
31
32
|
end
|
32
33
|
|
33
|
-
title = "# beanstalk_queue: #{
|
34
|
+
title = "# beanstalk_queue: #{user}@#{host} #{queue}"
|
34
35
|
formatOutput( title, "\n==> MSG <==\n\n" + list.join( "\n==> MSG <==\n\n" ) + "\n\n" )
|
35
36
|
end
|
36
37
|
|
37
38
|
|
38
39
|
def beanstalk( params )
|
40
|
+
usage = "beanstalk :user=><username>, :host=><hostname>, :queues=><queue|[queue1,queue2,...]>"
|
41
|
+
user = get_param( params, :user, usage )
|
42
|
+
host = get_param( params, :host, usage )
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
queues = nil
|
45
|
+
begin
|
46
|
+
queues = get_param( params, :queues, usage )
|
47
|
+
rescue ParameterMissingError=>e
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
localPort, gateway = open_gateway( user, host )
|
45
52
|
|
46
53
|
destinationUrl = "127.0.0.1:#{localPort}"
|
47
|
-
log "Opened SSH Gateway to, #{
|
54
|
+
log "Opened SSH Gateway to, #{host}, on, #{destinationUrl}", true
|
48
55
|
list = Array.new
|
49
56
|
log "Connect to remote beanstalk", true
|
50
57
|
beanstalk = Beanstalk::Pool.new([destinationUrl])
|
51
58
|
|
52
59
|
beanstalk.list_tubes[destinationUrl].each do |name|
|
53
60
|
tubeStats = beanstalk.stats_tube(name)
|
54
|
-
list << name + "(" + tubeStats["current-jobs-ready"].to_s + ")" if
|
61
|
+
list << name + "(" + tubeStats["current-jobs-ready"].to_s + ")" if queues.nil? or queues.index( name ).nil?
|
55
62
|
end
|
56
63
|
|
57
|
-
title = "beanstalk: #{
|
64
|
+
title = "beanstalk: #{user}@#{host} #{queues}"
|
58
65
|
formatOutput( title, list.join( "\n" ) )
|
59
66
|
end
|
60
67
|
|
data/lib/Snapshot/Ssh.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
require "net/ssh"
|
2
2
|
|
3
3
|
def ssh( params )
|
4
|
+
usage = "ssh :user=><username>, :host=><hostname>, :queues=><queue|[queue1,queue2,...]>"
|
5
|
+
user = get_param( params, :user, usage )
|
6
|
+
host = get_param( params, :host, usage )
|
7
|
+
cmd = get_param( params, :cmd, usage )
|
4
8
|
|
5
|
-
abort( "*** Incorrect parameters passed for, ssh\n*** Usage, ssh :user=><username>, :host=><hostname>, :cmd=><cmd>" ) if params.class.name != "Hash" || params.keys.length != 3
|
6
|
-
abort( "*** User parameter missing for, ssh, command\n*** Add, :user=><username>" ) if params[:user].nil?
|
7
|
-
abort( "*** Host parameter missing for, ssh, command\n*** Add, :host=><host>" ) if params[:host].nil?
|
8
|
-
abort( "*** Cmd parameter missing for, ssh, command\n*** Add, :cmd=><cmd>" ) if params[:cmd].nil?
|
9
|
-
|
10
9
|
content = ""
|
11
|
-
Net::SSH.start(
|
12
|
-
content = ssh.exec!(
|
10
|
+
Net::SSH.start(host, user) do |ssh|
|
11
|
+
content = ssh.exec!(cmd)
|
13
12
|
end
|
14
13
|
|
15
|
-
title = "ssh: #{
|
14
|
+
title = "ssh: #{user}@#{host} #{cmd}"
|
16
15
|
formatOutput( title, content )
|
17
16
|
end
|
data/lib/helper_functions.rb
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
require "net/ssh/gateway"
|
2
2
|
|
3
|
+
class ParameterMissingError<StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
def get_param( params, name, usage )
|
7
|
+
return params[name] unless params[name].nil?
|
8
|
+
return ENV[name.to_s] unless ENV[name.to_s].nil?
|
9
|
+
|
10
|
+
|
11
|
+
msg = %{*** Could not find parameter, #{name.to_s}, for command, #{caller[0][/`.*'/][1..-2]}
|
12
|
+
*** #{usage}
|
13
|
+
*** Try :#{name.to_s}=>'YourValue'
|
14
|
+
}
|
15
|
+
|
16
|
+
raise ParameterMissingError.new( msg )
|
17
|
+
end
|
18
|
+
|
19
|
+
def env( *args )
|
20
|
+
raise "Must have an even number of argument to env" if args.length % 2 != 0
|
21
|
+
|
22
|
+
(0..args.length-1).step(2) do |i|
|
23
|
+
ENV[args[i]] = args[i+1]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
3
27
|
def open_gateway( user, host )
|
4
28
|
log "Opening SSH Gateway to, #{host}", true
|
5
29
|
gateway = Net::SSH::Gateway.new(host, user)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servicesnapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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:
|
12
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: The fastest way to get a snapshot of your system.
|
15
15
|
email: guy@guyirvine.com
|