datacenter 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datacenter/cache.rb +9 -11
- data/lib/datacenter/process.rb +5 -7
- data/lib/datacenter/shell.rb +3 -1
- data/lib/datacenter/version.rb +1 -1
- data/lib/datacenter.rb +1 -0
- data/spec/commands.yml +23 -22
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dd32253b277b657b34434c9ce9eef0eae0f5b89
|
4
|
+
data.tar.gz: eea49f8e1a6d5efcfe8d0d8692972e51ea81057d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3091059ea87e63c6f70f0c2048dcf2d5265d8e730bb56a142b2e5033b0756490fabefe1e5c3e7bf92dd1e730d463a388498085a8e421ce20bae01816b81a7489
|
7
|
+
data.tar.gz: 785dce16665ea7b28970025c8ffa99ef1290d5bd7f073b2c55ffd596a41e3fabaefd9eb52713d86a3f7b20f874d98464d166017c175192c7c2f8d41cfca9d5d4
|
data/lib/datacenter/cache.rb
CHANGED
@@ -7,30 +7,28 @@ module Datacenter
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def fetch(key, &block)
|
10
|
-
set key,
|
10
|
+
set key, block.call if !data.key?(key) || expired?(key)
|
11
11
|
get key
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
+
attr_reader :data, :expiration_time
|
17
|
+
|
16
18
|
def get(key)
|
17
|
-
|
19
|
+
data[key][:value]
|
18
20
|
end
|
19
21
|
|
20
|
-
def set(key,
|
21
|
-
|
22
|
-
value:
|
22
|
+
def set(key, value)
|
23
|
+
data[key] = {
|
24
|
+
value: value,
|
23
25
|
fetched_at: Time.now
|
24
26
|
}
|
25
27
|
end
|
26
28
|
|
27
|
-
def key?(key)
|
28
|
-
@data.key? key
|
29
|
-
end
|
30
|
-
|
31
29
|
def expired?(key)
|
32
|
-
return false unless
|
33
|
-
Time.now >=
|
30
|
+
return false unless expiration_time
|
31
|
+
Time.now >= data[key][:fetched_at] + expiration_time
|
34
32
|
end
|
35
33
|
|
36
34
|
end
|
data/lib/datacenter/process.rb
CHANGED
@@ -13,14 +13,12 @@ module Datacenter
|
|
13
13
|
:mem_usage
|
14
14
|
]
|
15
15
|
|
16
|
-
EXPIRATION_TIME = 2
|
17
|
-
|
18
16
|
attr_reader :pid
|
19
17
|
|
20
18
|
def initialize(pid, shell=nil)
|
21
19
|
@pid = pid
|
22
20
|
@shell = shell || Shell::Local.new
|
23
|
-
@cache = Cache.new
|
21
|
+
@cache = Cache.new Datacenter.process_cache_expiration
|
24
22
|
end
|
25
23
|
|
26
24
|
ATTRIBUTES.each do |attribute|
|
@@ -45,9 +43,9 @@ module Datacenter
|
|
45
43
|
|
46
44
|
def info
|
47
45
|
@cache.fetch(:info) do
|
48
|
-
|
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
|
49
48
|
Hash.new.tap do |info|
|
50
|
-
status = Hash[proc_file(:status).split("\n").map{ |s| s.split(':').map(&:strip) }]
|
51
49
|
info[:name] = status['Name']
|
52
50
|
info[:user] = ps[0]
|
53
51
|
info[:pid] = ps[1]
|
@@ -55,8 +53,8 @@ module Datacenter
|
|
55
53
|
info[:mem_usage] = ps[3].to_f
|
56
54
|
info[:virtual_memory] = ps[4].to_i / 1024.0
|
57
55
|
info[:memory] = ps[5].to_i / 1024.0
|
58
|
-
info[:status] = ps[
|
59
|
-
info[:command] = ps[
|
56
|
+
info[:status] = ps[6]
|
57
|
+
info[:command] = ps[7..-1].reduce { |acum,e| "#{acum} #{e}" }
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
data/lib/datacenter/shell.rb
CHANGED
@@ -3,6 +3,7 @@ module Datacenter
|
|
3
3
|
|
4
4
|
class Local
|
5
5
|
def run(command)
|
6
|
+
Datacenter.logger.debug(self.class) { command }
|
6
7
|
if RUBY_ENGINE == 'jruby'
|
7
8
|
run_system command
|
8
9
|
else
|
@@ -42,6 +43,7 @@ module Datacenter
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def run(command)
|
46
|
+
Datacenter.logger.debug(self.class) { command }
|
45
47
|
if @session
|
46
48
|
@session.exec!(command).strip
|
47
49
|
else
|
@@ -50,7 +52,7 @@ module Datacenter
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def open
|
53
|
-
@session
|
55
|
+
@session ||= Net::SSH.start *options
|
54
56
|
end
|
55
57
|
|
56
58
|
def close
|
data/lib/datacenter/version.rb
CHANGED
data/lib/datacenter.rb
CHANGED
data/spec/commands.yml
CHANGED
@@ -2,25 +2,23 @@
|
|
2
2
|
|
3
3
|
"ps -p -22803 | grep -22803": ""
|
4
4
|
|
5
|
-
"kill -s QUIT 22803":
|
5
|
+
"kill -s QUIT 22803": "quit success"
|
6
6
|
|
7
|
-
"kill -s KILL 22803":
|
7
|
+
"kill -s KILL 22803": "kill success"
|
8
8
|
|
9
|
-
"uname -i": x86_64
|
9
|
+
"uname -i": "x86_64"
|
10
10
|
|
11
|
-
"uname -r": 3.5.0-49-generic
|
11
|
+
"uname -r": "3.5.0-49-generic"
|
12
12
|
|
13
|
-
"uname -o": GNU/Linux
|
13
|
+
"uname -o": "GNU/Linux"
|
14
14
|
|
15
15
|
"lsb_release -i": "Distributor ID: Ubuntu"
|
16
16
|
|
17
17
|
"lsb_release -r": "Release: 12.04"
|
18
18
|
|
19
|
-
hostname:
|
20
|
-
matias
|
19
|
+
"hostname": "matias"
|
21
20
|
|
22
|
-
nproc:
|
23
|
-
2
|
21
|
+
"nproc": "2"
|
24
22
|
|
25
23
|
"df -lT": |
|
26
24
|
Filesystem Type 1K-blocks Used Available Use% Mounted on
|
@@ -31,7 +29,7 @@ nproc: |
|
|
31
29
|
none tmpfs 5120 0 5120 0% /run/lock
|
32
30
|
none tmpfs 2019816 512 2019304 1% /run/shm
|
33
31
|
|
34
|
-
ifconfig: |
|
32
|
+
"ifconfig": |
|
35
33
|
eth4 Link encap:Ethernet HWaddr e0:cb:4e:c2:99:9d
|
36
34
|
inet addr:192.168.50.127 Bcast:192.168.50.255 Mask:255.255.255.0
|
37
35
|
inet6 addr: fe80::e2cb:4eff:fec2:999d/64 Scope:Link
|
@@ -41,7 +39,7 @@ ifconfig: |
|
|
41
39
|
collisions:0 txqueuelen:1000
|
42
40
|
RX bytes:110494415 (110.4 MB) TX bytes:21453491 (21.4 MB)
|
43
41
|
|
44
|
-
lo Link encap:Local Loopback
|
42
|
+
lo Link encap:Local Loopback
|
45
43
|
inet addr:127.0.0.1 Mask:255.0.0.0
|
46
44
|
inet6 addr: ::1/128 Scope:Host
|
47
45
|
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
@@ -82,6 +80,15 @@ ifconfig: |
|
|
82
80
|
siblings : 2
|
83
81
|
core id : 0
|
84
82
|
|
83
|
+
"ps aux": |
|
84
|
+
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
|
85
|
+
root 1 0.0 0.0 24548 2460 ? Ss May15 0:00 /sbin/init
|
86
|
+
root 2 0.0 0.0 0 0 ? S May15 0:00 [kthreadd]
|
87
|
+
root 3 0.0 0.0 0 0 ? S May15 0:06 [ksoftirqd/0]
|
88
|
+
root 6 0.0 0.0 0 0 ? S May15 0:00 [migration/0]
|
89
|
+
root 7 0.0 0.0 0 0 ? S May15 0:00 [watchdog/0]
|
90
|
+
root 8 0.0 0.0 0 0 ? S May15 0:00 [migration/1]
|
91
|
+
matias 22803 11.9 0.8 513268 33792 ? Sl 09:43 52:47 gnome-system-monitor
|
85
92
|
|
86
93
|
"ps aux --sort -rss | head -n 11": |
|
87
94
|
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
|
@@ -117,19 +124,13 @@ ifconfig: |
|
|
117
124
|
matias 23542 0.0 0.2 34216 11408 pts/0 Ss 10:24 0:01 -bash
|
118
125
|
matias 22903 0.0 0.2 34164 11360 pts/1 Ss 09:46 0:00 -bash
|
119
126
|
|
120
|
-
"ps aux": |
|
121
|
-
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
|
122
|
-
root 1 0.0 0.0 24548 2460 ? Ss May15 0:00 /sbin/init
|
123
|
-
root 2 0.0 0.0 0 0 ? S May15 0:00 [kthreadd]
|
124
|
-
root 3 0.0 0.0 0 0 ? S May15 0:06 [ksoftirqd/0]
|
125
|
-
root 6 0.0 0.0 0 0 ? S May15 0:00 [migration/0]
|
126
|
-
root 7 0.0 0.0 0 0 ? S May15 0:00 [watchdog/0]
|
127
|
-
root 8 0.0 0.0 0 0 ? S May15 0:00 [migration/1]
|
128
|
-
matias 22803 11.9 0.8 513268 33792 ? Sl 09:43 52:47 gnome-system-monitor
|
129
|
-
|
130
|
-
ps aux | grep "gnome-system-monitor" | grep -v grep: |
|
127
|
+
"ps aux | grep \"gnome-system-monitor\" | grep -v grep": |
|
131
128
|
matias 22803 7.2 0.8 597980 34948 ? Sl May21 136:34 gnome-system-monitor
|
132
129
|
|
130
|
+
"ps -p 22803 -o user,pid,pcpu,%mem,vsize,rss,stat,command": |
|
131
|
+
USER PID %CPU %MEM VSZ RSS STAT COMMAND
|
132
|
+
matias 22803 11.9 0.8 513268 33792 Sl gnome-system-monitor
|
133
|
+
|
133
134
|
"cat /proc/22803/status": |
|
134
135
|
Name: gnome-system-mo
|
135
136
|
State: S (sleeping)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datacenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -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.7
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Manage and monitor servers and processes
|