【问题标题】:How to send json-log to Elasticsearch using Fluentd如何使用 Fluentd 将 json-log 发送到 Elasticsearch
【发布时间】:2021-10-22 08:29:14
【问题描述】:

我的计算机上安装了 Windows 10,并且 Elasticsearch/Kibana 在 docker 容器中运行。

我正在尝试使用 Fluentd 将我的应用程序生成的日志重定向到 Elasticsearch。这是 td-agent.conf 文件:

<source>
  @type tail
  path C:/Projects/log.json
  pos_file C:/Projects/log.json.pos
  tag *
  format json
  time_key @timestamp
</source>

<match **>
  @type elasticsearch
  logstash_format false
  host localhost
  port 9200
  index_name appname-api-*
  type_name fluentd
  flush_interval 1s
</match>

这是 appsettings 的一部分,我在其中指定了我想要 elasticsearch 格式的 json 文件:

  {
    "Name": "File",
    "Args": {
      "path": "c:/Projects/log.json",
      "formatter": "Serilog.Formatting.Elasticsearch.ElasticsearchJsonFormatter, Serilog.Formatting.Elasticsearch"
    }
  }

这是日志文件中的一行:

{"@timestamp":"2021-10-22T11:13:39.4325643+03:00","level":"Information","messageTemplate":"Now listening on: {address}","message":"Now listening on: \"http://localhost:5001\"","fields":{"address":"http://localhost:5001","SourceContext":"Microsoft.Hosting.Lifetime","MachineName":"MACHINENAME"}}

但它不起作用。我怀疑我的 td-agent.conf。可以举个例子吗?

或者切换到 Filebeat 或其他方式更容易?

【问题讨论】:

    标签: elasticsearch serilog fluentd


    【解决方案1】:

    知道了!这是正确的 td-agent.conf

    <system>
      log_level debug
    </system>
    
    <source>
      @type tail
      path C:/Projects/log.json
      pos_file C:/Projects/log.json.pos
      tag log_test
      emit_unmatched_lines true
    
      <parse>
        @type json
      </parse>
    </source>
    
    <match log_test>
      @type elasticsearch
      host localhost
      port 9200
      index_name appname-api-2021-10
      type_name _doc
      flush_interval 1s
    </match>
    

    【讨论】:

      猜你喜欢
      • 2022-07-07
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 2020-09-01
      • 1970-01-01
      相关资源
      最近更新 更多