server_metrics 0.0.8.7.pre → 0.0.8.8

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 CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.8.8
2
+
3
+ * fix for LVM-mapped disk IO stats
4
+
1
5
  ## 0.0.8.5
2
6
 
3
7
  * Mac per-process memory and per-process CPU reports 0s instead of throwing an exception (Mac only)
@@ -1,6 +1,5 @@
1
1
  require "rubygems"
2
- require File.dirname(__FILE__)+ "/lib/server_metrics"
3
- require "pry"
2
+ require "server_metrics"
4
3
 
5
4
  class Harness
6
5
  attr_accessor :num_runs, :latest_run
@@ -30,7 +29,7 @@ harness = Harness.new
30
29
  harness.run
31
30
  sleep 1
32
31
  harness.run
33
- pp harness.latest_run
32
+ puts harness.latest_run.inspect
34
33
 
35
34
  #puts "starting"
36
35
  #while(true) do
@@ -9,6 +9,7 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
9
9
  ENV['LANG'] = 'C' # forcing English for parsing
10
10
  @df_output = `df -Pkh`.split("\n")
11
11
  @devices = `mount`.split("\n").grep(/^\/dev/).map{|l|l.split.first} # any device that starts with /dev
12
+ @disk_stats = `cat /proc/diskstats`.split("\n")
12
13
 
13
14
  @devices.each do |device|
14
15
  get_sizes(device) # does its own reporting
@@ -77,28 +78,22 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
77
78
  # * If there isn't an exact match but there are /proc/diskstats lines that are included in +dev+,
78
79
  # returns the first matching line. This is needed as the mount output used to find the default device doesn't always
79
80
  # match /proc/diskstats output.
80
- # * If there are no matches but an LVM is used, returns the line matching "dm-0".
81
81
  def iostat(dev)
82
- # if a LVM is used, `mount` output doesn't map to `/diskstats`. In this case, use dm-0 as the default device.
83
- lvm = nil
84
- retried = false
85
- possible_devices = []
86
- begin
87
- %x(cat /proc/diskstats).split(/\n/).each do |line|
88
- entry = Hash[*COLUMNS.zip(line.strip.split(/\s+/).collect { |v| Integer(v) rescue v }).flatten]
89
- possible_devices << entry if dev.include?(entry['name'])
90
- lvm = entry if (@default_device_used and 'dm-0'.include?(entry['name']))
91
- end
92
- rescue Errno::EPIPE
93
- if retried
94
- raise
95
- else
96
- retried = true
97
- retry
98
- end
82
+
83
+ # if this is a mapped device, translate it into the mapped name for lookup in @disk_stats
84
+ if dev =~ %r(^/dev/mapper/)
85
+ name_to_find = File.readlink(dev).split("/").last rescue dev
86
+ else
87
+ name_to_find = dev
99
88
  end
100
- found_device = possible_devices.find { |entry| dev == entry['name'] } || possible_devices.first
101
- return found_device || lvm
89
+
90
+ # narrow our @disk_stats down to a list of possible devices
91
+ possible_devices = @disk_stats.map { |line|
92
+ Hash[*COLUMNS.zip(line.strip.split(/\s+/).collect { |v| Integer(v) rescue v }).flatten]
93
+ }.select{|entry| name_to_find.include?(entry['name']) }
94
+
95
+ # return an exact match (preferred) or a partial match. If neither exist, nil will be returned
96
+ return possible_devices.find { |entry| name_to_find == entry['name'] } || possible_devices.first
102
97
  end
103
98
 
104
99
  def normalize_key(key)
@@ -157,7 +157,7 @@ class ServerMetrics::Processes
157
157
  # best thread I've seen on cutime vs utime & cstime vs stime: https://www.ruby-forum.com/topic/93176
158
158
  # * cutime and cstime include CPUusage of child processes
159
159
  # * utime and stime don't include CPU usage of child processes
160
- (cutime || 0) + (cstime || 0) # utime and stime aren't available on mac. Result is %cpu is 0 on mac.
160
+ (utime || 0) + (stime || 0) # utime and stime aren't available on mac. Result is %cpu is 0 on mac.
161
161
  end
162
162
  # delegate everything else to ProcTable::Struct
163
163
  def method_missing(sym, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module ServerMetrics
2
- VERSION = "0.0.8.7.pre"
2
+ VERSION = "0.0.8.8"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8.7.pre
5
- prerelease: 8
4
+ version: 0.0.8.8
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andre Lewis
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-30 00:00:00.000000000 Z
12
+ date: 2014-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sys-proctable
@@ -172,13 +172,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  segments:
174
174
  - 0
175
- hash: 2782727168826211888
175
+ hash: 1750487156162138654
176
176
  required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
179
- - - ! '>'
179
+ - - ! '>='
180
180
  - !ruby/object:Gem::Version
181
- version: 1.3.1
181
+ version: '0'
182
+ segments:
183
+ - 0
184
+ hash: 1750487156162138654
182
185
  requirements: []
183
186
  rubyforge_project:
184
187
  rubygems_version: 1.8.23