Module: NewRelic::DataSerialization::ClassMethods

Included in:
NewRelic::DataSerialization
Defined in:
lib/new_relic/data_serialization.rb

Instance Method Summary collapse

Instance Method Details

#pid_too_old?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/new_relic/data_serialization.rb', line 44

def pid_too_old?
  return true unless File.exists?(pid_file_path)
  age = (Time.now.to_i - File.mtime(pid_file_path).to_i)
  NewRelic::Control.instance.log.debug("Pid was #{age} seconds old, sending data") if age > 60
  age > 60
end

#read_and_write_to_fileObject

A combined locked read/write from the store file - reduces contention by not acquiring the lock and file handle twice



27
28
29
30
31
32
33
34
35
36
# File 'lib/new_relic/data_serialization.rb', line 27

def read_and_write_to_file
  with_locked_store do |f|
    result = (yield get_data_from_file(f))
    f.rewind
    f.truncate(0)
    write_contents_nonblockingly(f, dump(result)) if result
  end
rescue Errno::ENOENT => e
  NewRelic::Control.instance.log.warn(e.message)
end

#should_send_data?Boolean

Check whether the store is too large, too old, or the pid file is too old. If so, we should send the data right away. If not, we presumably store it for later sending (handled elsewhere)

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/new_relic/data_serialization.rb', line 15

def should_send_data?
  NewRelic::Control.instance.disable_serialization? || store_too_large? ||
    store_too_old? || pid_too_old? ||
    NewRelic::LanguageSupport.using_version?('1.8.6')
rescue => e
  NewRelic::Control.instance.disable_serialization = true
  NewRelic::Control.instance.log.warn("Disabling serialization: #{e.message}")
  true
end

#store_too_large?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
# File 'lib/new_relic/data_serialization.rb', line 58

def store_too_large?
  return true unless File.exists?(file_path)
  size = File.size(file_path) > max_size
  NewRelic::Control.instance.log.debug("Store was oversize, sending data") if size
  size
end

#store_too_old?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
# File 'lib/new_relic/data_serialization.rb', line 51

def store_too_old?
  return true unless File.exists?(file_path)
  age = (Time.now.to_i - File.mtime(file_path).to_i)
  NewRelic::Control.instance.log.debug("Store was #{age} seconds old, sending data") if age > 60
  age > 50
end

#update_last_sent!Object

touches the age file that determines whether we should send data now or not



40
41
42
# File 'lib/new_relic/data_serialization.rb', line 40

def update_last_sent!
  FileUtils.touch(pid_file_path)
end