Class: Fluent::Plugin::HttpPullInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_http_pull.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



36
37
38
39
40
# File 'lib/fluent/plugin/in_http_pull.rb', line 36

def configure(conf)
  super

  @shutdown = false
end

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fluent/plugin/in_http_pull.rb', line 46

def run
  while !@shutdown
    ts = Time.now.to_f

    res = RestClient.get(@url)
    if @status_only
      router.emit(@tag, Engine.now, {
        "url" => @url,
        "status" => res.code
      })
    else
      router.emit(@tag, Engine.now, {
        "url" => @url,
        "status" => res.code,
        "message" => JSON.parse(res.body)
      })
    end

    te = Time.now.to_f
    delay = @interval - (te - ts)
    delay = delay > 0 ? delay : 0

    sleep delay
  end
end

#shutdownObject



72
73
74
75
# File 'lib/fluent/plugin/in_http_pull.rb', line 72

def shutdown
  @shutdown = true
  @thread.join if @thread
end

#startObject



42
43
44
# File 'lib/fluent/plugin/in_http_pull.rb', line 42

def start
  @thread = Thread.new(&method(:run))
end