Class: MuninManager::Plugins::NetworkLatency
- Includes:
- ActsAsMuninPlugin
- Defined in:
- lib/munin_manager/plugins/network_latency.rb
Instance Attribute Summary
Attributes inherited from LogReader
#file_name, #me, #state_dir, #state_file
Class Method Summary collapse
Methods included from ActsAsMuninPlugin
Methods inherited from LogReader
#collect!, #initialize, #load_saved_state, #process!, #save_state, #scan
Constructor Details
This class inherits a constructor from MuninManager::LogReader
Class Method Details
.config(hostnames) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/munin_manager/plugins/network_latency.rb', line 39 def self.config(hostnames) configs = { "graph_title" => "Network Latency", "graph_vlabel" => "time (ms)", "graph_category" => "Network", "graph_order" => "" } hostnames.each do |hostname| configs["#{sanitize(hostname)}.label"] = hostname configs["graph_order"] += "#{sanitize(hostname)} " end configs.map {|key_value_pair| key_value_pair.join(" ")}.join("\n") end |
.run ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/munin_manager/plugins/network_latency.rb', line 5 def self.run hostnames = (ENV['hostnames'] || 'localhost').split(",") count = (ENV["count"] || 1).to_i if ARGV[0] == "config" puts config(hostnames) else values = Hash.new {|h,k| h[k] = []} threads = [] count.times do |i| threads << Thread.new do output = %x{/usr/sbin/fping -c 10 -p 100 -q #{hostnames.join(" ")} 2>&1} Thread.current[:output] = output end end threads.each do |t| t.join t[:output].to_s.split("\n").each do |line| if line =~ /^([^\s]+)\s*:\s*xmt\/rcv\/%loss = [0-9]+\/[0-9]+\/[0-9]+%, min\/avg\/max = [0-9.]+\/([0-9.]+)\/[0-9.]+/ values[$1] << $2.to_f end end end values.each do |host, results| avg = results.size > 0 ? results.inject(0){|a,b| a + b}.to_f / results.size : -1 puts "#{sanitize(host)}.value #{avg}" end end end |
.sanitize(hostname) ⇒ Object
35 36 37 |
# File 'lib/munin_manager/plugins/network_latency.rb', line 35 def self.sanitize(hostname) hostname.to_s.gsub(/[^\w]/, '_') end |