datacenter 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/datacenter.gemspec +1 -1
- data/lib/datacenter/process.rb +16 -13
- data/lib/datacenter/shell.rb +19 -10
- data/lib/datacenter/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00e4f1db48d930b517c89d8a48f716109e49ac1d
|
4
|
+
data.tar.gz: cefbf9313f800f8988d5d6b0f6239c24d2c6b8c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fceb78d5755b96ac6762a6d531a125383507a5f138c2b6edaddbdad2c84800615b55e90232bf626d0bebe7854c709f56d7d3d3fc7e73e6851f59f4a3b56ccb4
|
7
|
+
data.tar.gz: 5904e2beab150fc7552d78fb8f06c3c327f3a2d5cdec823c35b969261fc5855cf3e2cccae866d6fa53b4ac9be1389fb4239a97dbad2a5ac8c55e6a3c2e472e9f
|
data/datacenter.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'net-ssh'
|
21
|
+
spec.add_dependency 'net-ssh', '~> 2.9.2'
|
22
22
|
spec.add_dependency 'class_config'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
data/lib/datacenter/process.rb
CHANGED
@@ -19,6 +19,7 @@ module Datacenter
|
|
19
19
|
@pid = pid
|
20
20
|
@shell = shell || Shell::Local.new
|
21
21
|
@cache = Cache.new Datacenter.process_cache_expiration
|
22
|
+
@mutex = Mutex.new
|
22
23
|
end
|
23
24
|
|
24
25
|
ATTRIBUTES.each do |attribute|
|
@@ -42,19 +43,21 @@ module Datacenter
|
|
42
43
|
attr_reader :shell
|
43
44
|
|
44
45
|
def info
|
45
|
-
@
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
@mutex.synchronize do
|
47
|
+
@cache.fetch(:info) do
|
48
|
+
status = Hash[proc_file(:status).split("\n").map{ |s| s.split(':').map(&:strip) }]
|
49
|
+
ps = shell.run("ps -p #{pid} -o user,pid,pcpu,%mem,vsize,rss,stat,command").split("\n")[1].split
|
50
|
+
Hash.new.tap do |info|
|
51
|
+
info[:name] = status['Name']
|
52
|
+
info[:user] = ps[0]
|
53
|
+
info[:pid] = ps[1]
|
54
|
+
info[:cpu_usage] = ps[2].to_f
|
55
|
+
info[:mem_usage] = ps[3].to_f
|
56
|
+
info[:virtual_memory] = ps[4].to_i / 1024.0
|
57
|
+
info[:memory] = ps[5].to_i / 1024.0
|
58
|
+
info[:status] = ps[6]
|
59
|
+
info[:command] = ps[7..-1].reduce { |acum,e| "#{acum} #{e}" }
|
60
|
+
end
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
data/lib/datacenter/shell.rb
CHANGED
@@ -2,6 +2,11 @@ module Datacenter
|
|
2
2
|
module Shell
|
3
3
|
|
4
4
|
class Local
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@mutex = Mutex.new
|
8
|
+
end
|
9
|
+
|
5
10
|
def run(command)
|
6
11
|
Datacenter.logger.debug(self.class) { command }
|
7
12
|
if RUBY_ENGINE == 'jruby'
|
@@ -19,19 +24,23 @@ module Datacenter
|
|
19
24
|
end
|
20
25
|
|
21
26
|
def run_system(command)
|
22
|
-
|
23
|
-
|
27
|
+
@mutex.synchronize do
|
28
|
+
begin
|
29
|
+
$stdout = StringIO.new
|
30
|
+
$stderr = StringIO.new
|
24
31
|
|
25
|
-
|
32
|
+
system command
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
34
|
+
[$stdout, $stderr].map do |io|
|
35
|
+
io.rewind
|
36
|
+
io.readlines.join.force_encoding('UTF-8')
|
37
|
+
end.join.strip
|
31
38
|
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
ensure
|
40
|
+
$stdout = STDOUT
|
41
|
+
$stderr = STDERR
|
42
|
+
end
|
43
|
+
end
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
data/lib/datacenter/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datacenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.9.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.9.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: class_config
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
requirements: []
|
176
176
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.4.
|
177
|
+
rubygems_version: 2.4.8
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Manage and monitor servers and processes
|