server_metrics 1.2.8 → 1.2.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 1.2.9.1
2
+
3
+ * Ruby 1.8.7 fix
4
+
5
+ ## 1.2.9
6
+
7
+ * Add support for dockerized metric gathering
8
+
9
+ ## 1.2.8
10
+
11
+ * compatibility with Ruby 1.8.5 and 1.8.6
12
+
1
13
  ## 1.2.7
2
14
 
3
15
  * Revert vz changes from 1.2.6
@@ -89,4 +101,4 @@ Performance related:
89
101
 
90
102
  ## 0.0.8.3
91
103
 
92
- * Fall back to assumption of 100 jiffies/sec if /proc/timer_list isn't available
104
+ * Fall back to assumption of 100 jiffies/sec if /proc/timer_list isn't available
@@ -46,7 +46,7 @@ class ServerMetrics::Cpu < ServerMetrics::Collector
46
46
  def self.fetch
47
47
  output = nil
48
48
  begin
49
- output = File.read("/proc/stat")
49
+ output = File.read("#{ServerMetrics::SystemInfo.proc_dir}/stat")
50
50
  rescue Errno::ENOENT
51
51
  # No such file or directory - /proc/stat
52
52
  # /proc/stat doesn't exist on this system.
@@ -1,3 +1,5 @@
1
+ require "server_metrics/system_info"
2
+
1
3
  # Collects Disk metrics on eligible filesystems. Reports a hash of hashes, with the first hash keyed by device name.
2
4
  #
3
5
  # TODO: Currently, this reports on devices that begins with /dev as listed by `mount`. Revisit this.
@@ -12,7 +14,7 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
12
14
 
13
15
  devices.each do |device|
14
16
  get_sizes(device) # does its own reporting
15
- get_io_stats(device) if linux? # does its own reporting
17
+ get_io_stats(device[:name]) if linux? # does its own reporting
16
18
  end
17
19
  end
18
20
 
@@ -30,10 +32,20 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
30
32
  def devices
31
33
  if @devices.nil? or @last_devices_output < (Time.now-@options[:ttl].to_i*60)
32
34
  @last_devices_output = Time.now
33
- @devices = `mount`.split("\n").grep(/^\/dev/).map{|l|l.split.first} # any device that starts with /dev
34
- else
35
- @devices
35
+ # if running inside a docker container, we want the devices mounted on the host
36
+ mount_output = dockerized_agent? ? `cat /host/etc/mtab` : `mount`
37
+ @devices = mount_output.split("\n").grep(/^\/dev/).map{|l| {:name => l.split.first, :aliases => []}} # any device that starts with /dev
38
+ if dockerized_agent?
39
+ `blkid`.split("\n").grep(/ UUID=/).each do |device|
40
+ name = device.match(/\A[^\:]*/)[0]
41
+ uuid = device.match(/\ UUID="(.+?)"/)[1]
42
+ if host_device = @devices.find { |dn| dn[:name] == name }
43
+ host_device[:aliases] << "/dev/disk/by-uuid/#{uuid}"
44
+ end
45
+ end
46
+ end
36
47
  end
48
+ @devices
37
49
  end
38
50
 
39
51
  # called from build_report for each device
@@ -48,7 +60,11 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
48
60
  end
49
61
 
50
62
  # select the right line
51
- hash = parsed_lines.select{|l| l["Filesystem"] == device}.first
63
+ hash = parsed_lines.find {|l| l["Filesystem"] == device[:name]}
64
+ # device wasn't found. check device aliases
65
+ if hash.nil?
66
+ hash = parsed_lines.find {|l| device[:aliases].include?(l["Filesystem"])}
67
+ end
52
68
  # device wasn't found. could be a mapped device. skip over.
53
69
  return if hash.nil?
54
70
  result = {}
@@ -58,35 +74,35 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
58
74
  result[key]=value
59
75
  end
60
76
 
61
- report(device, result)
77
+ report(device[:name], result)
62
78
  end
63
79
 
