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

发布于 2024-12-14 00:42:17 字数 782 浏览 1 评论 0原文

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

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

[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

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

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

如何调试数据格式?

We are using newrelic_rpm in production environment.

I changed the log level to debug.
Whenever agent sends data to servers it displays:

[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

It doesn't show actual data being sent.

How can I log actual data which is being sent to server?

How can I debug the data format?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

開玄 2024-12-21 00:42:17

追踪调用堆栈,需要查看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

这应该能让你从一个不错的地方开始。

Tracing the call stack, you need to look at the source of the gem.

 lib/new_relic/agent/agent.rb

The data is actually send by a 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]}"

   ...

But, by the point the data arrives here, it's compressed.

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})

  ...

So compress_data is a good place to look.

So lets add an initializer that adds log statements whenever the data is sent.

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

And that should get you somewhere decent to start with.

蔚蓝源自深海 2024-12-21 00:42:17

New Relic 现在支持 审核日志,使应用程序传输的所有数据都能以人类可读的格式记录。

New Relic now supports an audit log, enabling all data that is transmitted by the app to be logged in human-readable format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文