oneapm_rpm 1.3.3 → 1.3.4.rc1

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Njc2ODZkMDE0YzE2YTNjMGVlYmM4ZDk2Y2M1YjVjZjQ5OTkwNTBmNg==
4
+ MmE0NDFhMTgyYjQxZDg5NWU0NTAzZTQyMDA1ZjBjMDRiMjY0NWE1OQ==
5
5
  data.tar.gz: !binary |-
6
- ZGEzYmYwYjBiNzE4Mzk4NzM4NTQzYmI3ZDcxMzYzMGJlZjU4Y2UxNg==
6
+ MmE1ZjcwYTUyZTc4NWE0ZjYzNWU2YjEyYTIyZTI4M2UwYzY2MTlmOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2RhZGUxYzQ4NGRmOGI2ZGZiODc5YzhhZDZjMGM5ODk1MDkyNWJkY2Y4OGUz
10
- MWJmZWE5MTFhNjgzNmZmZTU0MGVmMDI3MmE5NzgxMzVmNDMyNjYyY2YxNzcw
11
- M2E4MGMzZDUwMjQ1MWY5M2RhYWYyMjZhZjkxYTVkZjk0NGJhNzY=
9
+ MjMzYWExYmFlODhkZDE1YjBiMDZlYjYxNmRmODQ5NGNkZTAyMzBhMjRlNGEz
10
+ NzAyODFiY2NjNjUzZmU4YmU4Nzg4MjdjNTFlM2NhZjAxNTI3ZTAzZWMzZjU4
11
+ YzVjYmJkMjk2YmQyNmRiZThjMGMyNjdiMWUyYzczMTJjMmI0NTk=
12
12
  data.tar.gz: !binary |-
13
- NTZkNTVlZGQ5NmY1YjUyZWUwZDI0OTgyODAzY2M2ZWM2ZWE5MDRlZjgwZTBm
14
- MTBmY2EzMjBlYmU0NWFhYmU3NTA0NDBhNGIzYTAyOGUwMmY0NzI3MGQxNjAy
15
- NzVjM2I5NGEzYmI3MzkyZjA5ZWEyNWRkZTdiZTJjNWZlNDE2Mzg=
13
+ MjdjZGQwNjMzZmFiNGI3YmIzYzA1NWY2ZWRhYzZjMjFkMGJkNWQ2YTM1Nzhh
14
+ NDI2YWVjZjU1YjgzMWViOThjZjk4YTU5MTNhNGRkMzQ3NTRiYmFhZTMzYmJj
15
+ MTk0NjdjNzdhYWFlNmUzODFlOGU3YzE0Y2UxYWM5NjRjYzAyNTA=
@@ -15,14 +15,15 @@ module OneApm
15
15
  poll
16
16
  end
17
17
 
18
- def self.supported_on_this_platform?
19
- # Process.times on JRuby < 1.7.0 reports wall clock elapsed time, not actual cpu time used
20
- defined?(JRuby) ? (JRUBY_VERSION >= '1.7.0') : true
18
+ def set_poller poller
19
+ @poller = poller
21
20
  end
22
-
21
+
23
22
  def poll
24
23
  now = Time.now
24
+ @poller.pid = Process.pid if @poller
25
25
  t = Process.times
26
+
26
27
  if @last_time
27
28
  elapsed = now - @last_time
28
29
  return if elapsed < 1 # Causing some kind of math underflow
@@ -35,14 +36,21 @@ module OneApm
35
36
  OneApm::Manager.record_metric("CPU/System/Utilization", systemtime / (elapsed * @processor_count))
36
37
  end
37
38
  if usertime >= 0
39
+ cpu_utilization = @poller ? @poller.cpu_utilization : (usertime / (elapsed * @processor_count))
38
40
  OneApm::Manager.record_metric("CPU/User Time", usertime)
39
- OneApm::Manager.record_metric("CPU/User/Utilization", usertime / (elapsed * @processor_count))
41
+ OneApm::Manager.record_metric("CPU/User/Utilization", cpu_utilization)
40
42
  end
41
43
  end
42
44
  @last_utime = t.utime
43
45
  @last_stime = t.stime
44
46
  @last_time = now
45
47
  end
48
+
49
+ def self.supported_on_this_platform?
50
+ # Process.times on JRuby < 1.7.0 reports wall clock elapsed time, not actual cpu time used
51
+ defined?(JRuby) ? (JRUBY_VERSION >= '1.7.0') : true
52
+ end
53
+
46
54
  end
47
55
  end
48
56
  end
@@ -9,43 +9,8 @@ module OneApm
9
9
  class MemorySampler < OneApm::Collector::Sampler
10
10
  named :memory
11
11
 
12
- attr_accessor :sampler
13
-
14
- def initialize
15
- if defined? JRuby
16
- @sampler = JavaHeapSampler.new
17
- elsif platform =~ /linux/
18
- @sampler = ProcStatus.new
19
- if !@sampler.can_run?
20
- OneApm::Manager.logger.debug "Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead."
21
- @sampler = ShellPS.new("ps -o rsz")
22
- else
23
- OneApm::Manager.logger.debug "Using /proc/#{$$}/status for reading process memory."
24
- end
25
- elsif platform =~ /darwin9/ # 10.5
26
- @sampler = ShellPS.new("ps -o rsz")
27
- elsif platform =~ /darwin1\d+/ # >= 10.6
28
- @sampler = ShellPS.new("ps -o rss")
29
- elsif platform =~ /freebsd/
30
- @sampler = ShellPS.new("ps -o rss")
31
- elsif platform =~ /solaris/
32
- @sampler = ShellPS.new("/usr/bin/ps -o rss -p")
33
- end
34
-
35
- raise Unsupported, "Unsupported platform for getting memory: #{platform}" if @sampler.nil?
36
- raise Unsupported, "Unable to run #{@sampler}" unless @sampler.can_run?
37
- end
38
-
39
- def self.supported_on_this_platform?
40
- defined?(JRuby) or platform =~ /linux|darwin|freebsd|solaris/
41
- end
42
-
43
- def self.platform
44
- if RUBY_PLATFORM =~ /java/
45
- %x[uname -s].downcase
46
- else
47
- RUBY_PLATFORM.downcase
48
- end
12
+ def set_poller poller
13
+ @poller = poller
49
14
  end
50
15
 
51
16
  def platform
@@ -53,108 +18,37 @@ module OneApm
53
18
  end
54
19
 
55
20
  def poll
56
- sample = @sampler.get_sample
21
+ sample = get_sample
57
22
  if sample
58
23
  OneApm::Manager.record_metric("Memory/Used", sample)
59
24
  end
60
25
  end
61
26
 
62
- class Base
63
-
64
- def pgrp_id
65
- Process.getpgrp
66
- end
67
-
68
- def pids_cmd
69
- `ps -o pid,pgid -e | grep #{pgrp_id}`
70
- end
71
-
72
- def pids
73
- @pids = pids_cmd.split(/\s+/).uniq rescue [Process.pid]
74
- @pids = [Process.pid] if @pids.empty?
75
- @pids
76
- end
77
-
78
- def can_run?
79
- return false if @broken
80
- m = get_memory rescue nil
81
- m && m > 0
82
- end
83
-
84
- def get_memory
85
- pids.inject(0.0){|m, pid| m + get_memory_by_pid(pid)}
86
- end
87
-
88
- def get_sample
89
- return nil if @broken
90
- begin
91
- m = get_memory
92
- if m.nil?
93
- OneApm::Manager.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler."
94
- @broken = true
95
- end
96
- return m
97
- rescue => e
98
- OneApm::Manager.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler.", e
99
- @broken = true
100
- return nil
27
+ def get_sample
28
+ begin
29
+ m = @poller.memory
30
+ if m.nil?
31
+ OneApm::Manager.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler."
101
32
  end
33
+ return m
34
+ rescue => e
35
+ OneApm::Manager.logger.warn "Unable to get the resident memory for process #{$$}. Disabling memory sampler.", e
36
+ return nil
102
37
  end
103
-
104
38
  end
105
39
 
106
- class JavaHeapSampler < Base
107
-
108
- def get_memory
109
- raise "Can't sample Java heap unless running in JRuby" unless defined? JRuby
110
- java.lang.Runtime.getRuntime.totalMemory / (1024 * 1024).to_f rescue nil
111
- end
112
-
113
- def to_s
114
- "JRuby Java heap sampler"
115
- end
116
-
40
+ def self.supported_on_this_platform?
41
+ defined?(::JRuby) or platform =~ /linux|darwin|freebsd|solaris/
117
42
  end
118
43
 
119
- class ShellPS < Base
120
-
121
- def initialize(command)
122
- super()
123
- @command = command
124
- end
125
-
126
- def get_memory_by_pid pid
127
- process = pid
128
- memory = `#{@command} #{process}`.split("\n")[1].to_f / 1024.0 rescue nil
129
- raise "Faulty command: `#{@command} #{process}`" if memory.nil? || memory < 0
130
- memory
131
- end
132
-
133
- def to_s
134
- "shell command sampler: #{@command}"
44
+ def self.platform
45
+ if RUBY_PLATFORM =~ /java/
46
+ %x[uname -s].downcase
47
+ else
48
+ RUBY_PLATFORM.downcase
135
49
  end
136
-
137
50
  end
138
51
 