64
80
  # called from build_report for each device
65
- def get_io_stats(device)
66
- stats = iostat(device)
81
+ def get_io_stats(device_name)
82
+ stats = iostat(device_name)
67
83
 
68
84
  if stats
69
- counter(device, :rps, stats['rio'], :per => :second)
70
- counter(device, :wps, stats['wio'], :per => :second)
71
- counter(device, :rps_kb, stats['rsect'] / 2, :per => :second)
72
- counter(device, :wps_kb, stats['wsect'] / 2, :per => :second)
73
- counter(device, :utilization, stats['use'] / 10.0, :per => :second)
85
+ counter(device_name, :rps, stats['rio'], :per => :second)
86
+ counter(device_name, :wps, stats['wio'], :per => :second)
87
+ counter(device_name, :rps_kb, stats['rsect'] / 2, :per => :second)
88
+ counter(device_name, :wps_kb, stats['wsect'] / 2, :per => :second)
89
+ counter(device_name, :utilization, stats['use'] / 10.0, :per => :second)
74
90
  # Not 100% sure that average queue length is present on all distros.
75
91
  if stats['aveq']
76
- counter(device, :average_queue_length, stats['aveq'], :per => :second)
92
+ counter(device_name, :average_queue_length, stats['aveq'], :per => :second)
77
93
  end
78
94
 
79
- if old = memory(device, "stats")
95
+ if old = memory(device_name, "stats")
80
96
  ios = (stats['rio'] - old['rio']) + (stats['wio'] - old['wio'])
81
97
 
82
98
  if ios > 0
83
99
  await = ((stats['ruse'] - old['ruse']) + (stats['wuse'] - old['wuse'])) / ios.to_f
84
100
 
85
- report(device, :await => await)
101
+ report(device_name, :await => await)
86
102
  end
87
103
  end
88
104
 
89
- remember(device, "stats" => stats)
105
+ remember(device_name, "stats" => stats)
90
106
  end
91
107
  end
92
108
 
@@ -119,7 +135,7 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
119
135
 
120
136
  # Returns /proc/diskstats as array.
121
137
  def disk_stats
122
- File.readlines("/proc/diskstats")
138
+ File.readlines("#{ServerMetrics::SystemInfo.proc_dir}/diskstats")
123
139
  rescue Errno::ENOENT # Handle missing /proc/diskstats, i.e. on Mac OS X.
124
140
  []
125
141
  end
@@ -128,4 +144,8 @@ class ServerMetrics::Disk < ServerMetrics::MultiCollector
128
144
  key = "Used Percent" if /capacity|use.*%|%.*use/i === key
129
145
  key.downcase.gsub(" ", "_").to_sym
130
146
  end
147
+
148
+ def dockerized_agent?
149
+ File.exists?("/host/etc/mtab")
150
+ end
131
151
  end
@@ -1,3 +1,5 @@
1
+ require "server_metrics/system_info"
2
+
1
3
  class ServerMetrics::Memory < ServerMetrics::Collector
2
4
  # reports darwin units as MB
