【问题标题】:Update mongo records with fluentd使用 fluentd 更新 mongo 记录
【发布时间】:2023-04-01 13:12:01
【问题描述】:

我们需要将我们的 nodejs 应用程序日志保存为 MongoDB 中的记录。 我们应该创建的大部分记录,但有些记录只需要更新。

我们想使用 Fluentd。我看到它可以选择将日志插入 mongo,但我找不到更新现有记录的方法。

有没有办法做到这一点?

这是我当前的 td-agent.conf(仍在开发中):

<match mongo.*>
  @type mongo
  host localhost
  port 27017
  database my-db

  # Set 'tag_mapped' if you want to use tag mapped mode.
  tag_mapped

  # If the tag is "mongo.foo", then the prefix "mongo." is removed.
  # The inserted collection name is "foo".
  remove_tag_prefix mongo.

  # This configuration is used if the tag is not found. The default is 'untagged'.
  collection misc
</match>

【问题讨论】:

  • 你能分享你的 fluent.conf 看看你在做什么以及可以做什么?
  • 我正在添加。请注意,它仍在开发中。

标签: node.js mongodb fluentd td-agent


【解决方案1】:

查看documentationcode的fluentd mongo插件,好像不支持update/upsert操作。

目前,它只执行insert_many操作。

get_collection(database, collection, @collection_options).insert_many(records)

https://github.com/fluent/fluent-plugin-mongo/blob/master/lib/fluent/plugin/out_mongo.rb#L265

其中一个选项是使用update_many(或批量更新插入)操作在此存储库上创建功能请求或拉取请求,但这需要您在每个文档插入中发送更新字段。


更新 - 任何替代工具?

我可以想到logstash,但即使它也打开了一堆功能请求以支持对 MongoDB 的更新/更新。

https://github.com/logstash-plugins/logstash-output-mongodb/issues/16

当您检查上述链接 cmets 时,建议您通常不希望执行更新操作。

https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying

我想说首先重新审视您更新日志方法的设计,否则创建一个可以执行更新操作的自定义应用程序(Java、NodeJS、Python 或 .NET Core)(替换 fluentd 或从 fluentd 传播到自定义应用程序到 mongodb)。

【讨论】:

  • 你有替代工具吗?
猜你喜欢
  • 2018-05-07
  • 1970-01-01
  • 2015-10-17
  • 1970-01-01
  • 1970-01-01
  • 2021-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多