Ric*_*ich 3 json elasticsearch fluentd kibana
我在 Stackoverflow 上看到了许多类似的问题,包括这个。但没有一个解决我的特殊问题。
该应用程序部署在 Kubernetes (v1.15) 集群中。我正在使用基于fluent/fluentd-docker-image GitHub 存储库的docker 镜像v1.9/armhf,修改为包含 elasticsearch 插件。Elasticsearch 和 Kibana 都是version 7.6.0.
日志将进入标准输出,如下所示:
{"Application":"customer","HTTPMethod":"GET","HostName":"","RemoteAddr":"10.244.4.154:51776","URLPath":"/customers","level":"info","msg":"HTTP request received","time":"2020-03-10T20:17:32Z"}
Run Code Online (Sandbox Code Playgroud)
在 Kibana 中,我看到了这样的事情:
{
"_index": "logstash-2020.03.10",
"_type": "_doc",
"_id": "p-UZxnABBcooPsDQMBy_",
"_version": 1,
"_score": null,
"_source": {
"log": "{\"Application\":\"customer\",\"HTTPMethod\":\"GET\",\"HostName\":\"\",\"RemoteAddr\":\"10.244.4.154:46160\",\"URLPath\":\"/customers\",\"level\":\"info\",\"msg\":\"HTTP request received\",\"time\":\"2020-03-10T20:18:18Z\"}\n",
"stream": "stdout",
"docker": {
"container_id": "cd1634b0ce410f3c89fe63f508fe6208396be87adf1f27fa9d47a01d81ff7904"
},
"kubernetes": {
Run Code Online (Sandbox Code Playgroud)
我期待看到从log:值中提取的 JSON有点像这样(缩写):
{
"_index": "logstash-2020.03.10",
...
"_source": {
"log": "...",
"Application":"customer",
"HTTPMethod":"GET",
"HostName":"",
"RemoteAddr":"10.244.4.154:46160",
"URLPath":"/customers",
"level":"info",
"msg":"HTTP request received",
"time":"2020-03-10T20:18:18Z",
"stream": "stdout",
"docker": {
"container_id": "cd1634b0ce410f3c89fe63f508fe6208396be87adf1f27fa9d47a01d81ff7904"
},
"kubernetes": {
Run Code Online (Sandbox Code Playgroud)
我的流畅配置是:
match fluent.**>
@type null
</match>
<source>
@type tail
path /var/log/containers/*.log
pos_file /var/log/fluentd-containers.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag kubernetes.*
format json
read_from_head true
</source>
<match kubernetes.var.log.containers.**fluentd**.log>
@type null
</match>
<match kubernetes.var.log.containers.**kube-system**.log>
@type null
</match>
<filter kubernetes.**>
@type kubernetes_metadata
</filter>
<match **>
@type elasticsearch
@id out_es
@log_level info
include_tag_key true
host "#{ENV['FLUENT_ELASTICSEARCH_HOST']}"
port "#{ENV['FLUENT_ELASTICSEARCH_PORT']}"
path "#{ENV['FLUENT_ELASTICSEARCH_PATH']}"
<format>
@type json
</format>
</match>
Run Code Online (Sandbox Code Playgroud)
我确定我错过了一些东西。任何人都可以指出我正确的方向吗?
谢谢,丰富
这个配置对我有用:
<source>
@type tail
path /var/log/containers/*.log,/var/log/containers/*.log
pos_file /opt/bitnami/fluentd/logs/buffers/fluentd-docker.pos
tag kubernetes.*
read_from_head true
<parse>
@type json
time_key time
time_format %iso8601
</parse>
</source>
<filter kubernetes.**>
@type parser
key_name "$.log"
hash_value_field "log"
reserve_data true
<parse>
@type json
</parse>
</filter>
<filter kubernetes.**>
@type kubernetes_metadata
</filter>
Run Code Online (Sandbox Code Playgroud)
确保编辑路径以使其与您的用例相匹配。
发生这种情况是因为 docker/var/log/containers/*.log将容器 STDOUT 作为字符串登录到 'log' 键下,因此要将这些 JSON 日志作为字符串放在那里,它们必须首先序列化为字符串。您需要做的是添加一个额外的步骤来解析“log”键下的这个字符串:
<filter kubernetes.**>
@type parser
key_name "$.log"
hash_value_field "log"
reserve_data true
<parse>
@type json
</parse>
</filter>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4395 次 |
| 最近记录: |