Fluent-bit -在Elasticsearch中将json日志拆分为结构化字段

kse8i1jr  于 7个月前  发布在  ElasticSearch
关注(0)|答案(3)|浏览(56)

我试图在Fluent-bit config中找到一种方法来告诉/强制ES存储纯JSON格式的日志(下面的log位来自docker stdout/stderror*)-请参阅底部的图像以获得更好的解释。例如,除了(或者沿着)将日志存储为log字段下的普通JSON条目,我想单独存储每个属性,如red所示。
过滤器和解析器的文档真的很差,不清楚。最重要的是,forward输入没有“解析器”选项。我尝试了json/docker/regex解析器,但没有运气。如果我必须使用正则表达式,我的正则表达式是here。目前使用ES(7.1),Fluent-bit(1.1.3)和Kibana(7.1)-而不是Kubernetes。
如果有人能给我一个例子或给予一个,我将不胜感激。
谢谢

{
  "_index": "hello",
  "_type": "logs",
  "_id": "T631e2sBChSKEuJw-HO4",
  "_version": 1,
  "_score": null,
  "_source": {
    "@timestamp": "2019-06-21T21:34:02.000Z",
    "tag": "php",
    "container_id": "53154cf4d4e8d7ecf31bdb6bc4a25fdf2f37156edc6b859ba0ddfa9c0ab1715b",
    "container_name": "/hello_php_1",
    "source": "stderr",
    "log": "{\"time_local\":\"2019-06-21T21:34:02+0000\",\"client_ip\":\"-\",\"remote_addr\":\"192.168.192.3\",\"remote_user\":\"\",\"request\":\"GET / HTTP/1.1\",\"status\":\"200\",\"body_bytes_sent\":\"0\",\"request_time\":\"0.001\",\"http_referrer\":\"-\",\"http_user_agent\":\"curl/7.38.0\",\"request_id\":\"91835d61520d289952b7e9b8f658e64f\"}"
  },
  "fields": {
    "@timestamp": [
      "2019-06-21T21:34:02.000Z"
    ]
  },
  "sort": [
    1561152842000
  ]
}

字符串
谢谢
联系我们

[SERVICE]
    Flush        5
    Daemon       Off
    Log_Level    debug
    Parsers_File parsers.conf

[INPUT]
    Name   forward
    Listen 0.0.0.0
    Port   24224

[OUTPUT]
    Name  es
    Match hello_*
    Host  elasticsearch
    Port  9200
    Index hello
    Type  logs
    Include_Tag_Key On
    Tag_Key tag


x1c 0d1x的数据

bvjxkvbb

bvjxkvbb1#

解决方案如下。

[SERVICE]
    Flush        5
    Daemon       Off
    Log_Level    debug
    Parsers_File parsers.conf

[INPUT]
    Name         forward
    storage.type filesystem
    Listen       my_fluent_bit_service
    Port         24224

[FILTER]
    Name         parser
    Parser       docker
    Match        hello_*
    Key_Name     log
    Reserve_Data On
    Preserve_Key On

[OUTPUT]
    Name            es
    Host            my_elasticsearch_service
    Port            9200
    Match           hello_*
    Index           hello
    Type            logs
    Include_Tag_Key On
    Tag_Key         tag

个字符

myzjeezk

myzjeezk2#

当Firelens与aws-for-fluent-bit图像一起使用时,请考虑更一般的用例,其中消息最终作为顶级密钥log,如下所示:

{
    "log": "{\"time_local\":\"2019-06-21T21:34:02+0000\",\"client_ip\":\"-\",\"remote_addr\":\"192.168.192.3\",\"remote_user\":\"\",\"request\":\"GET / HTTP/1.1\",\"status\":\"200\",\"body_bytes_sent\":\"0\",\"request_time\":\"0.001\",\"http_referrer\":\"-\",\"http_user_agent\":\"curl/7.38.0\",\"request_id\":\"91835d61520d289952b7e9b8f658e64f\"}"
}

字符串
this official AWS example之后,请注意JSON parser already exists in the image,可以这样使用:

"firelensConfiguration": {
    "type": "fluentbit",
    "options": {
        "config-file-type": "file",
        "config-file-value": "/fluent-bit/configs/parse-json.conf"
    }
}

或者可以通过环境变量调用:

"environment": [
    {
        "name": "aws_fluent_bit_init_file_1",
        "value": "/fluent-bit/configs/parse-json.conf"
    }
]


测试结果:

{
    "time_local": "2019-06-21T21:34:02+0000",
    "client_ip": "-",
    "remote_addr": "192.168.192.3",
    "remote_user": "",
    "request": "GET / HTTP/1.1",
    "status": "200",
    "body_bytes_sent": "0",
    "request_time": "0.001",
    "http_referrer": "-",
    "http_user_agent": "curl/7.38.0",
    "request_id": "91835d61520d289952b7e9b8f658e64f"
}

voj3qocg

voj3qocg3#

您可以使用Fluent Bit Nest过滤器来实现此目的,请参阅以下文档:
https://docs.fluentbit.io/manual/filter/nest

相关问题