newrelic_rpm如何将数据发送到New Relic服务器?

时间:2011-11-08 08:33:00

标签: newrelic

我们在生产环境中使用newrelic_rpm。

我将日志级别更改为debug。 每当代理向服务器发送数据时,它都会显示:

[11/08/11 13:58:09 +0530 mubarocks.local (788)] DEBUG : Sending data to New Relic Service
[11/08/11 13:58:09 +0530 mubarocks.local (788)] DEBUG : Spool file empty.
[11/08/11 13:58:09 +0530 mubarocks.local (788)] DEBUG : Connect to newrelic.com:80/agent_listener/8/.../metric_data?run_id=327878253
[11/08/11 13:58:09 +0530 mubarocks.local (788)] DEBUG : Http Connection opened to 204.93.223.142:80
[11/08/11 13:58:10 +0530 mubarocks.local (788)] DEBUG : Uncompressed content returned
[11/08/11 13:58:10 +0530 mubarocks.local (788)] DEBUG : 2011-11-08 13:58:09 +0530: sent 8 timeslices (327878253) in 0.660168 seconds

它不会显示正在发送的实际数据。

如何记录发送到服务器的实际数据?

如何调试数据格式?

2 个答案:

答案 0 :(得分:4)

跟踪调用堆栈,您需要查看gem的来源。

 lib/new_relic/agent/agent.rb

数据实际上是由Net::HTTP::Post

发送的
 def send_request(opts)
   request = Net::HTTP::Post.new(opts[:uri],
     'CONTENT-ENCODING' => opts[:encoding],
     'HOST' => opts[:collector].name)
   request.content_type = "application/octet-stream"
   request.body = opts[:data]

   log.debug "Connect to #{opts[:collector]}#{opts[:uri]}"

   ...

但是,到这里数据到达时,它就被压缩了。

def invoke_remote(method, *args)
  #determines whether to zip the data or send plain
  post_data, encoding = compress_data(args)

  response = send_request({
    :uri => remote_method_uri(method),
    :encoding => encoding,
    :collector => collector,
    :data => post_data})

  ...

所以compress_data是个好看的地方。

因此,我们添加一个初始化程序,在发送数据时添加日志语句。

module NewRelic
  module Agent
    class Agent
      def compress_data_with_debug(object)
        Rails.logger.debug("Newrelic Data: #{object.inspect}")

        compress_data_without_debug(object)
      end

      alias_method_chain :compress_data, :debug
    end
  end
end

这应该让你在某个地方开始。

答案 1 :(得分:0)

New Relic现在支持audit log,允许应用程序传输的所有数据以人类可读的格式记录。

相关问题