freyr 0.3.4 → 0.3.5

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -81,14 +81,12 @@ module Freyr
81
81
 
82
82
  if args[:procinfo]
83
83
  begin
84
- @proc_list ||= ProcessInfoList.new
85
-
86
84
  pid = s.command.pid
87
-
88
- proc = @proc_list[pid.to_i]
89
-
90
- str << " CPU: #{proc.cpu}% - MEM: #{proc.mem}%" if proc
91
- rescue => e
85
+
86
+ proc = ProcessInfo[pid]
87
+
88
+ str << " CPU: #{proc.pcpu}% - MEM: #{proc.mem_in_mb}mb" if proc
89
+ # rescue => e
92
90
  end
93
91
  end
94
92
 
@@ -1,5 +1,33 @@
1
1
  module Freyr
2
2
  class ProcessInfo
3
- attr_accessor :user, :pid, :cpu, :mem, :vsz, :rss, :tt, :stat, :started, :time, :cmd
3
+ attr_reader :pid, :rss, :vsz, :pcpu, :pmem, :ruser, :command
4
+ def initialize pid
5
+ @pid = pid
6
+ end
7
+
8
+ def ps
9
+ return if !pid || pid.to_s.empty?
10
+ info = `ps p #{pid} -o pid,rss,vsz,pmem,pcpu,ruser,command`
11
+ match = info.match(/#{pid}\s+(\d+)\s+(\d+)\s+([\d\.]+)\s+([\d\.]+)\s+(\w+)\s+(.+)/)
12
+ return unless match
13
+ @rss = match[1].to_i
14
+ @vsz = match[2].to_i
15
+ @pmem = match[3].to_f
16
+ @pcpu = match[4].to_f
17
+ @ruser = match[5]
18
+ @command = match[6]
19
+ info
20
+ end
21
+
22
+ def mem_in_mb
23
+ @rss/1024
24
+ end
25
+
26
+ class << self
27
+ def [] *args
28
+ n = new(*args)
29
+ n.ps ? n : nil
30
+ end
31
+ end
4
32
  end
5
- end
33
+ end
data/lib/freyr.rb CHANGED
@@ -4,6 +4,6 @@ module Freyr
4
4
 
5
5
  end
6
6
 
7
- %w{version service_info service_group service command pinger process_info process_info_list}.each do |f|
7
+ %w{version service_info service_group service command pinger process_info}.each do |f|
8
8
  require File.expand_path(File.dirname(__FILE__)+"/freyr/#{f}.rb")
9
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freyr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tal Atlas
@@ -94,7 +94,6 @@ files:
94
94
  - lib/freyr/command.rb
95
95
  - lib/freyr/pinger.rb
96
96
  - lib/freyr/process_info.rb
97
- - lib/freyr/process_info_list.rb
98
97
  - lib/freyr/service.rb
99
98
  - lib/freyr/service_group.rb
100
99
  - lib/freyr/service_info.rb
@@ -1,32 +0,0 @@
1
- module Freyr
2
- class ProcessInfoList
3
- def initialize
4
- ps = `ps aux`.chomp.split("\n")
5
- ps.shift
6
-
7
- @processes = {}
8
- ps.each do |proc|
9
- proc = proc.split(/\s+/)
10
- p = ProcessInfo.new
11
- p.user = proc.shift
12
- p.pid = proc.shift
13
- p.cpu = proc.shift
14
- p.mem = proc.shift
15
- p.vsz = proc.shift
16
- p.rss = proc.shift
17
- p.tt = proc.shift
18
- p.stat = proc.shift
19
- p.started = proc.shift
20
- p.time = proc.shift
21
- p.cmd = proc.join(' ')
22
-
23
- @processes[p.pid.to_i] = p
24
- end
25
- end
26
-
27
- def [] pid
28
- @processes[pid.to_i]
29
- end
30
-
31
- end
32
- end