JasonWu73/Blog

Logstash 输入插件 Http_poller

JasonWu73 opened this issue · 0 comments

Logstash 输入插件 Http_poller

Logstash 配置文件

logstash.conf

input {
  http_poller {
    urls => {
      placeholder_api => {
        url => "https://jsonplaceholder.typicode.com/posts"
        method => POST
        headers => {
          "Content-Type" => "application/json"
        }
        body => '{"title": "foo", "body": "bar", "userId": "1"}'
      }
    }
    tags => "jsonplaceholder_api"
    request_timeout => 100
    schedule => {"every" => "5s"}
    codec => "json"
    metadata_target => "http_poller_metadata"
  }
  http_poller  {
    urls => {
      es_health_status => {
        url => "http://localhost:9200/_cluster/health"
        method => GET
        headers => {
          Accept => "application/json"
        }
      }
    }
    tags => "es_health"
    request_timeout => 60
    schedule => {cron => "* * * * * UTC"}
    codec => "json"
    metadata_target => "http_poller_metadata"
  }
}

output {
  stdout {}

  if "es_health" in [tags] {
    elasticsearch {
      hosts => ["localhost:9200"]
      index => "http-poller-es-health"
    }
  }

  if "jsonplaceholder_api" in [tags] {
    elasticsearch {
      hosts => ["localhost:9200"]
      index => "http-poller-jsonplaceholder"
    }
  }
}

执行 Logstash 导入 Elasticsearch

$ bin/logstash -f /Users/jasonwu/WorkSpace/learn/Elasticsearch/logstash.conf