Sha256: b6855866443e5cf45ff5d6c4d84488de95f1f9f61e3ab4e77641640c94c7f681

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

module NewRelic
  module Agent
    class PipeService
      attr_reader :channel_id, :buffer
      attr_accessor :request_timeout, :agent_id, :collector
      
      def initialize(channel_id)
        @channel_id = channel_id
        @collector = NewRelic::Control::Server.new(:name => 'parent',
                                                   :port => 0)
      end
      
      def connect(config)
        nil
      end

      def get_agent_commands
        []
      end

      def metric_data(last_harvest_time, now, unsent_timeslice_data)
        write_to_pipe(:stats => hash_from_metric_data(unsent_timeslice_data))
        {}
      end

      def transaction_sample_data(transactions)
        write_to_pipe(:transaction_traces => transactions) if transactions
      end

      def error_data(errors)
        write_to_pipe(:error_traces => errors) if errors
      end

      def sql_trace_data(sql)
        write_to_pipe(:sql_traces => sql) if sql
      end
      
      def shutdown(time)
        write_to_pipe('EOF')
        NewRelic::Agent::PipeChannelManager.channels[@channel_id].close
      end

      # Invokes the block it is passed.  This is used to implement HTTP
      # keep-alive in the NewRelicService, and is a required interface for any
      # Service class.
      def session
        yield
      end
      
      private

      def hash_from_metric_data(metric_data)
        metric_hash = {}
        metric_data.each do |metric_entry|
          metric_hash[metric_entry.metric_spec] = metric_entry
        end
        metric_hash
      end

      def write_to_pipe(data)
        NewRelic::Agent::PipeChannelManager.channels[@channel_id].write(data)
      rescue => e
        NewRelic::Agent.logger.error("#{e.message}: Unable to send data to parent process, please see https://newrelic.com/docs/ruby/resque-instrumentation for more information.")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
newrelic_rpm-3.5.7.59 lib/new_relic/agent/pipe_service.rb
newrelic_rpm-3.5.7.59.beta lib/new_relic/agent/pipe_service.rb
newrelic_rpm-3.5.7.58.beta lib/new_relic/agent/pipe_service.rb
wd_newrelic_rpm-3.5.6 lib/new_relic/agent/pipe_service.rb
newrelic_rpm-3.5.7.57.beta lib/new_relic/agent/pipe_service.rb
newrelic_rpm-3.5.6.55 lib/new_relic/agent/pipe_service.rb