Module: NewRelic::DataSerialization::ClassMethods
- Included in:
- NewRelic::DataSerialization
- Defined in:
- lib/new_relic/data_serialization.rb
Instance Method Summary collapse
- #pid_too_old? ⇒ Boolean
-
#read_and_write_to_file ⇒ Object
A combined locked read/write from the store file - reduces contention by not acquiring the lock and file handle twice.
-
#should_send_data? ⇒ Boolean
Check whether the store is too large, too old, or the pid file is too old.
- #store_too_large? ⇒ Boolean
- #store_too_old? ⇒ Boolean
-
#update_last_sent! ⇒ Object
touches the age file that determines whether we should send data now or not.
Instance Method Details
#pid_too_old? ⇒ 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_file ⇒ Object
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.) 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)
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.}") true end |
#store_too_large? ⇒ 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
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 |