【问题标题】:NGINX, Extracting url path from http headerNGINX,从http标头中提取url路径
【发布时间】:2020-06-13 08:48:51
【问题描述】:

所以我将我的 Nginx 访问日志发送到 Datadog(APM 解决方案)。

我的日志格式是这样的

  log_format json_custom 
    '{'
      '"http.version":"$request",'
      '"http.status_code":$status,'
      '"http.method":"$request_method",'
      '"http.referer":"$http_referer",'
      '"http.useragent":"$http_user_agent",'
      '"time_local":"$time_local",'
      '"remote_addr":"$remote_addr",'
      '"remote_user":"$remote_user",'
      '"body_bytes_sent":"$body_bytes_sent",'
      '"request_time":$request_time,'
      '"response_content_type":"$sent_http_content_type",'
      '"X-Forwarded-For":"$proxy_add_x_forwarded_for",'
      '"custom_key":"custom_value"'
    '}';

我可以从 referrer 字段中提取 url,它看起来像这样

http://example.com/foo/bar 

我只想要/foo/bar。这是我必须在log_format 中修改的内容吗?

我从 datadog 文档中看到了一个示例,他们能够提取 url 路径属性,但没有示例配置。

【问题讨论】:

标签: nginx webserver devops nginx-config datadog


【解决方案1】:

如果您已经有一个包含 url 的属性,一个非常简单的方法是使用 processing pipelines 并将“url parser”类型的处理器添加到这些日志中。您只需插入包含 url 的属性和您希望包含其所有输出的属性路径(通常为http.url_details),然后所有新日志都会应用额外的 url 解析。

如果您的日志应用了“source:nginx”(在日志发送程序中配置),那么您将已经拥有 Datadog 用于构建标准 Nginx 语法日志的开箱即用的 Nginx 处理管道.您可以克隆它,然后在此处添加新的 url 解析器。或者,如果您的语法与标准语法相似,您只需修改其默认建议的解析器(在克隆管道中)。在任何情况下,值得查看默认管道以获取除 url 解析之外的其他有价值的事情的灵感。

【讨论】:

    【解决方案2】:

    Datadog 可以通过其管道过滤功能处理日志

    https://docs.datadoghq.com/logs/processing/pipelines/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 2020-04-04
      • 1970-01-01
      • 2016-03-04
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多