Docker使用Fluentd登录,我无法解析我想要的内容
我正在尝试解析docker容器中的日志。我使用的是docker fluentd驱动程序,无法准确提取我想要的内容。在第一次尝试中,我的fluentd配置如下:Docker使用Fluentd登录,我无法解析我想要的内容,docker,logging,fluentd,Docker,Logging,Fluentd,我正在尝试解析docker容器中的日志。我使用的是docker fluentd驱动程序,无法准确提取我想要的内容。在第一次尝试中,我的fluentd配置如下: <source> @type forward port 24224 bind 0.0.0.0 </source> <match docker.mycontainer*> @type copy <store> @type elasticsearch host
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<match docker.mycontainer*>
@type copy
<store>
@type elasticsearch
host 192.168.0.35
port 9200
logstash_format true
logstash_prefix mycontainer-
logstash_dateformat %Y%m
include_tag_key true
type_name access_log
tag_key @log_name
flush_interval 1s
</store>
<store>
@type stdout
</store>
</match>
在这种情况下,正如您所看到的,我获得了有关容器(容器id、容器名称)和日志行的信息。问题是时间,我需要保存日志行中的时间,因此我将Fluentd conf更改为:
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<filter docker.mycontainer*>
@type onekeyparse
in_format ^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3})(?: )(?<log>.*)$
in_key log
out_record_keys time,log
out_record_types time,string
</filter>
<match docker.mycontainer*>
@type copy
<store>
@type elasticsearch
host 192.168.0.35
port 9200
index_name mycontainer-
logstash_format true
logstash_prefix mycontainer
logstash_dateformat %Y%m
include_tag_key true
type_name access_log
tag_key @log_name
flush_interval 1s
</store>
<store>
@type stdout
</store>
</match>
现在,我没有像第一个案例(container\u id,container\u name)那样获得容器信息。有人知道如何获取有关容器的信息,并获得时间和登录分开的密钥吗
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<filter docker.mycontainer*>
@type onekeyparse
in_format ^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3})(?: )(?<log>.*)$
in_key log
out_record_keys time,log
out_record_types time,string
</filter>
<match docker.mycontainer*>
@type copy
<store>
@type elasticsearch
host 192.168.0.35
port 9200
index_name mycontainer-
logstash_format true
logstash_prefix mycontainer
logstash_dateformat %Y%m
include_tag_key true
type_name access_log
tag_key @log_name
flush_interval 1s
</store>
<store>
@type stdout
</store>
</match>
{
"_index": "myindex-202105",
"_type": "_doc",
"_id": "CJS-wnkBUd7624sx3VKO",
"_version": 1,
"_score": 1,
"_source": {
"time": "2021-05-31 15:52:50.250",
"log": "INFO 1 LOG LOG LOG LOG LOG LOG",
"@timestamp": "2021-05-31T14:05:58.000000000+00:00",
"@log_name": "docker.mycontainer"
},
"fields": {
"@timestamp": [
"2021-05-31T14:05:58.000Z"
]
}
}