tracebin 0.0.10 → 0.0.11

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d94ffa099d279c476c327437396669eaa91e0f46
4
- data.tar.gz: af463513780cde0a9f5b15c16f6ad81946485733
3
+ metadata.gz: e823382bbf674934553df737b9a52652f9081a14
4
+ data.tar.gz: ab4ac41cead343e9d8068c925113c241340e15a7
5
5
  SHA512:
6
- metadata.gz: bb95a49c5155ce797593b1d49e7067ef0bd87add0c573787f78a123aa77f77a0356907794eee4930a60cb5927d80822e243d5f5fb8b1948bff265b3c7b6a66e9
7
- data.tar.gz: 789d333045a7620c5e7858f3ef4fcc1771da2956bbf1c2dd766c61b4662925e9d228c1df95a115cece2d2ef155f5887b44616eb795e0bab2321c5a33031e471b
6
+ metadata.gz: cdb4d07940b6895511a4866ca1e140502f463f984c074b82524930e493042b1020a7edf02a75e9ca79d21f5da4a53c34eb458b73860266ee0fd3ad049a58439d
7
+ data.tar.gz: b6d60fd08949816eb22f5273f415d4dfb04266ce25b4e7829bfa00799624690d8c70cd45bdbac37923007f297a3bc02c9af6e769f11ab0111fe15e2e8003f8a4
@@ -4,6 +4,7 @@ module Tracebin
4
4
  log_level: 'info',
5
5
  host: 'https://traceb.in',
6
6
  report_path: 'reports',
7
+ enable_ssl: true,
7
8
  ignored_paths: [],
8
9
  enabled: true
9
10
  }.freeze
@@ -21,9 +21,9 @@ module Tracebin
21
21
  def data_hash
22
22
  {
23
23
  event_type: type,
24
- start: event[1],
25
- stop: event[2],
26
- duration: to_milliseconds(event[2] - event[1]),
24
+ start: time_to_string(event[1]),
25
+ stop: time_to_string(event[2]),
26
+ duration: milliseconds_between(event[2], event[1]),
27
27
  data: select_data || event.last
28
28
  }
29
29
  end
@@ -3,5 +3,32 @@ module Tracebin
3
3
  def to_milliseconds(time)
4
4
  time.to_f * 1000
5
5
  end
6
+
7
+ def time_to_string(time)
8
+ time.is_a?(String) ? time : time.iso8601(6)
9
+ end
10
+
11
+ def timestamp_string
12
+ Time.now.iso8601 6
13
+ end
14
+
15
+ def deserialize_time_string(str)
16
+ Time.parse str
17
+ end
18
+
19
+ def milliseconds_between(time1, time2)
20
+ time1 = deserialize_time_string(time1) if time1.is_a?(String)
21
+ time2 = deserialize_time_string(time2) if time2.is_a?(String)
22
+
23
+ to_milliseconds(time1 - time2).abs
24
+ end
25
+ end
26
+ end
27
+
28
+ module Tracebin
29
+ class PatchHelper
30
+ class << self
31
+ include ::Tracebin::Helpers
32
+ end
6
33
  end
7
34
  end
@@ -41,6 +41,8 @@ module Tracebin
41
41
  def fetch_endpoint_name(env)
42
42
  if controller = env['action_controller.instance']
43
43
  "#{controller.class}##{controller.params['action']}"
44
+ elsif route = env['sinatra.route']
45
+ route
44
46
  else
45
47
  'RackTransaction'
46
48
  end
@@ -13,11 +13,11 @@
13
13
  end
14
14
 
15
15
  if layout
16
- start_time = Time.now
16
+ start_time = ::Tracebin::PatchHelper.timestamp_string
17
17
 
18
18
  result = render_with_layout_without_tracebin(path, locals, *args, &block)
19
19
 
20
- end_time = Time.now
20
+ end_time = ::Tracebin::PatchHelper.timestamp_string
21
21
 
