elasticsearch - 如何使用 Fluentd 将 json-log 发送到 Elasticsearch
问题描述
我的计算机上安装了 Windows 10,并且在 docker 容器中运行了 Elasticsearch/Kibana。
我正在尝试使用 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 或其他东西?
解决方案
知道了!这是正确的 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>
推荐阅读
- kubernetes - 如何使用 argoCD 部署存储在 AWS ECR 中的 helm 图表
- python - 为什么我的函数返回 HTTP 错误 301?
- java - 使用java从neo4j获取所有图形数据,包括节点和关系到hashmap
- random - 如果提供了 FrequencyWeights(),则 StatsBase.sample() 无法在不替换的情况下绘制
- settings - 未安装设置架构“com.github.Suzie97.epoch”
- javascript - 如何将连续的图像流实时转换为 h264 流
- python - 添加包含部分行的新列时如何解决 SettingWithCopyWarning 错误?
- r - 使用 prcomp 对 R 进行 PCA(主成分分析)的问题
- dolphindb - 如何取表中前 5% 记录的平均值
- flutter - Webview中点击事件的颤振处理