Class: LogStash::Inputs::HTTP_Poller

Inherits:
Base
  • Object
show all
Includes:
PluginMixins::HttpClient
Defined in:
lib/logstash/inputs/http_poller.rb

Overview

This Logstash input plugin allows you to call an HTTP API, decode the output of it into event(s), and send them on their merry way. The idea behind this plugins came from a need to read springboot metrics endpoint, instead of configuring jmx to monitor my java application memory/gc/ etc.

Example

Reads from a list of urls and decodes the body of the response with a codec. The config should look like this:

source,ruby

input {

http_poller {
  urls => {
    test1 => "http://localhost:9200"
    test2 => {
      # Supports all options supported by ruby's Manticore HTTP client
      method => get
      url => "http://localhost:9200/_cluster/health"
      headers => {
        Accept => "application/json"
      }
      auth => {
        user => "AzureDiamond"
        password => "hunter2"
      }
    }
  }
  request_timeout => 60
  interval => 60
  codec => "json"
  # A hash of request metadata info (timing, response headers, etc.) will be sent here
   => "http_poller_metadata"
}

}

output {

stdout {
  codec => rubydebug
}

}


Instance Method Summary collapse

Instance Method Details

#registerObject



73
74
75
76
77
78
79
80
# File 'lib/logstash/inputs/http_poller.rb', line 73

def register
  @host = Socket.gethostname.force_encoding(Encoding::UTF_8)

  @logger.info("Registering http_poller Input", :type => @type,
               :urls => @urls, :interval => @interval, :timeout => @timeout)

  setup_requests!
end

#run(queue) ⇒ Object



135
136
137
138
139
140
# File 'lib/logstash/inputs/http_poller.rb', line 135

def run(queue)
  @interval_thread = Thread.current
  Stud.interval(@interval) do
    run_once(queue)
  end
end

#stopObject



82
83
84
# File 'lib/logstash/inputs/http_poller.rb', line 82

def stop
  Stud.stop!(@interval_thread) if @interval_thread
end