server_metrics 0.0.8.5 → 0.0.8.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,8 @@
6
6
  class ServerMetrics::Disk < ServerMetrics::MultiCollector
7
7
 
8
8
  def build_report
9
- @df_output = `df -h`.split("\n")
9
+ ENV['LANG'] = 'C' # forcing English for parsing
10
+ @df_output = `df -Pkh`.split("\n")
10
11
  @devices = `mount`.split("\n").grep(/^\/dev/).map{|l|l.split.first} # any device that starts with /dev
11
12
 
12
13
  @devices.each do |device|
@@ -17,15 +18,12 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
17
18
 
18
19
  # called from build_report for each device
19
20
  def get_sizes(device)
20
- ENV['LANG'] = 'C' # forcing English for parsing
21
-
22
21
  header_line=@df_output.first
23
- num_columns = header_line.include?("iused") ? 9 : 6 # Mac has extra columns
24
- headers = header_line.split(/\s+/,num_columns)
22
+ headers = header_line.split(/\s+/,6) # limit to 6 columns - last column is "mounted on"
25
23
  parsed_lines=[] # Each line will look like {"%iused" => "38%","Avail" => "289Gi", "Capacity=> "38%", "Filesystem"=> "/dev/disk0s2","Mounted => "/", "Size" => "465Gi", "Used" => "176Gi", "ifree" => "75812051", "iused" => "46116178"}
26
24
 
27
25
  @df_output[1..@df_output.size-1].each do |line|
28
- values=line.split(/\s+/,num_columns)
26
+ values=line.split(/\s+/,6)
29
27
  parsed_lines<<Hash[headers.zip(values)]
30
28
  end
31
29
 
@@ -1,3 +1,3 @@
1
1
  module ServerMetrics
2
- VERSION = "0.0.8.5"
2
+ VERSION = "0.0.8.6"
3
3
  end
@@ -13,7 +13,7 @@ none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
13
13
  none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
14
14
  nfsd on /proc/fs/nfsd type nfsd (rw)
15
15
 
16
- ### `df -h` ubuntu
16
+ ### `df -Pkh` ubuntu
17
17
  Filesystem Size Used Avail Use% Mounted on
18
18
  /dev/xvda1 124G 84G 37G 70% /
19
19
  none 7.9G 128K 7.9G 1% /dev
@@ -38,7 +38,7 @@ class TestWithFixtures < Test::Unit::TestCase
38
38
  c = ServerMetrics::Disk.new()
39
39
  fixture = fixtures(:disk)
40
40
  c.expects(:`).with("mount").returns(fixture.command("mount")).once
41
- c.expects(:`).with("df -h").returns(fixture.command("df -h")).once
41
+ c.expects(:`).with("df -Pkh").returns(fixture.command("df -Pkh")).once
42
42
  c.expects(:`).with("cat /proc/diskstats").returns(fixture.command("cat /proc/diskstats")).once
43
43
  c.run
44
44
 
@@ -85,7 +85,7 @@ eos
85
85
  c = ServerMetrics::Disk.new()
86
86
  c.expects(:`).with("mount").returns(fixture.command("mount")).once
87
87
  c.expects(:`).with("cat /proc/diskstats").returns(fixture.command("cat /proc/diskstats")).once
88
- c.expects(:`).with("df -h").returns(response)
88
+ c.expects(:`).with("df -Pkh").returns(response)
89
89
  c.run
90
90
 
91
91
  assert c.data['/dev/xvda1'][:used_percent]
@@ -97,7 +97,7 @@ eos
97
97
  c=test_disk
98
98
  fixture = fixtures(:disk)
99
99
  c.expects(:`).with("mount").returns(fixture.command("mount")).once
100
- c.expects(:`).with("df -h").returns(fixture.command("df -h")).once
100
+ c.expects(:`).with("df -Pkh").returns(fixture.command("df -Pkh")).once
101
101
  c.expects(:`).with("cat /proc/diskstats").returns(fixture.command("cat /proc/diskstats", "ubuntu second run")).once
102
102
 
103
103
  Timecop.travel(60) do
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: 0.0.8.5
4
+ version: 0.0.8.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-19 00:00:00.000000000 Z
12
+ date: 2013-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sys-proctable
@@ -172,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  segments:
174
174
  - 0
175
- hash: 1712031912329811387
175
+ hash: -1938747791304012429
176
176
  required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  segments:
183
183
  - 0
184
- hash: 1712031912329811387
184
+ hash: -1938747791304012429
185
185
  requirements: []
186
186
  rubyforge_project:
187
187
  rubygems_version: 1.8.23