3
5
  DARWIN_UNITS = { "b" => 1/(1024*1024),
@@ -17,7 +19,7 @@ class ServerMetrics::Memory < ServerMetrics::Collector
17
19
 
18
20
  def linux_memory
19
21
  mem_info = {}
20
- File.read("/proc/meminfo").each_line do |line|
22
+ File.read("#{ServerMetrics::SystemInfo.proc_dir}/meminfo").each_line do |line|
21
23
  _, key, value = *line.match(/^(\w+):\s+(\d+)\s/)
22
24
  mem_info[key] = value.to_i
23
25
  end
@@ -4,7 +4,7 @@ class ServerMetrics::Network < ServerMetrics::MultiCollector
4
4
 
5
5
  def build_report
6
6
  if linux?
7
- lines = File.read("/proc/net/dev").lines.to_a[2..-1]
7
+ lines = File.read("#{ServerMetrics::SystemInfo.proc_dir}/net/dev").lines.to_a[2..-1]
8
8
  interfaces = []
9
9
  lines.each do |line|
10
10
  iface, rest = line.split(':', 2).collect { |e| e.strip }
@@ -80,15 +80,17 @@ module SysLite
80
80
  array = block_given? ? nil : []
81
81
  struct = nil
82
82
  raise TypeError unless pid.is_a?(Fixnum) if pid
83
+
84
+ proc_dir = ServerMetrics::SystemInfo.proc_dir
83
85
 
84
- Dir.chdir("/proc")
86
+ Dir.chdir(proc_dir)
85
87
  Dir.glob("[0-9]*").each do |file|
86
88
  next unless file.to_i == pid if pid
87
89
 
88
90
  struct = ProcTableStruct.new
89
91
 
90
92
  # Get /proc/<pid>/stat information
91
- stat = IO.read("/proc/#{file}/stat") rescue next
93
+ stat = IO.read("#{proc_dir}/#{file}/stat") rescue next
92
94
 
93
95
  # Deal with spaces in comm name. Courtesy of Ara Howard.
94
96
  re = %r/\([^\)]+\)/
@@ -42,6 +42,11 @@ module ServerMetrics
42
42
  def self.to_h
43
43
  {:architecture => architecture, :os=>os, :os_version=>os_version, :num_processors=>num_processors, :hostname=>hostname, :timezone=>timezone, :timezone_offset=>timezone_offset }
44
44
  end
45
+
46
+ # When run inside a docker container, we want to read from the host proc dir.
47
+ def self.proc_dir
48
+ @@proc_dir ||= (File.directory?("/host/proc") ? "/host/proc" : "/proc")
49
+ end
45
50
  end
46
51
  end
47
52
 
@@ -1,3 +1,3 @@
1
1
  module ServerMetrics
2
- VERSION = '1.2.8'
2
+ VERSION = '1.2.9.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Andre Lewis
@@ -10,104 +11,118 @@ authors:
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2014-12-11 00:00:00.000000000 Z
14
+ date: 2015-02-01 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: bundler
17
18
  requirement: !ruby/object:Gem::Requirement
19
+ none: false
18
20
  requirements:
19
- - - "~>"
21
+ - - ~>
20
22
  - !ruby/object:Gem::Version
21
23
  version: '1.3'
22
24
  type: :development
23
25
  prerelease: false
24
26
  version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
25
28
  requirements:
26
- - - "~>"
29
+ - - ~>
27
30
  - !ruby/object:Gem::Version
28
31
  version: '1.3'
29
32
  - !ruby/object:Gem::Dependency
30
33
  name: rake
31
34
  requirement: !ruby/object:Gem::Requirement
35
+ none: false
32
36
  requirements:
33
- - - ">="
37
+ - - ! '>='
34
38
  - !ruby/object:Gem::Version
35
39
  version: '0'
36
40
  type: :development
37
41
  prerelease: false
38
42
  version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
39
44
  requirements:
40
- - - ">="
45
+ - - ! '>='
41
46
  - !ruby/object:Gem::Version
42
47
  version: '0'
43
48
  - !ruby/object:Gem::Dependency
44
49
  name: awesome_print
45
50
  requirement: !ruby/object:Gem::Requirement
51
+ none: false
46
52
  requirements:
47
- - - ">="
53
+ - - ! '>='
48
54
  - !ruby/object:Gem::Version
49
55
  version: '0'
50
56
  type: :development
51
57
  prerelease: false
52
58
  version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
53
60
  requirements:
54
- - - ">="
61
+ - - ! '>='
55
62
  - !ruby/object:Gem::Version
56
63
  version: '0'
57
64
  - !ruby/object:Gem::Dependency
58
65
  name: pry
59
66
  requirement: !ruby/object:Gem::Requirement
67
+ none: false
60
68
  requirements:
61
- - - ">="
69
+ - - ! '>='
62
70
  - !ruby/object:Gem::Version
63
71
  version: '0'
64
72
  type: :development
65
73
  prerelease: false
