NGINX,从http头中提取url路径

NGINX,从http头中提取url路径,nginx,webserver,devops,nginx-config,datadog,Nginx,Webserver,Devops,Nginx Config,Datadog,因此,我将我的Nginx访问日志发送到Datadog(一个APM解决方案) 我的日志格式如下所示 log_format json_custom '{' '"http.version":"$request",' '"http.status_code":$status,' '"http.method":"$request_method",' '"http.referer":"$http_referer",' '"http.us

因此,我将我的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"'
    '}';
http://example.com/foo/bar 
我可以从
referer
字段中提取url,如下所示

  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"'
    '}';
http://example.com/foo/bar 
不过我只想要
/foo/bar
。这是我必须以
log\u格式修改的内容吗

我在datadog文档中看到了一个示例,其中可以提取url路径属性,但没有示例配置


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


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


如果您的日志应用了“source:nginx”(在日志传送程序中配置),那么您就已经有了一个现成的nginx处理管道,Datadog可以用来构造标准nginx语法日志。您可以克隆它,然后在那里添加新的url解析器。或者,如果您的语法与标准语法相似,您可以修改它们的默认建议解析器(在克隆管道中)。在任何情况下,都值得一看这个默认管道,从中获得一些灵感,为url解析之外的其他有价值的事情提供帮助

使用
map
regex
如本例所示:应该完成这项工作