通过google-fluentd使Docker容器中的JSON日志字段在GCP日志中可用

问题描述

首先让我解释一下设置/系统:

我有一台通过GCP Compute Engine运行的虚拟Ubuntu 18.04计算机。我已遵循GCP文档,并通过apt-get进入了installed the structured logging agent

在这台机器上,我有一个运行在Docker容器中的golang Web服务,该容器使用Logrus发出如下所示的日志:

{"message":"some interesting thing occured","severity":"INFO","timestamp":{"seconds":1599668988,"nanos":567943787}}

为了将这些日志从机器/容器发送到GCP日志,我创建了一个新的流畅的配置文件/etc/google-fluentd/config.d/docker.conf,名为described in fluentd documentation

<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

<filter docker.**>
  @type parser
  format json
  key_name log
  reserve_data true
</filter>

以及Docker守护进程,该容器发送日志以使该容器流畅,如described in Docker documentationdocker run --log-driver=fluentd ...

我面临的局限性是日志确实到达了GCP Logs Viewer中,但是我的服务字段没有正确解析,因此我无法按严重性排序。到达GCP的日志如下:

{
  "insertId": "xxxxxxxxxxxxxxxx","jsonPayload": {
    "stream": "stderr","log": "{\"message\":\"some interesting thing occured\",\"severity\":\"INFO\",\"timestamp\":{\"seconds\":1599668988,\"nanos\":567943787}}\n"
  },"resource": {
    "type": "gce_instance","labels": {
      "instance_id": "22222222222222222","project_id": "xxxxxxx-333333","zone": "us-east1-b"
    }
  },"timestamp": "2020-09-09T16:29:48.568042072Z","labels": {
    "compute.googleapis.com/resource_name": "xxxxxxxx"
  },"logName": "some/folder/logs/docker.var.lib.docker.containers.7ec67d861ea6d2dbf20db456dad4e7efc43b91a498580dda325f76170b502509.7ec67d861ea6d2dbf20db456dad4e7efc43b91a498580dda325f76170b502509-json.log","receiveTimestamp": "2020-09-09T16:33:29.159377657Z"
}

我需要采取哪些其他步骤,以使GCP Logs Viewer能够理解日志?尽管我对fluentd的过滤器/解析器配置足够实现此目的,尤其是有关本节的内容。

  format json
  key_name log

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...