我们在云中有几个外部应用程序(IBM Bluemix),它将应用程序syslog记录在内部使用ELK堆栈的bluemix logmet服务中。批量上传日志消息到本地Elasticsearch
现在我们定期从云端下载日志并将其上传到本地的Elastic/Kibana实例中。这是因为如果我们想通过Kibana搜索相同的日志,将日志存储在云服务中会产生成本和额外的成本。本地弹性实例可以删除/刷新我们不需要的旧日志。
下载的日志将这个样子
{"instance_id_str":"0","source_id_str":"APP/PROC/WEB","app_name_str":"ABC","message":"Hello","type":"syslog","event_uuid":"474b78aa-6012-44f3-8692-09bd667c5822","origin_str":"rep","ALCH_TENANT_ID":"3213cd20-63cc-4592-b3ee-6a204769ce16","logmet_cluster":"topic3-elasticsearch_3","org_name_str":"123","@timestamp":"2017-09-29T02:30:15.598Z","message_type_str":"OUT","@version":"1","space_name_str":"prod","application_id_str":"3104b522-aba8-48e0-aef6-6291fc6f9250","ALCH_ACCOUNT_ID_str":"","org_id_str":"d728d5da-5346-4614-b092-e17be0f9b820","timestamp":"2017-09-29T02:30:15.598Z"}
{"instance_id_str":"0","source_id_str":"APP/PROC/WEB","app_name_str":"ABC","message":"EFG","type":"syslog","event_uuid":"d902dddb-afb7-4f55-b472-211f1d370837","origin_str":"rep","ALCH_TENANT_ID":"3213cd20-63cc-4592-b3ee-6a204769ce16","logmet_cluster":"topic3-elasticsearch_3","org_name_str":"123","@timestamp":"2017-09-29T02:30:28.636Z","message_type_str":"OUT","@version":"1","space_name_str":"prod","application_id_str":"dcd9f975-3be3-4451-a9db-6bed1d906ae8","ALCH_ACCOUNT_ID_str":"","org_id_str":"d728d5da-5346-4614-b092-e17be0f9b820","timestamp":"2017-09-29T02:30:28.636Z"}
我在我们当地elasticsearch创建一个索引作为
curl -XPUT 'localhost:9200/commslog?pretty' -H 'Content-Type: application/json' -d'
{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"logs" : {
"properties" : {
"instance_id_str" : { "type" : "text" },
"source_id_str" : { "type" : "text" },
"app_name_str" : { "type" : "text" },
"message" : { "type" : "text" },
"type" : { "type" : "text" },
"event_uuid" : { "type" : "text" },
"ALCH_TENANT_ID" : { "type" : "text" },
"logmet_cluster" : { "type" : "text" },
"org_name_str" : { "type" : "text" },
"@timestamp" : { "type" : "date" },
"message_type_str" : { "type" : "text" },
"@version" : { "type" : "text" },
"space_name_str" : { "type" : "text" },
"application_id_str" : { "type" : "text" },
"ALCH_ACCOUNT_ID_str" : { "type" : "text" },
"org_id_str" : { "type" : "text" },
"timestamp" : { "type" : "date" }
}
}
}
}'
我们批量上传的文件,使用的命令
curl -XPOST -H 'Content-Type: application/x-ndjson' http://localhost:9200/commslog/logs/_bulk --data-binary '@commslogs.json'
上述命令会引发错误
格式错误的动作/元数据线[1],预期START_OBJECT或END_OBJECT但发现[VALUE_STRING]
的解决方案是遵循大量上载的规则按
https://discuss.elastic.co/t/bulk-insert-file-having-many-json-entries-into-elasticsearch/46470/2
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
所以我通过在每行之前加入动作手动更改了几条日志语句
{ "index" : { "_index" : "commslog", "_type" : "logs" } }
这个作品!!
另一种选择是要求curl命令,提供_idex和_type路径
curl -XPOST -H 'Content-Type: application/x-ndjson' http://localhost:9200/commslog/logs/_bulk --data-binary '@commslogs.json'
,但没有行动,这也引发了同样的错误
问题是,我们不能这样做为我们得到的数千条日志记录。是否有一种选择,即我们从Bluemix下载日志文件并上传文件而不添加操作。
注意我们不使用logstash的那一刻,但
- 是有可能使用logstash,只需使用神交改造 日志,并添加必要的条目?
我们如何通过Logstash批量上传文件?
是logstash理想的解决方案,或者我们可以只编写一个程序来 改造和做
感谢
Filebeat应该能够将json日志直接写入您的本地elasticsearch。 –
谢谢@AlainCollins。我确实尝试了Filebeats,并能够将日志直接上传到ES中。 – Tatha