139
- class ProcStatus < Base
140
-
141
- def get_memory_by_pid pid
142
- proc_status = File.open(proc_status_file(pid), "r") {|f| f.read_nonblock(4096).strip }
143
- if proc_status =~ /RSS:\s*(\d+) kB/i
144
- return $1.to_f / 1024.0
145
- end
146
- raise "Unable to find RSS in #{proc_status_file}"
147
- end
148
-
149
- def proc_status_file pid=Process.pid
150
- "/proc/#{pid}/status"
151
- end
152
-
153
- def to_s
154
- "proc status file sampler: #{proc_status_file}"
155
- end
156
-
157
- end
158
52
  end
159
53
  end
160
54
  end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'one_apm/collector/support/shell_poller'
3
+
4
+ module OneApm
5
+ module Collector
6
+ class JrubyPoller < OneApm::Collector::ShellPoller
7
+
8
+ def self.enable?
9
+ defined?(::JRuby)
10
+ end
11
+
12
+ def memory
13
+ java.lang.Runtime.getRuntime.totalMemory / (1024 * 1024).to_f rescue nil
14
+ end
15
+
16
+ def to_s
17
+ "JrubyPoller from: java.lang.Runtime.getRuntime.totalMemory"
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ require 'one_apm/collector/support/shell_poller'
3
+
4
+ module OneApm
5
+ module Collector
6
+ class ProcPoller < OneApm::Collector::ShellPoller
7
+
8
+ UPTIME_PATH = '/proc/uptime'.freeze
9
+
10
+ def self.enable?
11
+ ::RUBY_PLATFORM.downcase =~ /linux/
12
+ end
13
+
14
+ def poll_memory
15
+ return 0.0 unless File.exist?(proc_status_file)
16
+ stats[:rss].to_f * OneApm::Collector::ShellPoller.kb_page_size / 1024.0
17
+ end
18
+
19
+ def cpu_utilization
20
+ @pid = Process.pid
21
+ stat = stats
22
+ total_time = stat[:utime].to_f + stat[:stime].to_f # in jiffies
23
+ seconds = uptime - stat[:starttime].to_f / 100
24
+ return 0.0 if seconds <= 0.0
25
+ ((total_time * 1000.0 / 100.0) / seconds) / 10.0 / 100.0
26
+ rescue => e
27
+ OneApm::Manager.logger.warn "Fetch cpu usage error: #{e.message}"
28
+ 0.0
29
+ end
30
+
31
+ def to_s
32
+ "ProcPoller from: #{proc_status_file}"
33
+ end
34
+
35
+ private
36
+ # in seconds
37
+ def uptime
38
+ File.read(UPTIME_PATH).split[0].to_f
39
+ end
40
+
41
+ def proc_status_file
42
+ "/proc/#{pid}/stat"
43
+ end
44
+
45
+ def stats
46
+ stat = {}
47
+ stat[:pid], stat[:comm], stat[:state], stat[:ppid], stat[:pgrp],
48
+ stat[:session], stat[:tty_nr], stat[:tpgid], stat[:flags],
49
+ stat[:minflt], stat[:cminflt], stat[:majflt], stat[:cmajflt],
50
+ stat[:utime], stat[:stime], stat[:cutime], stat[:cstime],
51
+ stat[:priority], stat[:nice], _, stat[:itrealvalue],
52
+ stat[:starttime], stat[:vsize], stat[:rss], stat[:rlim],
53
+ stat[:startcode], stat[:endcode], stat[:startstack], stat[:kstkesp],
54
+ stat[:kstkeip], stat[:signal], stat[:blocked], stat[:sigignore],
55
+ stat[:sigcatch], stat[:wchan], stat[:nswap], stat[:cnswap],
56
+ stat[:exit_signal], stat[:processor], stat[:rt_priority],
57
+ stat[:policy] = File.open(proc_status_file, "r") {|f| f.read_nonblock(4096).strip }.scan(/\(.*?\)|\w+/)
58
+ stat
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -1,4 +1,7 @@
1
1
  # encoding: utf-8
2
+ require 'one_apm/collector/support/shell_poller'
3
+ require 'one_apm/collector/support/proc_poller'
4
+ require 'one_apm/collector/support/jruby_poller'
2
5
 
3
6
  module OneApm
4
7
  module Collector
@@ -47,6 +50,7 @@ module OneApm
47
50
  if supported && enabled && !sampler_class_registered?(sampler_class)
48
51
  sampler = sampler_class.new
49
52
  sampler.setup_events(@event_listener) if sampler.respond_to?(:setup_events)
53
+ sampler.set_poller(poller) if sampler.respond_to?(:set_poller)
50
54
  @samplers << sampler
51
55
  OneApm::Manager.logger.debug("Registered #{sampler_class.name} for harvest time sampling.")
52
56
  else
@@ -57,6 +61,19 @@ module OneApm
57
61
  rescue => e
