我们在云中有一些外部应用程序(IBM Bluemix),该应用程序将其应用程序syslog记录在内部使用ELK堆栈的bluemix logmet服务中。
现在,我们要定期从云中下载日志,并将其上传到本地Elastic / Kibana实例中。这是因为如果我们想通过Kibana进行搜索,将日志存储在云服务中会产生成本和额外成本。本地 flex 实例可以删除/刷新我们不需要的旧日志。
下载的日志如下所示
{"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'
但是如果没有 Action ,也会引发相同的错误
问题是我们无法对获得的数千条日志记录执行此操作。是否存在一个选项,让我们一旦从Bluemix下载日志文件并上传文件而不添加操作即可。
注意目前我们不使用logstash,但是
日志并添加必要的条目?
转换并执行
谢谢
最佳答案
正如@Alain Collins所说,您应该能够直接使用filebeat。
对于logstash:
至于您的问题,我认为仅使用一个小程序来添加缺少的 Action 行或使用filebeat就会容易得多,除非您对logstash config进行了足够的实验,以使其比在其中各处添加一行的程序更快地编写和logstash配置文件。
关于elasticsearch - 将日志消息批量上传到本地Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46677179/