mool 2.0.1 → 3.0.0

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.
@@ -1,13 +0,0 @@
1
- class MoolLoadAverage
2
- attr_reader :current_loadavg, :last_5min_loadavg, :last_15min_loadavg, :thread_entities_exec, :total_thread_entities, :last_pid_process_created
3
-
4
- def initialize
5
- result = File.read("/proc/loadavg").chomp.split(" ")
6
- @current_loadavg = result[0].to_f
7
- @last_5min_loadavg = result[1].to_f
8
- @last_15min_loadavg = result[2].to_f
9
- @thread_entities_exec = result[3].split("/").first.to_i # Currently executing kernel scheduling entities
10
- @total_thread_entities = result[3].split("/").last.to_i # Number of kernel scheduling entities that currently exist on the system
11
- @last_pid_process_created = result[4].to_i
12
- end
13
- end
data/lib/mool/service.rb DELETED
@@ -1,80 +0,0 @@
1
- class MoolService
2
- STATUS_PROCESS = { "D" => I18n.t("process.status.uninterruptible_sleep"),
3
- "R" => I18n.t("process.status.running"),
4
- "S" => I18n.t("process.status.sleeping"),
5
- "T" => I18n.t("process.status.traced_or_stopped"),
6
- "Z" => I18n.t("process.status.zombie") }
7
-
8
- attr_reader :messure, :pattern
9
-
10
- def initialize(name, pattern, opt={})
11
- raise "Please only use string types!" if (name.class != String or pattern.class != String)
12
- @messure = []
13
- @pattern = pattern
14
-
15
- result = opt[:result] || MoolService.services_status([{:name => name, :pattern => pattern}])[name]
16
-
17
- result.each do |res|
18
- #pid,user,pcpu,pmem,rss,priority,args,nice, memory_in_kb, status, cpu_percetage, men_percentage, time
19
- @messure << { :name => name,
20
- :pattern => pattern,
21
- :pid => res[0],
22
- :user => res[1],
23
- :cpu_average => res[2],
24
- :mem_average => res[3],
25
- :resident_set_size => res[4],
26
- :priority => res[5],
27
- :time => res[6],
28
- :status => MoolService::STATUS_PROCESS[res[7]],
29
- :nice => res[8],
30
- :args => res[9],
31
- :memory_in_kb => res[10],
32
- :cpu_instant => (res[11] || 0),
33
- :mem_instant => (res[12] || 0.0)}
34
- end
35
- end
36
-
37
-
38
- def self.all(services)
39
- raise "Please only use Array type!" if services.class != Array
40
- _services = {}
41
-
42
- services_data = MoolService.services_status services
43
-
44
- services.each do |service|
45
- _services[service[:name]] = MoolService.new(service[:name],
46
- service[:pattern],
47
- { :result => services_data[service[:name]] })
48
- end
49
- _services
50
- end
51
-
52
- def self.services_status services
53
- command_ps = MoolService.ps
54
- command_top = MoolService.top
55
- result = {}
56
- services.each do |service|
57
- result[service[:name]] = MoolService.ps_parser(command_ps, service[:pattern]).collect{ |data| data += MoolService.top_parser(command_top, data[0]) }
58
- end
59
- result
60
- end
61
-
62
- def self.ps; `ps --no-headers -o pid,user,pcpu,pmem,rss,priority,time,stat,nice,args -A`; end
63
-
64
- def self.top; `top -c -b -n1`; end
65
-
66
- private
67
-
68
- def self.ps_parser(command, pattern)
69
- pattern = pattern.gsub('/','\/')
70
- # pid,user,pcpu,pmem,rss,priority,time,stat,nice,args
71
- command.scan(/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S)\S*\s+(\S+)\s+.*(#{pattern}).*\n/)
72
- end
73
-
74
- def self.top_parser(command, pid)
75
- # memory_in_kb, cpu_percetage, men_percentage
76
- # command.scan(/[\s+]#{pid}\s+\S+\s+\S+\s+(\S+)\s+\S+\s+(\S+)\s+\S+\s+(\S)\s+(\S+)\s+(\S+)\s+(\S+)\s+.*/)
77
- result = command.scan(/#{pid}\s+\S+\s+\S+\s+\S+\s+(\S+)\s+\S+\s+\S+\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+\S+/).flatten
78
- end
79
-
80
- end