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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf9e6023877cc1a608033a323719d016c78c0ee4
4
- data.tar.gz: 9039da364e1b6514c5314495b70cb5aed94d67cb
3
+ metadata.gz: 00e4f1db48d930b517c89d8a48f716109e49ac1d
4
+ data.tar.gz: cefbf9313f800f8988d5d6b0f6239c24d2c6b8c6
5
5
  SHA512:
6
- metadata.gz: a69725f3ead19ae06730bbdc9045c0b7f395b5e3dfbf2f70eabe8e4473ab94d4c39bc8a124d8938522098e479672472e238a78a6d97b103470936e7a0f621c3a
7
- data.tar.gz: dcb60ea81aad847f4ca853d8106d88b0ce44dc191d533473becded4e905d2685ed06fa9a4759136c790f0b7fb51e32c3b019ebb1ac6191f6fad0a6a24867abd1
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'
@@ -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
- @cache.fetch(:info) do
46
- status = Hash[proc_file(:status).split("\n").map{ |s| s.split(':').map(&:strip) }]
47
- ps = shell.run("ps -p #{pid} -o user,pid,pcpu,%mem,vsize,rss,stat,command").split("\n")[1].split
48
- Hash.new.tap do |info|
49
- info[:name] = status['Name']
50
- info[:user] = ps[0]
51
- info[:pid] = ps[1]
52
- info[:cpu_usage] = ps[2].to_f
53
- info[:mem_usage] = ps[3].to_f
54
- info[:virtual_memory] = ps[4].to_i / 1024.0
55
- info[:memory] = ps[5].to_i / 1024.0
56
- info[:status] = ps[6]
57
- info[:command] = ps[7..-1].reduce { |acum,e| "#{acum} #{e}" }
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
@@ -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
- $stdout = StringIO.new
23
- $stderr = StringIO.new
27
+ @mutex.synchronize do
28
+ begin
29
+ $stdout = StringIO.new
30
+ $stderr = StringIO.new
24
31
 
25
- system command
32
+ system command
26
33
 
27
- [$stdout, $stderr].map do |io|
28
- io.rewind
29
- io.readlines.join.force_encoding('UTF-8')
30
- end.join.strip
34
+ [$stdout, $stderr].map do |io|
35
+ io.rewind
36
+ io.readlines.join.force_encoding('UTF-8')
37
+ end.join.strip
31
38
 
32
- ensure
33
- $stdout = STDOUT
34
- $stderr = STDERR
39
+ ensure
40
+ $stdout = STDOUT
41
+ $stderr = STDERR
42
+ end
43
+ end
35
44
  end
36
45
  end
37
46
 
@@ -1,3 +1,3 @@
1
1
  module Datacenter
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.1'
3
3
  end
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.2.2
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: 2015-10-28 00:00:00.000000000 Z
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: '0'
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: '0'
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.7
177
+ rubygems_version: 2.4.8
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Manage and monitor servers and processes