server_metrics 0.0.8.9 → 0.0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,11 +1,15 @@
1
- ## 0.0.8.9
1
+ ## 0.0.9.0
2
+
3
+ * Reporting process memory in MB, not in page size.
4
+ * When determining process cpu usage, caching number of processors.
2
5
 
3
- * fix for top cpu-consuming processes in the process list
6
+ ## 0.0.8.9
4
7
 
8
+ * Fix for top cpu-consuming processes in the process list
5
9
 
6
10
  ## 0.0.8.8
7
11
 
8
- * fix for LVM-mapped disk IO stats
12
+ * Fix for LVM-mapped disk IO stats
9
13
 
10
14
  ## 0.0.8.5
11
15
 
@@ -13,8 +17,8 @@
13
17
 
14
18
  ## 0.0.8.4
15
19
 
16
- * normalize load (last minute, etc) by number of CPUs. This keeps the metrics in sync with Scout's server load plugin.
20
+ * Normalize load (last minute, etc) by number of CPUs. This keeps the metrics in sync with Scout's server load plugin.
17
21
 
18
22
  ## 0.0.8.3
19
23
 
20
- * fall back to assumption of 100 jiffies/sec if /proc/timer_list isn't available
24
+ * Fall back to assumption of 100 jiffies/sec if /proc/timer_list isn't available
@@ -2,9 +2,19 @@ require 'sys/proctable'
2
2
  require 'server_metrics/system_info'
3
3
 
4
4
  # Collects information on processes. Groups processes running under the same command, and sums up their CPU & memory usage.
5
- # CPU is calculated **since the last run**, and is a pecentage of overall CPU usage during the timeframe
5
+ # CPU is calculated **since the last run**, and is a pecentage of overall CPU usage during the time span since the instance was last run.
6
+ #
7
+ # FAQ:
8
+ #
9
+ # 1) top and htop show PIDs. Why doesn't this class? This class aggregates processes. So if you have 10 apache processes running, it will report the total memory and CPU for all instances, and also report that there are 10 processes.
10
+ #
11
+ # 2) why are the process CPU numbers lower than [top|htop]? We normalize the CPU usage according to the number of CPUs your server has. Top and htop don't do that. So on a 8 CPU system, you'd expect these numbers to be almost an order of magnitude lower.
12
+ #
13
+ #
6
14
  # http://www.linuxquestions.org/questions/linux-general-1/per-process-cpu-utilization-557577/
7
15
  class ServerMetrics::Processes
16
+ # most commmon - used if page size can't be retreived. units are bytes.
17
+ DEFAULT_PAGE_SIZE = 4096
8
18
 
9
19
  def initialize(options={})
10
20
  @last_run
@@ -23,8 +33,8 @@ class ServerMetrics::Processes
23
33
  # {
24
34
  # :cmd => "mysqld", # the command (without the path of arguments being run)
25
35
  # :count => 1, # the number of these processes (grouped by the above command)
26
- # :cpu => 34, # the total CPU usage of the processes
27
- # :memory => 2, # the total memory usage of the processes
36
+ # :cpu => 34, # the percentage of the total computational resources available (across all cores/CPU) that these processes are using.
37
+ # :memory => 2, # the percentage of total memory that these processes are using.
28
38
  # :cmd_lines => ["cmd args1", "cmd args2"]
29
39
  # },
30
40
  # 'apache' =>
@@ -52,7 +62,6 @@ class ServerMetrics::Processes
52
62
  # and calculates CPU time for each process. Since CPU time has to be calculated relative to the last sample,
53
63
  # the collector has to be run twice to get CPU data.
54
64
  def calculate_processes
55
- num_processors = ServerMetrics::SystemInfo.num_processors
56
65
  ## 1. get a list of all processes
57
66
  processes = Sys::ProcTable.ps.map{|p| ServerMetrics::Processes::Process.new(p) } # our Process object adds a method some behavior
58
67
 
@@ -90,8 +99,9 @@ class ServerMetrics::Processes
90
99
  }
91
100
  grouped[proc.comm][:count] += 1
92
101
  grouped[proc.comm][:cpu] += proc.recent_cpu_percentage || 0
93
- if proc.respond_to?(:rss) # mac doesn't return rss. Mac returns 0 for memory usage
94
- grouped[proc.comm][:memory] += proc.rss.to_f / 1024.0
102
+ if proc.has?(:rss) # mac doesn't return rss. Mac returns 0 for memory usage
103
+ # converted to MB from bytes
104
+ grouped[proc.comm][:memory] += (proc.rss.to_f*page_size) / 1024 / 1024
95
105
  end
