server_metrics 1.1.0.pre → 1.1.1.pre
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/CHANGELOG.md +5 -0
- data/lib/server_metrics/collectors/processes.rb +22 -10
- data/lib/server_metrics/system_info.rb +2 -2
- data/lib/server_metrics/version.rb +1 -1
- metadata +3 -5
data/CHANGELOG.md
CHANGED
@@ -84,15 +84,7 @@ class ServerMetrics::Processes
|
|
84
84
|
elapsed_jiffies = current_jiffies - @last_jiffies
|
85
85
|
if elapsed_time >= 1
|
86
86
|
processes.each do |p|
|
87
|
-
|
88
|
-
p.recent_cpu = p.combined_cpu - last_cpu
|
89
|
-
else
|
90
|
-
p.recent_cpu = p.combined_cpu # this process wasn't around last time, so just use the cumulative CPU time for its existence so far
|
91
|
-
end
|
92
|
-
# a) p.recent_cpu / elapsed_jiffies = the amount of CPU time this process has taken divided by the total "time slots" the CPU has available
|
93
|
-
# b) * 100 ... this turns it into a percentage
|
94
|
-
# b) / num_processors ... this normalizes for the the number of processors in the system, so it reflects the amount of CPU power avaiable as a whole
|
95
|
-
p.recent_cpu_percentage = ((p.recent_cpu.to_f / elapsed_jiffies.to_f ) * 100.0) / num_processors.to_f
|
87
|
+
p.set_recent_cpu(@last_process_list[p.pid],elapsed_jiffies,num_processors)
|
96
88
|
end
|
97
89
|
end
|
98
90
|
end
|
@@ -107,7 +99,7 @@ class ServerMetrics::Processes
|
|
107
99
|
:cmdlines => []
|
108
100
|
}
|
109
101
|
grouped[proc.comm][:count] += 1
|
110
|
-
grouped[proc.comm][:cpu] += proc.recent_cpu_percentage
|
102
|
+
grouped[proc.comm][:cpu] += proc.recent_cpu_percentage
|
111
103
|
if proc.has?(:rss) # mac doesn't return rss. Mac returns 0 for memory usage
|
112
104
|
# converted to MB from bytes
|
113
105
|
grouped[proc.comm][:memory] += (proc.rss.to_f*page_size) / 1024 / 1024
|
@@ -173,16 +165,36 @@ class ServerMetrics::Processes
|
|
173
165
|
@pts=proctable_struct
|
174
166
|
@recent_cpu = 0
|
175
167
|
end
|
168
|
+
|
176
169
|
# because apparently respond_to doesn't work through method_missing
|
177
170
|
def has?(method_name)
|
178
171
|
@pts.respond_to?(method_name)
|
179
172
|
end
|
173
|
+
|
174
|
+
def set_recent_cpu(last_cpu,elapsed_jiffies,num_processors)
|
175
|
+
if last_cpu
|
176
|
+
self.recent_cpu = combined_cpu - last_cpu
|
177
|
+
else
|
178
|
+
self.recent_cpu = combined_cpu # this process wasn't around last time, so just use the cumulative CPU time for its existence so far
|
179
|
+
end
|
180
|
+
# a) self.recent_cpu / elapsed_jiffies = the amount of CPU time this process has taken divided by the total "time slots" the CPU has available
|
181
|
+
# b) * 100 ... this turns it into a percentage
|
182
|
+
# b) / num_processors ... this normalizes for the the number of processors in the system, so it reflects the amount of CPU power avaiable as a whole
|
183
|
+
self.recent_cpu_percentage = ((recent_cpu.to_f / elapsed_jiffies.to_f ) * 100.0) / num_processors.to_f
|
184
|
+
end
|
185
|
+
|
186
|
+
def recent_cpu_percentage
|
187
|
+
# On RaspberryPi, cpu % has been reported as both Infinite and NaN. Instead, 0 is reported.
|
188
|
+
(@recent_cpu_percentage and !@recent_cpu_percentage.infinite? and !@recent_cpu_percentage.nan?) ? @recent_cpu_percentage : 0
|
189
|
+
end
|
190
|
+
|
180
191
|
def combined_cpu
|
181
192
|
# best thread I've seen on cutime vs utime & cstime vs stime: https://www.ruby-forum.com/topic/93176
|
182
193
|
# * cutime and cstime include CPUusage of child processes
|
183
194
|
# * utime and stime don't include CPU usage of child processes
|
184
195
|
(utime || 0) + (stime || 0) # utime and stime aren't available on mac. Result is %cpu is 0 on mac.
|
185
196
|
end
|
197
|
+
|
186
198
|
# delegate everything else to ProcTable::Struct
|
187
199
|
def method_missing(sym, *args, &block)
|
188
200
|
@pts.send sym, *args, &block
|
@@ -21,10 +21,10 @@ module ServerMetrics
|
|
21
21
|
`sysctl -n hw.ncpu`.to_i
|
22
22
|
elsif os =~ /linux/
|
23
23
|
lines = `cat /proc/cpuinfo`.split("\n")
|
24
|
-
lines.grep(/^processor\s*:/).size
|
24
|
+
lines.grep(/^processor\s*:/i).size
|
25
25
|
end
|
26
26
|
rescue
|
27
|
-
|
27
|
+
1
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.timezone
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: server_metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1.pre
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-01-
|
14
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -157,9 +157,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
157
|
- - ! '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
|
-
segments:
|
161
|
-
- 0
|
162
|
-
hash: 926714783005878761
|
163
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
161
|
none: false
|
165
162
|
requirements:
|
@@ -181,3 +178,4 @@ test_files:
|
|
181
178
|
- test/test_basics.rb
|
182
179
|
- test/test_helper.rb
|
183
180
|
- test/test_with_fixtures.rb
|
181
|
+
has_rdoc:
|