以弹性搜索连接为条件的 Logstash 输出

Logstash output conditional on elasticsearch connection

我目前正在使用logstash解析并输出几个类似命令的结果给elasticsearch,类似这样:

input {
  exec {
    type => 'hist'
    command => '/usr/bin/somecommand'
    interval => 900
    codec => "json"
  }

  exec {
    type => 'hist'
    command => '/usr/bin/somecommand'
    interval => 900
    codec => "json"
  }

  exec {
    type => 'hist'
    command => '/usr/bin/somecommand'
    interval => 900
    codec => "json"
  }
}

output {
        if [type] == "hist" {
                elasticsearch {
                        hosts => ["hostname.domain.com:9200"]
                        index => "monitor-hist-%{+YYYY-MM-dd}"
                }
        }
}

如果与 elasticsearch 的连接失败,我希望能够输出到标准输出或文件,例如:

if _connectionfails_ {
    stdout {
          codec => rubydebug
    }
}

这可能吗?或者在弹性不可用时管理数据的任何其他建议?

Logstash 在处理过程中将所有事件保存在主内存中。 Logstash 通过尝试停止输入并等待未决事件在关闭前完成处理来响应 SIGTERM。当由于输出或过滤器卡住而无法刷新管道时,Logstash 会无限期地等待。例如,当管道将输出发送到 Logstash 实例无法访问的数据库时,该实例会在收到 SIGTERM 后无限期等待。