class Panopticon::WlanUtilization
Constants
- FREQ2CHAN
- REG_ACTIVE
- REG_BUSY
- REG_FREQ
Public Class Methods
new(ifname)
click to toggle source
# File lib/panopticon/wlan_utilization.rb, line 69 def initialize ifname @ifname = ifname @ifname_exists = interface_exists?(ifname) unless @ifname_exists STDERR.puts("WARNING: interface #{ifname} does not exists, run in dummy mode") end end
Public Instance Methods
current_data()
click to toggle source
# File lib/panopticon/wlan_utilization.rb, line 77 def current_data unless @ifname.match(/^(wlan\d+|wlx.+)$/) $log.debug("non-wlan skips utilization acquirement") return [0, 0, 0, 0] end unless @ifname_exists $log.warn("interface not available for utilizationm aquirement") return [0, 0, 0, 0] end str = get_survey_dump() active = 0 busy = 0 channel = 0 str.split("\n").map{|line| line.strip}.each do |line| case line when REG_FREQ channel = FREQ2CHAN[$1.to_i] when REG_ACTIVE active = $1.to_i active *= 1000 if $2 != "m" when REG_BUSY busy = $1.to_i busy *= 1000 if $2 != "m" end end return [0, 0, 0, 0] if active == 0 return [channel, active, busy, fto2f(busy.to_f * 100 / active.to_f) ] end
Private Instance Methods
fto2f(f)
click to toggle source
# File lib/panopticon/wlan_utilization.rb, line 115 def fto2f f return (f * 100).to_i.to_f / 100 end
get_survey_dump()
click to toggle source
# File lib/panopticon/wlan_utilization.rb, line 111 def get_survey_dump return `iw #{@ifname} survey dump | grep -A 4 "in use"` end
interface_exists?(ifname)
click to toggle source
# File lib/panopticon/wlan_utilization.rb, line 119 def interface_exists?(ifname) return system("ip link show ${ifname} 1>/dev/null 2>&1") end