58
62
  OneApm::Manager.logger.error("Error registering sampler:", e)
59
63
  end
64
+
65
+ def poller
66
+ @pller ||= begin
67
+ if OneApm::Collector::JrubyPoller.enable?
68
+ OneApm::Collector::JrubyPoller.new
69
+ elsif OneApm::Collector::ProcPoller.enable?
70
+ OneApm::Collector::ProcPoller.new
71
+ else
72
+ OneApm::Collector::ShellPoller.new
73
+ end
74
+ end
75
+ end
76
+
60
77
  end
61
78
  end
62
79
  end
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+
3
+ module OneApm
4
+ module Collector
5
+ class ShellPoller
6
+
7
+ attr_accessor :pid
8
+
9
+ def memory
10
+ pids.inject(0.0){|m, pid| m + get_memory_by_pid(pid) }
11
+ end
12
+
13
+ def cpu_utilization
14
+ @pid = Process.pid
15
+ ps_float('%cpu') / 100.0
16
+ end
17
+
18
+ def to_s
19
+ "ShellPoller from: ps -p #{pid}"
20
+ end
21
+
22
+ def self.kb_page_size
23
+ @size ||= `getconf PAGE_SIZE`.to_f / 1024.0 rescue 4.0
24
+ end
25
+
26
+ protected
27
+
28
+ def pgrp_id
29
+ Process.getpgrp
30
+ end
31
+
32
+ def pids_cmd
33
+ `ps -o pid,pgid -e | grep -w "#{pgrp_id}"`
34
+ end
35
+
36
+ def pids
37
+ @pids = pids_cmd.split(/\s+/).uniq rescue [Process.pid.to_s]
38
+ @pids = [Process.pid.to_s] if @pids.empty?
39
+ @pids
40
+ end
41
+
42
+ def get_memory_by_pid pid
43
+ return 0.0 if pid.empty?
44
+ @pid = pid
45
+ poll_memory rescue 0.0
46
+ end
47
+
48
+ def poll_memory
49
+ ps_float('rss') / 1024.0
50
+ end
51
+
52
+ def ps_float keyword
53
+ `ps -o #{keyword}= -p #{pid}`.to_f
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -13,6 +13,7 @@ require 'one_apm/transaction/transaction_sample'
13
13
  require 'one_apm/transaction/transaction_analysis'
14
14
 
15
15
  require 'one_apm/rack/developer_mode/helper'
16
+ require 'one_apm/collector/support/shell_poller'
16
17
 
17
18
  module OneApm
18
19
  module Rack
@@ -291,7 +292,7 @@ module OneApm
291
292
  ERB.new(File.read(File.join(VIEW_PATH, 'oneapm', view.to_s + '.html.erb')), nil, nil, 'frobnitz').result(binding)
292
293
  end
293
294
 
294
- def content_tag(tag, contents, opts={})
295
+ def content_tag(tag, contents, opts={})
295
296
  opt_values = opts.map {|k, v| "#{k}=\"#{v}\"" }.join(' ')
296
297
  "<#{tag} #{opt_values}>#{contents}</#{tag}>"
297
298
  end
@@ -358,7 +359,9 @@ module OneApm
358
359
 
359
360
  def current_memory_used
360
361
  @memory_sampler ||= OneApm::Collector::Samplers::MemorySampler.new
361
- @memory_sampler.sampler.get_sample
362
+ @shell_poller ||= OneApm::Collector::ShellPoller.new
363
+ @memory_sampler.set_poller(@shell_poller)
364
+ @memory_sampler.get_sample
362
365
  end
363
366
 
364
367
  end
@@ -5,10 +5,11 @@ module OneApm
5
5
 
6
6
  MAJOR = 1
7
7
  MINOR = 3
8
- TINY = 3
8
+ TINY = 4
9
+ TAG = 'rc1'
9
10
 
10
11
 
11
- STRING = [MAJOR, MINOR, TINY].compact.join('.')
12
+ STRING = [MAJOR, MINOR, TINY, TAG].compact.join('.')
12
13
 
13
14
  end
14
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oneapm_rpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - oneapm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-23 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -295,7 +295,10 @@ files:
295
295
  - lib/one_apm/collector/stats_engine/metric_stats.rb
296
296
  - lib/one_apm/collector/stats_engine/stats_hash.rb
297
297
  - lib/one_apm/collector/support/forked_process_service.rb
298
+ - lib/one_apm/collector/support/jruby_poller.rb
299
+ - lib/one_apm/collector/support/proc_poller.rb
298
300
  - lib/one_apm/collector/support/sampler_collection.rb
301
+ - lib/one_apm/collector/support/shell_poller.rb
299
302
  - lib/one_apm/configuration.rb
300
303
  - lib/one_apm/configuration/default_source.rb
301
304
  - lib/one_apm/configuration/environment_source.rb