96
106
  grouped[proc.comm][:cmdlines] << proc.cmdline if !grouped[proc.comm][:cmdlines].include?(proc.cmdline)
97
107
  end # processes.each
@@ -128,6 +138,18 @@ class ServerMetrics::Processes
128
138
  (Time.now.to_f*100).to_i
129
139
  end
130
140
  end
141
+
142
+ # Sys::ProcTable.ps returns +rss+ in pages, not in bytes.
143
+ # Returns the page size in bytes.
144
+ def page_size
145
+ @page_size ||= %x(getconf PAGESIZE).to_i
146
+ rescue
147
+ @page_size = DEFAULT_PAGE_SIZE
148
+ end
149
+
150
+ def num_processors
151
+ @num_processors ||= ServerMetrics::SystemInfo.num_processors
152
+ end
131
153
 
132
154
  # for persisting to a file -- conforms to same basic API as the Collectors do.
133
155
  # why not just use marshall? This is a lot more manageable written to the Scout agent's history file.
@@ -153,6 +175,10 @@ class ServerMetrics::Processes
153
175
  @pts=proctable_struct
154
176
  @recent_cpu = 0
155
177
  end
178
+ # because apparently respond_to doesn't work through method_missing
179
+ def has?(method_name)
180
+ @pts.respond_to?(method_name)
181
+ end
156
182
  def combined_cpu
157
183
  # best thread I've seen on cutime vs utime & cstime vs stime: https://www.ruby-forum.com/topic/93176
158
184
  # * cutime and cstime include CPUusage of child processes
@@ -1,3 +1,3 @@
1
1
  module ServerMetrics
2
- VERSION = "0.0.8.9"
2
+ VERSION = "0.0.9.0"
3
3
  end
@@ -6,10 +6,10 @@ require 'server_metrics/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "server_metrics"
8
8
  spec.version = ServerMetrics::VERSION
9
- spec.authors = ["Andre Lewis"]
10
- spec.email = ["andre@scoutapp.com"]
11
- spec.description = %q{Collect information about disks, memory, CPU, etc}
12
- spec.summary = %q{For use with the Scout agent}
9
+ spec.authors = ["Andre Lewis", "Derek Haynes", "Matt Rose"]
10
+ spec.email = ["support@scoutapp.com"]
11
+ spec.description = %q{Collect information about disks, memory, CPU, networks, and processes}
12
+ spec.summary = %q{Used by the Scout agent, but also available as a stand-lone gem}
13
13
  spec.homepage = "http://scoutapp.com"
14
14
  spec.license = "MIT"
15
15
 
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8.9
4
+ version: 0.0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andre Lewis
9
+ - Derek Haynes
10
+ - Matt Rose
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2014-01-07 00:00:00.000000000 Z
14
+ date: 2014-01-09 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
17
  name: sys-proctable
@@ -123,9 +125,9 @@ dependencies:
123
125
  - - ! '>='
124
126
  - !ruby/object:Gem::Version
125
127
  version: '0'
126
- description: Collect information about disks, memory, CPU, etc
128
+ description: Collect information about disks, memory, CPU, networks, and processes
127
129
  email:
128
- - andre@scoutapp.com
130
+ - support@scoutapp.com
129
131
  executables: []
130
132
  extensions: []
131
133
  extra_rdoc_files: []
@@ -172,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
174
  version: '0'
173
175
  segments:
174
176
  - 0
175
- hash: 3133671317737464320
177
+ hash: -2321548191254875842
176
178
  required_rubygems_version: !ruby/object:Gem::Requirement
177
179
  none: false
178
180
  requirements:
@@ -181,13 +183,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
183
  version: '0'
182
184
  segments:
183
185
  - 0
184
- hash: 3133671317737464320
186
+ hash: -2321548191254875842
185
187
  requirements: []
186
188
  rubyforge_project:
187
189
  rubygems_version: 1.8.23
188
190
  signing_key:
189
191
  specification_version: 3
190
- summary: For use with the Scout agent
192
+ summary: Used by the Scout agent, but also available as a stand-lone gem
191
193
  test_files:
192
194
  - test/fixtures/cpu.txt
193
195
  - test/fixtures/disk.txt