arbi 1.0.8.1 → 1.0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arbi/config.rb +4 -4
- data/lib/arbi/modules/net.rb +5 -9
- data/lib/arbi/version.rb +1 -1
- metadata +2 -2
data/lib/arbi/config.rb
CHANGED
@@ -30,10 +30,10 @@ class Config < Hash
|
|
30
30
|
self.parse
|
31
31
|
end
|
32
32
|
|
33
|
-
def parse(file = '/etc/arbi.
|
34
|
-
config = YAML.load_file(file)
|
35
|
-
rescue
|
36
|
-
Arbi.debug "Config:
|
33
|
+
def parse(file = '/etc/arbi.yaml')
|
34
|
+
config = ::YAML.load_file(file)
|
35
|
+
rescue Exception => e
|
36
|
+
Arbi.debug "Config: #{e}"
|
37
37
|
ensure
|
38
38
|
config ||= {}
|
39
39
|
config[:server] ||= {}
|
data/lib/arbi/modules/net.rb
CHANGED
@@ -31,7 +31,7 @@ class Net < Arbi::Modules::Module
|
|
31
31
|
@prev = {:up => {}, :down => {}}
|
32
32
|
@datas = []
|
33
33
|
|
34
|
-
every
|
34
|
+
every 1, :timeout => 10, &self.method(:update)
|
35
35
|
end
|
36
36
|
|
37
37
|
def valid?
|
@@ -53,6 +53,7 @@ class Net < Arbi::Modules::Module
|
|
53
53
|
})
|
54
54
|
end
|
55
55
|
|
56
|
+
protected
|
56
57
|
def update
|
57
58
|
stats = {}
|
58
59
|
File.read('/proc/net/dev').gsub(/^.*\|.*?\n/m, '').each_line {|line|
|
@@ -63,8 +64,8 @@ class Net < Arbi::Modules::Module
|
|
63
64
|
@prev[:up][name] = @prev[:down][name] = 0 if !@prev[:up].include?(name) and !@prev[:down].include?(name)
|
64
65
|
|
65
66
|
stats[name] = {
|
66
|
-
up: "%.
|
67
|
-
down: "%.
|
67
|
+
up: "%.1f kB/s" % [( up - @prev[ :up ][name]).to_f / 1024],
|
68
|
+
down: "%.1f kB/s" % [(down - @prev[:down][name]).to_f / 1024],
|
68
69
|
state: (File.read('/proc/net/route') =~ /#{Regexp.escape(name)}/ ? true : false),
|
69
70
|
quality: nil,
|
70
71
|
essid: nil
|
@@ -72,11 +73,7 @@ class Net < Arbi::Modules::Module
|
|
72
73
|
|
73
74
|
if stats[name][:state]
|
74
75
|
stats[name][:quality] = quality(name)
|
75
|
-
|
76
|
-
stats[name][ :essid ] = essid(name) if stats[name][:quality]
|
77
|
-
rescue Exception => e
|
78
|
-
Arbi.debug("ESSID: #{e}")
|
79
|
-
end
|
76
|
+
stats[name][ :essid ] = essid(name) if stats[name][:quality]
|
80
77
|
end
|
81
78
|
|
82
79
|
@prev[ :up ][name] = up
|
@@ -88,7 +85,6 @@ class Net < Arbi::Modules::Module
|
|
88
85
|
Arbi.debug(e.to_s)
|
89
86
|
end
|
90
87
|
|
91
|
-
protected
|
92
88
|
def quality(interface)
|
93
89
|
File.read('/proc/net/wireless').match(/^\s*#{Regexp.escape(interface)}:.*$/)[0].strip.split(/:?\s+/)[2].gsub('.', '') + "%"
|
94
90
|
rescue
|
data/lib/arbi/version.rb
CHANGED