66
74
  version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
67
76
  requirements:
68
- - - ">="
77
+ - - ! '>='
69
78
  - !ruby/object:Gem::Version
70
79
  version: '0'
71
80
  - !ruby/object:Gem::Dependency
72
81
  name: timecop
73
82
  requirement: !ruby/object:Gem::Requirement
83
+ none: false
74
84
  requirements:
75
- - - ">="
85
+ - - ! '>='
76
86
  - !ruby/object:Gem::Version
77
87
  version: '0'
78
88
  type: :development
79
89
  prerelease: false
80
90
  version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
81
92
  requirements:
82
- - - ">="
93
+ - - ! '>='
83
94
  - !ruby/object:Gem::Version
84
95
  version: '0'
85
96
  - !ruby/object:Gem::Dependency
86
97
  name: mocha
87
98
  requirement: !ruby/object:Gem::Requirement
99
+ none: false
88
100
  requirements:
89
- - - ">="
101
+ - - ! '>='
90
102
  - !ruby/object:Gem::Version
91
103
  version: '0'
92
104
  type: :development
93
105
  prerelease: false
94
106
  version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
95
108
  requirements:
96
- - - ">="
109
+ - - ! '>='
97
110
  - !ruby/object:Gem::Version
98
111
  version: '0'
99
112
  - !ruby/object:Gem::Dependency
100
113
  name: rspec
101
114
  requirement: !ruby/object:Gem::Requirement
115
+ none: false
102
116
  requirements:
103
- - - "~>"
117
+ - - ~>
104
118
  - !ruby/object:Gem::Version
105
119
  version: '2.14'
106
120
  type: :development
107
121
  prerelease: false
108
122
  version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
109
124
  requirements:
110
- - - "~>"
125
+ - - ~>
111
126
  - !ruby/object:Gem::Version
112
127
  version: '2.14'
113
128
  description: Collect information about disks, memory, CPU, networks, and processes
@@ -117,7 +132,7 @@ executables: []
117
132
  extensions: []
118
133
  extra_rdoc_files: []
119
134
  files:
120
- - ".gitignore"
135
+ - .gitignore
121
136
  - CHANGELOG.md
122
137
  - Gemfile
123
138
  - LICENSE.txt
@@ -153,26 +168,27 @@ files:
153
168
  homepage: http://scoutapp.com
154
169
  licenses:
155
170
  - MIT
156
- metadata: {}
157
171
  post_install_message:
158
172
  rdoc_options: []
159
173
  require_paths:
160
174
  - lib
161
175
  required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
162
177
  requirements:
163
- - - ">="
178
+ - - ! '>='
164
179
  - !ruby/object:Gem::Version
165
180
  version: '0'
166
181
  required_rubygems_version: !ruby/object:Gem::Requirement
182
+ none: false
167
183
  requirements:
168
- - - ">="
184
+ - - ! '>='
169
185
  - !ruby/object:Gem::Version
170
186
  version: '0'
171
187
  requirements: []
172
188
  rubyforge_project:
173
- rubygems_version: 2.2.2
189
+ rubygems_version: 1.8.23
174
190
  signing_key:
175
- specification_version: 4
191
+ specification_version: 3
176
192
  summary: Used by the Scout agent, but also available as a stand-lone gem
177
193
  test_files:
178
194
  - spec/server_metrics/collector_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: a4040b1194f4904d529f0b9325e5770d33ca7364
4
- data.tar.gz: 2cd897acaa0dbde2e0a44e4a3d83fa3263b8720c
5
- SHA512:
6
- metadata.gz: 18a1aaf212424d1d3801b7d1519980aacad35b9b84cbda28774638c70cb93fbf6db786e0222ef0c7366a4556cabd413067a166a92ac4feeada4f181a20b60ab0
7
- data.tar.gz: b55d1b3a853393b13c86a817a38e33d2587f659733613f5b31abd4fd518f08c5977b3a1406a7e00aa5d672bf99d857cd04c9a0f9878f44936505499055387d03