【问题标题】:Send file logs to logstash将文件日志发送到 logstash
【发布时间】:2018-01-16 19:34:08
【问题描述】:

我在 GCS 中有文件,每个文件都包含 json 行 文件示例:

{"msg": "hello world", "level": "info", "timestamp": "2017-09-01T00:00"}
{"msg": "some error",  "level": "error", "timestamp": "2017-09-02T00:00"}
{"msg": "success" , "level": "info", "timestamp": "2017-09-03T00:00"}
...

我正在 GCS 中的所有文件上运行,下载每个文件并尝试将它们发送到 logstash - 所以我在弹性中获取每一行日志

这是我的logstash conf:

input {
  tcp {
    port => 5000
  }
}
output {
  elasticsearch {
    hosts => "https://xxxxxxxxxxx.us-central1.gcp.cloud.es.io:9243"
    user => "elastic"
    password => "xxxxxxx"
    index => "app-log-%{+YYYY.MM.dd}"
  }
}

现在如何将文件内容发送到logstash? 我应该使用与 tcp 不同的输入吗?也许文件节拍? 是否有任何 nodejs(或其他语言)的演示代码来发送文件?

【问题讨论】:

    标签: logstash


    【解决方案1】:

    而不是下载然后将日志发送到logstash 使用filebeat,它甚至可以通过将它们发送到logstash 来处理未来的文件更改,最重要的是,它非常易于设置并且与logstashelaticsearch

    【讨论】:

    • 有没有办法让我在不保存本地的情况下发送日志文件?我想将我的脚本从 GCS 下载的文件的内容发送到 logstash WO 保存在本地 - 因为它是大量文件,我该怎么做?
    • @dina 看起来现在可以直接从 S3 解析文件,但还不支持 GCS。你可以看到所有可用的输入插件here。但是您可以尝试使用this 将这些文件作为普通文件处理,如果不是这样,您可以将所有这些文件插入到 S3 进行处理,然后从 S3 不进行任何处理就可以插入到 ELK 中。跨度>
    • @dina 让我知道这是否适合你 如果这是你正在寻找的更新答案
    • 感谢您的帮助,我没有尝试过 file input plugin ,我最终使用了 http 插件,无论如何谢谢
    【解决方案2】:

    我结束了使用http 插件

    input { 
      http { codec => line} 
    }
    
    filter {
    }
    
    output {
      elasticsearch {
        hosts => "https://xxxxx.us-central1.gcp.cloud.es.io:9243"
        user => "elastic"
        password => "xxxxxxx"
        index => "app"
      }
    
    }
    

    然后用http发送:

    curl -X POST \
      http://127.0.0.1:8080/ \
      -H 'content-type: content-type: application/json' \
      -d '{"msg": "hello world", "level": "info", "timestamp": "2017-09-01T00:00"}
    {"msg": "some error",  "level": "error", "timestamp": "2017-09-02T00:00"}
    {"msg": "success" , "level": "info", "timestamp": "2017-09-03T00:00"}
    '
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 2014-08-29
      相关资源
      最近更新 更多