22
22
  event_data = [
23
23
  'render_layout.action_view',
@@ -2,9 +2,9 @@
2
2
  alias_method :query_without_tracebin, :query
3
3
 
4
4
  def query(*args, &block)
5
- start_time = Time.now
5
+ start_time = ::Tracebin::PatchHelper.timestamp_string
6
6
  result = query_without_tracebin(*args, &block)
7
- end_time = Time.now
7
+ end_time = ::Tracebin::PatchHelper.timestamp_string
8
8
 
9
9
  event_data = [
10
10
  'sql.mysql2_query',
@@ -3,9 +3,9 @@
3
3
  alias_method :exec_params_without_tracebin, :exec_params
4
4
 
5
5
  def exec_params(*args, &block)
6
- start_time = Time.now
6
+ start_time = ::Tracebin::PatchHelper.timestamp_string
7
7
  result = exec_params_without_tracebin(*args, &block)
8
- end_time = Time.now
8
+ end_time = ::Tracebin::PatchHelper.timestamp_string
9
9
 
10
10
  event_data = [
11
11
  'sql.postgres_exec',
@@ -22,9 +22,9 @@
22
22
  end
23
23
 
24
24
  def exec(*args, &block)
25
- start_time = Time.now
25
+ start_time = ::Tracebin::PatchHelper.timestamp_string
26
26
  result = exec_without_tracebin(*args, &block)
27
- end_time = Time.now
27
+ end_time = ::Tracebin::PatchHelper.timestamp_string
28
28
 
29
29
  event_data = [
30
30
  'sql.postgres_exec',
@@ -2,16 +2,18 @@
2
2
  alias_method :dispatch_without_tracebin!, :dispatch!
3
3
 
4
4
  def dispatch!(*args, &block)
5
- start_time = Time.now
5
+ start_time = ::Tracebin::PatchHelper.timestamp_string
6
6
  result = dispatch_without_tracebin!(*args, *block)
7
- end_time = Time.now
7
+ end_time = ::Tracebin::PatchHelper.timestamp_string
8
8
  route = env['sinatra.route']
9
9
 
10
10
  event_data = [
11
- 'sinatra.route_exec',
11
+ 'sinatra.route',
12
12
  start_time,
13
13
  end_time,
14
- route
14
+ {
15
+ endpoint: route
16
+ }
15
17
  ]
16
18
 
17
19
  ::Tracebin::Patches.handle_event :sinatra, event_data
@@ -1,4 +1,3 @@
1
- require 'net/https'
2
1
  require 'json'
3
2
  require 'concurrent'
4
3
 
@@ -11,6 +10,12 @@ module Tracebin
11
10
  @config = config
12
11
  @storage = storage
13
12
 
13
+ if config.enable_ssl
14
+ require 'net/https'
15
+ else
16
+ require 'net/http'
17
+ end
18
+
14
19
  host = Tracebin::Agent.config.host
15
20
  path = Tracebin::Agent.config.report_path
16
21
  @uri = URI("#{host}/#{path}")
@@ -44,8 +49,11 @@ module Tracebin
44
49
  logger.info "TRACEBIN: Sending #{payload.length} samples to: #{@uri}"
45
50
 
46
51
  http = Net::HTTP.new @uri.host, @uri.port
47
- http.use_ssl = true
48
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52
+
53
+ if config.enable_ssl
54
+ http.use_ssl = true
55
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
+ end
49
57
 
50
58
  body = {
51
59
  bin_id: @bin_id,
@@ -1,10 +1,12 @@
1
1
  module Tracebin
2
2
  class SystemHealthSample
3
+ include ::Tracebin::Helpers
4
+
3
5
  DATA_TYPE = 'system_health_sample'.freeze
4
6
 
5
7
  def initialize(options = {})
6
8
  @process = options[:process] || :web
7
- @sampled_at = Time.new
9
+ @sampled_at = timestamp_string
8
10
  @metrics = sample_metrics
9
11
  end
10
12
 
@@ -139,9 +141,11 @@ module Tracebin
139
141
  info[:processor_count] = get_sysctl_value('hw.packages').to_i
140
142
  info[:core_count] = get_sysctl_value('hw.physicalcpu_max').to_i,
141
143
  info[:logical_cpu_count] = get_sysctl_value('hw.logicalcpu_max').to_i
144
+ info[:usage] = get_darwin_cpu_usage
142
145
  elsif linux?
143
146
  proc_string = read_proc('/proc/cpuinfo')
144
147
  info = parse_proc_cpuinfo_string(proc_string)
148
+ info[:usage] = get_linux_cpu_usage
145
149
  end
146
150
  info
147
151
  end
@@ -183,5 +187,24 @@ module Tracebin
183
187
  logical_cpu_count: threads.count
184
188
  }
185
189
  end
190
+
191
+ def get_darwin_cpu_usage
192
+ iostat = `iostat 2>/dev/null`.split(/\n+/).map do |line|
193
+ line.strip.split(/\s+/)
194
+ end
195
+ cpu_idx = iostat[0].index('cpu') * 3
196
+ user, sys, idle = iostat[2].map(&:to_f)[cpu_idx..cpu_idx + 2]
197
+
198
+ (user + sys) / (user + sys + idle)
199
+ end
200
+
201
+ def get_linux_cpu_usage
202
+ proc_data = File.readlines('/proc/stat').grep(/^cpu /).first.split(" ")
203
+
204
+ usage = proc_data[1].to_i + proc_data[2].to_i + proc_data[3].to_i
205
+ total = usage + proc_data[4].to_i
206
+
207
+ usage.to_f / total.to_f
208
+ end
186
209
  end
187
210
  end
@@ -2,6 +2,10 @@ require 'tracebin/recorder'
2
2
  require 'tracebin/helpers'
3
3
 
4
4
  module Tracebin
5
+ ##
6
+ # This is the timer for a top-level transaction. Transactions include
7
+ # request/response cycles, as well as background jobs. Background jobs
8
+ # subclass this class and overwrite the +#transaction_type+ method.
5
9
  class Timer
6
10
  include ::Tracebin::Helpers
7
11
 
@@ -15,14 +19,14 @@ module Tracebin
15
19
  end
16
20
 
17
21
  def start!
18
- @start_time = Time.now
22
+ @start_time = timestamp_string
19
23
  Recorder.start_recording
20
24
  end
21
25
 
22
26
  def stop!
23
27
  collect_events
24
28
  Recorder.stop_recording
25
- @stop_time = Time.now
29
+ @stop_time = timestamp_string
26
30
  end
27
31
 
28
32
  def payload
@@ -43,7 +47,7 @@ module Tracebin
43
47
  end
44
48
 
45
49
  def duration
46
- to_milliseconds @stop_time - @start_time
50
+ milliseconds_between @stop_time, @start_time
47
51
  end
48
52
 
49
53
  def transaction_type
@@ -1,3 +1,3 @@
1
1
  module Tracebin
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracebin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Guillen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby