Class: Fluent::NetworkProbeInput
- Inherits:
-
Input
- Object
- Input
- Fluent::NetworkProbeInput
- Defined in:
- lib/fluent/plugin/in_network_probe.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #exec_curl ⇒ Object
- #exec_fping ⇒ Object
-
#initialize ⇒ NetworkProbeInput
constructor
A new instance of NetworkProbeInput.
- #run ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ NetworkProbeInput
Returns a new instance of NetworkProbeInput.
26 27 28 29 30 |
# File 'lib/fluent/plugin/in_network_probe.rb', line 26 def initialize require "eventmachine" super end |
Instance Method Details
#configure(conf) ⇒ Object
32 33 34 35 36 |
# File 'lib/fluent/plugin/in_network_probe.rb', line 32 def configure(conf) super @conf = conf end |
#exec_curl ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fluent/plugin/in_network_probe.rb', line 91 def exec_curl cmd = "#{@curl_exec} #{@curl_protocol}://#{@target}:#{@curl_port}#{@curl_path} -w \%\{time_total\} -m #{@curl_timeout}" result_times = [] @curl_count.times do cmd_results = run_cmd(cmd) result_times << cmd_results[0].split("\n").last.to_f * 1000 sleep @curl_interval end results = {} results[:max] = result_times.max results[:min] = result_times.min results[:avg] = result_times.inject(0.0){|r,i| r+=i }/result_times.size results end |
#exec_fping ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fluent/plugin/in_network_probe.rb', line 68 def exec_fping cmd = "#{@fping_exec} -i #{@fping_interval*1000} -T #{@fping_timeout} -c #{@fping_count} #{@target} -s" cmd_results = run_cmd(cmd) round_trip_times = Hash.new(nil) cmd_results[1].split("\n").each do |line| if /([^\s]*) ms \(min round trip time\)/=~ line round_trip_times[:min] = $1.to_f end if /([^\s]*) ms \(avg round trip time\)/=~ line round_trip_times[:avg]= $1.to_f end if /([^\s]*) ms \(max round trip time\)/=~ line round_trip_times[:max] = $1.to_f end end round_trip_times end |
#run ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fluent/plugin/in_network_probe.rb', line 49 def run init_eventmachine EM.run do EM.add_periodic_timer(@interval) do begin EM.defer do Engine.emit("#{@tag}_#{@target}", Engine.now, exec_fping) if @probe_type == 'fping' end EM.defer do Engine.emit("#{@tag}_#{@target}", Engine.now, exec_curl) if @probe_type == 'curl' end rescue => ex $log.warn("EM.periodic_timer loop error.") $log.warn("#{ex}, tracelog : \n#{ex.backtrace.join("\n")}") end end end end |
#shutdown ⇒ Object
44 45 46 47 |
# File 'lib/fluent/plugin/in_network_probe.rb', line 44 def shutdown super @thread.kill end |
#start ⇒ Object
38 39 40 41 42 |
# File 'lib/fluent/plugin/in_network_probe.rb', line 38 def start super @thread = Thread.new(&method(:run)) $log.info "starting network probe, target #{@target} probe_type #{@probe_type}." end |