如何在流利的弹性搜索消息中添加额外数据
How to add extra data to the messages going to elasticsearch in fluentd
我在我的机器上设置了 elasticsearch
和 fluentd
。我写了一个基本的配置文件,它正在监视一个日志文件并将日志发送到 elasticsearch
。下面是配置文件:
<source>
@type tail
path /home/user/log.json
pos_file /home/user/log.json.pos
format json
time_format %Y-%m-%d %H:%M:%S
tag first
</source>
<match *first*>
@type elasticsearch
hosts 192.168.60.118:9200
user <username>
password <password>
</match>
以下是 elasticsearch
收到的日志消息:
{
"_index": "fluentd",
"_type": "fluentd",
"_id": "2987",
"_version": 88,
"_score": null,
"_source": {
"DataNumber": "030",
"DataId": "MMX56",
"DataCount": 87,
"Status": "Done"
},
"fields": {
"Created": [
"2018-06-11T05:27:20.278Z"
]
},
"sort": [
1528694840278
]
}
对于上面的消息,我还想添加其他信息,例如生成此数据的 machine number
、floor number
和其他内容。我不能在生成这些日志的代码中硬编码这些细节。因此,我正在寻找一种方法将这些详细信息添加到 fluentd 配置文件中,以便每个发往 elasticsearch
的出站消息都附加 machine number
& floor number
.
谢谢
看看record:
<record>
hostname "#{Socket.gethostname}"
tag ${tag}
</record>
我在我的机器上设置了 elasticsearch
和 fluentd
。我写了一个基本的配置文件,它正在监视一个日志文件并将日志发送到 elasticsearch
。下面是配置文件:
<source>
@type tail
path /home/user/log.json
pos_file /home/user/log.json.pos
format json
time_format %Y-%m-%d %H:%M:%S
tag first
</source>
<match *first*>
@type elasticsearch
hosts 192.168.60.118:9200
user <username>
password <password>
</match>
以下是 elasticsearch
收到的日志消息:
{
"_index": "fluentd",
"_type": "fluentd",
"_id": "2987",
"_version": 88,
"_score": null,
"_source": {
"DataNumber": "030",
"DataId": "MMX56",
"DataCount": 87,
"Status": "Done"
},
"fields": {
"Created": [
"2018-06-11T05:27:20.278Z"
]
},
"sort": [
1528694840278
]
}
对于上面的消息,我还想添加其他信息,例如生成此数据的 machine number
、floor number
和其他内容。我不能在生成这些日志的代码中硬编码这些细节。因此,我正在寻找一种方法将这些详细信息添加到 fluentd 配置文件中,以便每个发往 elasticsearch
的出站消息都附加 machine number
& floor number
.
谢谢
看看record:
<record>
hostname "#{Socket.gethostname}"
tag ${tag}
</record>