【发布时间】: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 路径属性,但没有示例配置。
【问题讨论】:
-
使用
map和regex就像在这个例子中:stackoverflow.com/a/12459673/5372462 应该做的工作
标签: nginx webserver devops nginx-config datadog