server_metrics 1.2.3 → 1.2.4
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/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/lib/server_metrics/collector.rb +8 -2
- data/lib/server_metrics/collectors/disk.rb +10 -5
- data/lib/server_metrics/collectors/network.rb +0 -1
- data/lib/server_metrics/version.rb +1 -1
- data/server_metrics.gemspec +1 -0
- data/spec/server_metrics/collector_spec.rb +33 -0
- data/spec/server_metrics/collectors/disk_spec.rb +27 -0
- data/spec/spec_helper.rb +1 -0
- metadata +24 -2
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -136,12 +136,18 @@ module ServerMetrics
|
|
136
136
|
end
|
137
137
|
|
138
138
|
def linux?
|
139
|
-
|
139
|
+
ruby_config['target_os'].start_with?('linux')
|
140
140
|
end
|
141
141
|
|
142
142
|
def osx?
|
143
|
-
|
143
|
+
ruby_config['target_os'].start_with?('darwin')
|
144
144
|
end
|
145
145
|
|
146
|
+
private
|
147
|
+
|
148
|
+
# Returns hash of Ruby config parameters.
|
149
|
+
def ruby_config
|
150
|
+
RbConfig::CONFIG
|
151
|
+
end
|
146
152
|
end
|
147
153
|
end
|
@@ -10,8 +10,6 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
|
|
10
10
|
ENV['LC_ALL'] = 'C'
|
11
11
|
ENV['LANG'] = 'C'
|
12
12
|
|
13
|
-
@disk_stats = File.read("/proc/diskstats").lines.to_a
|
14
|
-
|
15
13
|
devices.each do |device|
|
16
14
|
get_sizes(device) # does its own reporting
|
17
15
|
get_io_stats(device) if linux? # does its own reporting
|
@@ -103,15 +101,15 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
|
|
103
101
|
# match /proc/diskstats output.
|
104
102
|
def iostat(dev)
|
105
103
|
|
106
|
-
# if this is a mapped device, translate it into the mapped name for lookup in
|
104
|
+
# if this is a mapped device, translate it into the mapped name for lookup in disk_stats
|
107
105
|
if dev =~ %r(^/dev/mapper/)
|
108
106
|
name_to_find = File.readlink(dev).split("/").last rescue dev
|
109
107
|
else
|
110
108
|
name_to_find = dev
|
111
109
|
end
|
112
110
|
|
113
|
-
# narrow our
|
114
|
-
possible_devices =
|
111
|
+
# narrow our disk_stats down to a list of possible devices
|
112
|
+
possible_devices = disk_stats.map { |line|
|
115
113
|
Hash[*COLUMNS.zip(line.strip.split(/\s+/).collect { |v| Integer(v) rescue v }).flatten]
|
116
114
|
}.select{|entry| name_to_find.include?(entry['name']) }
|
117
115
|
|
@@ -119,6 +117,13 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
|
|
119
117
|
return possible_devices.find { |entry| name_to_find == entry['name'] } || possible_devices.first
|
120
118
|
end
|
121
119
|
|
120
|
+
# Returns /proc/diskstats as array.
|
121
|
+
def disk_stats
|
122
|
+
File.readlines("/proc/diskstats")
|
123
|
+
rescue Errno::ENOENT # Handle missing /proc/diskstats, i.e. on Mac OS X.
|
124
|
+
[]
|
125
|
+
end
|
126
|
+
|
122
127
|
def normalize_key(key)
|
123
128
|
key = "Used Percent" if /capacity|use.*%|%.*use/i === key
|
124
129
|
key.downcase.gsub(" ", "_").to_sym
|
data/server_metrics.gemspec
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ServerMetrics::Collector do
|
4
|
+
let(:collector) { ServerMetrics::Collector.new }
|
5
|
+
|
6
|
+
describe '#linux?' do
|
7
|
+
it 'is true when target OS starts with linux' do
|
8
|
+
collector.should_receive(:ruby_config).
|
9
|
+
and_return( {'target_os' => 'linux42.0'} )
|
10
|
+
expect(collector.linux?).to be true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is false when target OS does not start with linux' do
|
14
|
+
collector.should_receive(:ruby_config).
|
15
|
+
and_return( {'target_os' => 'chunkybacon'} )
|
16
|
+
expect(collector.linux?).to be false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#osx?' do
|
21
|
+
it 'is true when target OS starts with darwin' do
|
22
|
+
collector.should_receive(:ruby_config).
|
23
|
+
and_return( {'target_os' => 'darwin42.0'} )
|
24
|
+
expect(collector.osx?).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is false when target OS does not start with darwin' do
|
28
|
+
collector.should_receive(:ruby_config).
|
29
|
+
and_return( {'target_os' => 'chunkybacon'} )
|
30
|
+
expect(collector.osx?).to be false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ServerMetrics::Disk do
|
4
|
+
let(:disk) { ServerMetrics::Disk.new }
|
5
|
+
|
6
|
+
describe '#iostat' do
|
7
|
+
it 'uses Disk#diskstats instead @disk_stats' do
|
8
|
+
disk.should_receive(:disk_stats).and_return( [] )
|
9
|
+
expect {
|
10
|
+
disk.send(:iostat, '/dev/chunky')
|
11
|
+
}.to_not raise_error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#disk_stats' do
|
16
|
+
it 'returns lines from /proc/diskstats as array' do
|
17
|
+
File.should_receive(:readlines).with('/proc/diskstats').
|
18
|
+
and_return( %w(chunky bacon) )
|
19
|
+
expect(disk.send(:disk_stats)).to eq %w(chunky bacon)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns empty array when /proc/diskstats is missing' do
|
23
|
+
File.stub(:readlines).and_raise(Errno::ENOENT)
|
24
|
+
expect(disk.send(:disk_stats)).to eq []
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'server_metrics'
|
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.2.
|
4
|
+
version: 1.2.4
|
5
5
|
prerelease:
|
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-03
|
14
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -109,6 +109,22 @@ dependencies:
|
|
109
109
|
- - ! '>='
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rspec
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ~>
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '2.14'
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ~>
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '2.14'
|
112
128
|
description: Collect information about disks, memory, CPU, networks, and processes
|
113
129
|
email:
|
114
130
|
- support@scoutapp.com
|
@@ -136,6 +152,9 @@ files:
|
|
136
152
|
- lib/server_metrics/system_info.rb
|
137
153
|
- lib/server_metrics/version.rb
|
138
154
|
- server_metrics.gemspec
|
155
|
+
- spec/server_metrics/collector_spec.rb
|
156
|
+
- spec/server_metrics/collectors/disk_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
139
158
|
- test/fixtures/cpu.txt
|
140
159
|
- test/fixtures/disk.txt
|
141
160
|
- test/fixtures/memory.txt
|
@@ -171,6 +190,9 @@ signing_key:
|
|
171
190
|
specification_version: 3
|
172
191
|
summary: Used by the Scout agent, but also available as a stand-lone gem
|
173
192
|
test_files:
|
193
|
+
- spec/server_metrics/collector_spec.rb
|
194
|
+
- spec/server_metrics/collectors/disk_spec.rb
|
195
|
+
- spec/spec_helper.rb
|
174
196
|
- test/fixtures/cpu.txt
|
175
197
|
- test/fixtures/disk.txt
|
176
198
|
- test/fixtures/memory.txt
|