Rag*_*son 5 nginx google-kubernetes-engine google-cloud-stackdriver
我有一个基本的 nginx 部署,在 GKE 集群上运行,提供静态内容。我已按照此处的说明为集群配置了 Stackdriver 日志记录(我为现有集群启用了日志记录),并且还启用了此处解释的 Stackdriver Kubernetes 监控功能。日志记录本身似乎工作正常,因为我可以在 Stackdriver 中看到来自 nginx 的日志。
我正在尝试创建一些基于日志的指标,例如已完成的 2xx 请求的数量,但我在 Stackdriver 中的日志条目中获得的只是该字段textPayload
。据我了解,在集群上启用 Stackdriver Monitoring 会启动一些 Fluentd 代理(如果运行我可以看到这些代理kubectl get pods -n kube-system
),并且它们应该默认启用 nginx 日志解析器(根据此处的文档)。但是,Stackdriver 中显示的日志条目均不具有jsonPayload
结构化日志应有的字段。
我正在使用 nginx 的默认log_format
配置,并且我已经验证默认的 nginx 解析器能够解析我的应用程序正在写入的日志(我将默认的 Fluentd nginx 解析器插件正则表达式和日志条目从我的应用程序复制到此工具,它能够解析该条目)
我确信我一定错过了一些东西,但我不知道是什么。
编辑:
作为参考,这是我的 NGINX 日志格式:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经尝试过以下操作:
jsonPayload
字段,只有textPayload
。到目前为止,这些都没有解决这个问题。
在与 Google Cloud 支持联系后,我们能够针对此问题设计出解决方法,但根本原因仍然未知。
解决方法是将 NGINX 日志格式本身定义为 JSON 字符串。这将允许 Google-Fluentd 解析器将有效负载正确解析为 JSON 对象。这是迄今为止唯一对我有用的解决方案。
作为参考,我使用的日志格式是:
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request_method":"$request_method",'
'"request":"$request",'
'"status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent"'
'}';
access_log /var/log/nginx/access.log json_combined;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1699 次 |
最近记录: |