scout_apm 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b13f09a100d1842c8aa30d4b494907796b30dac4
4
- data.tar.gz: 94b7e8b9ce5bc0a884db7df223728fda3d475dd6
3
+ metadata.gz: b2f2ddadaf118058d788a7d39c15de73fb24c19d
4
+ data.tar.gz: 7c495ff3fda4aab68c3d31b543bc3d934df4ae83
5
5
  SHA512:
6
- metadata.gz: 2692fa9370afc2fd71ae1c8a6985a535174ce0607b048dc5ceb653149b3fb2dfe2fdf2411f25f36f58f3bbfa46fa49bb79cf0fa929e74d4d6028596c3ebfafad
7
- data.tar.gz: 5529282c94ea75dbfb6f6c7bab6b12634880f6e8942452a510db90d9eac09857f8843d1658c1d252c4eab1b3bad5463aca69113a13f2a28eed60f68a35d61f30
6
+ metadata.gz: f3378b43c95b66a8f33fd3f0af330ff73d00e6aa2fde247246b205697d809cd30f65ed73306e4db135bc25011e08aedac434233469945a3b73d0c2f8dfda0795
7
+ data.tar.gz: 56eea7c846a87ae932a758ca52dffd5b22287fb2852f36f9d267d374587cfa7c982c87d8bdd2c54f8b5bc5802754e2af1aa74e1a4e9f5b0a6742c182d8bf6b59
@@ -7,10 +7,17 @@ module ScoutApm
7
7
  end
8
8
 
9
9
  def run
10
- logger.info("Sending Startup Info: #{data.inspect}")
11
- payload = ScoutApm::Serializers::AppServerLoadSerializer.serialize(data)
12
- reporter = Reporter.new(:app_server_load)
13
- reporter.report(payload)
10
+ @thread = Thread.new do
11
+ begin
12
+ logger.info("Sending Startup Info: #{data.inspect}")
13
+ payload = ScoutApm::Serializers::AppServerLoadSerializer.serialize(data)
14
+ reporter = Reporter.new(:app_server_load)
15
+ reporter.report(payload)
16
+ logger.info("Finished sending Startup Info")
17
+ rescue => e
18
+ logger.debug("Failed Startup Info In Thread - #{e.message} \n\t#{e.backtrace.join("\t\n")}")
19
+ end
20
+ end
14
21
  rescue => e
15
22
  logger.debug("Failed Startup Info - #{e.message} \n\t#{e.backtrace.join("\t\n")}")
16
23
  end
@@ -3,9 +3,12 @@ module ScoutApm
3
3
  module Process
4
4
  class ProcessCpu
5
5
  attr_reader :logger
6
+ attr_reader :num_processors
7
+ attr_accessor :last_run, :last_utime, :last_stime
8
+
6
9
 
7
10
  def initialize(num_processors, logger)
8
- @num_processors = num_processors || 1
11
+ @num_processors = [num_processors, 1].compact.max
9
12
  @logger = logger
10
13
 
11
14
  t = ::Process.times
@@ -24,19 +27,31 @@ module ScoutApm
24
27
 
25
28
  def run
26
29
  res = nil
27
- now = Time.now
30
+
28
31
  t = ::Process.times
29
- if @last_run
30
- elapsed_time = now - @last_run
31
- if elapsed_time >= 1
32
- user_time_since_last_sample = t.utime - @last_utime
33
- system_time_since_last_sample = t.stime - @last_stime
34
- res = ((user_time_since_last_sample + system_time_since_last_sample)/(elapsed_time * @num_processors))*100
35
- end
36
- end
37
- @last_utime = t.utime
38
- @last_stime = t.stime
39
- @last_run = now
32
+ now = Time.now
33
+ utime = t.utime
34
+ stime = t.stime
35
+
36
+ wall_clock_elapsed = now - last_run
37
+
38
+ utime_elapsed = utime - last_utime
39
+ stime_elapsed = stime - last_stime
40
+ process_elapsed = utime_elapsed + stime_elapsed
41
+
42
+ # Normalized to # of processors
43
+ normalized_wall_clock_elapsed = wall_clock_elapsed * num_processors
44
+
45
+ # If somehow we run for 0 seconds between calls, don't try to divide by 0
46
+ res = if normalized_wall_clock_elapsed == 0
47
+ 0
48
+ else
49
+ ( process_elapsed / normalized_wall_clock_elapsed )*100
50
+ end
51
+
52
+ self.last_run = now
53
+ self.last_utime = t.utime
54
+ self.last_stime = t.stime
40
55
 
41
56
  logger.debug "#{human_name}: #{res.inspect} [#{Environment.instance.processors} CPU(s)]"
42
57
 
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes