arbi 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/arbi +3 -5
- data/bin/arbid +3 -11
- data/lib/arbi.rb +31 -256
- data/lib/arbi/cli/client.rb +89 -0
- data/lib/arbi/cli/server.rb +75 -0
- data/lib/arbi/client.rb +52 -0
- data/lib/arbi/config.rb +70 -0
- data/lib/arbi/modules.rb +183 -0
- data/lib/arbi/modules/acpi/adapter.rb +62 -0
- data/lib/arbi/modules/acpi/battery.rb +99 -0
- data/lib/arbi/modules/acpi/utils.rb +50 -0
- data/lib/arbi/modules/adapter.rb +22 -0
- data/lib/arbi/modules/battery.rb +22 -0
- data/lib/arbi/modules/cpu.rb +88 -0
- data/lib/arbi/modules/diskstat.rb +81 -0
- data/lib/arbi/modules/help.rb +40 -0
- data/lib/arbi/modules/net.rb +120 -0
- data/lib/arbi/modules/ram.rb +52 -0
- data/lib/arbi/modules/sys/adapter.rb +60 -0
- data/lib/arbi/modules/sys/battery.rb +101 -0
- data/lib/arbi/modules/sys/thermal.rb +71 -0
- data/lib/arbi/modules/version.rb +42 -0
- data/lib/arbi/server.rb +67 -0
- data/lib/arbi/timeline.rb +70 -0
- data/lib/arbi/utils/numeric.rb +81 -0
- data/lib/arbi/utils/table.rb +48 -0
- data/lib/arbi/version.rb +23 -0
- metadata +53 -10
- data/lib/arbi/common.rb +0 -3
- data/lib/arbi/plugins/batteries.rb +0 -85
- data/lib/arbi/plugins/cpu.rb +0 -89
- data/lib/arbi/plugins/diskspace.rb +0 -68
- data/lib/arbi/plugins/net.rb +0 -120
- data/lib/arbi/plugins/ram.rb +0 -29
- data/lib/arbi/plugins/thermal.rb +0 -71
data/bin/arbi
CHANGED
data/bin/arbid
CHANGED
data/lib/arbi.rb
CHANGED
@@ -1,266 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
#--
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
3
|
+
#
|
4
|
+
# This file is part of arbi.
|
5
|
+
#
|
6
|
+
# arbi is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# arbi is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with arbi. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'arbi/client'
|
10
21
|
|
11
22
|
module Arbi
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
VERSION = "1.0.7"
|
16
|
-
|
17
|
-
@cmd = []
|
18
|
-
|
19
|
-
def self.add_plugin regex, instance
|
20
|
-
@cmd += [[regex, instance]]
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.cmd
|
24
|
-
@cmd
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.show_version
|
28
|
-
puts "Arbi (Client|Server) v#{VERSION}"
|
29
|
-
exit 0
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.connect address = '127.0.0.1', port = '6969'
|
33
|
-
@@connection = TCPSocket.new address, port
|
34
|
-
@@connection.print "SERIAL\r\n"
|
23
|
+
class << self
|
24
|
+
def connect(address = '127.0.0.1', port = 6969)
|
25
|
+
@@connection = Arbi::Client.new(address, port)
|
35
26
|
end
|
36
27
|
|
37
|
-
def
|
38
|
-
|
39
|
-
false
|
28
|
+
def connected?
|
29
|
+
@@connection ? true : false
|
40
30
|
end
|
41
31
|
|
42
|
-
def
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.get what
|
47
|
-
self.connect unless self.connected?
|
48
|
-
@@connection.print what + "\r\n"
|
49
|
-
eval @@connection.gets.strip
|
50
|
-
end
|
51
|
-
|
52
|
-
class Server
|
53
|
-
require 'socket'
|
54
|
-
|
55
|
-
def initialize
|
56
|
-
@threads = Array.new
|
57
|
-
@sessions = Array.new
|
58
|
-
@address = 'localhost'
|
59
|
-
@port = 6969
|
60
|
-
parse_args
|
61
|
-
@server = TCPServer.new(@address, @port)
|
62
|
-
end
|
63
|
-
|
64
|
-
def start
|
65
|
-
@servert = Thread.new do
|
66
|
-
while(session = @server.accept)
|
67
|
-
new_client session
|
68
|
-
end
|
69
|
-
end
|
70
|
-
@servert.join
|
71
|
-
end
|
72
|
-
|
73
|
-
def close
|
74
|
-
@sessions.each{ |session|
|
75
|
-
session.close
|
76
|
-
}
|
77
|
-
|
78
|
-
@threads.each{ |thread|
|
79
|
-
thread.kill
|
80
|
-
}
|
81
|
-
@server.close
|
82
|
-
@servert.kill
|
83
|
-
end
|
84
|
-
|
85
|
-
def finalize
|
86
|
-
close
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def parse_args
|
92
|
-
OptionParser.new do |o|
|
93
|
-
|
94
|
-
o.program_name = 'arbid'
|
95
|
-
o.banner = 'Arbi server, USAGE:'
|
96
|
-
|
97
|
-
o.on('-a', '--bind-address ADDR', 'Address to bind, default to "127.0.0.1"') do |addr|
|
98
|
-
@address = addr
|
99
|
-
end
|
100
|
-
|
101
|
-
o.on('-p', '--port PORT', 'Port to use for server, default to 6969') do |port|
|
102
|
-
@port = port
|
103
|
-
end
|
104
|
-
|
105
|
-
o.on('-V', '--version', 'Print version and exit') do
|
106
|
-
puts Arbi::show_version
|
107
|
-
exit 0
|
108
|
-
end
|
109
|
-
|
110
|
-
o.on_tail('-h', '--help', 'Print this help and exit') do
|
111
|
-
puts o.to_s
|
112
|
-
exit 0
|
113
|
-
end
|
114
|
-
|
115
|
-
end.parse!
|
116
|
-
|
117
|
-
rescue OptionParser::MissingArgument
|
118
|
-
puts "At least one argument is required for this option."
|
119
|
-
puts "See help for details."
|
120
|
-
exit -1
|
121
|
-
end
|
122
|
-
|
123
|
-
def new_client session
|
124
|
-
@threads.push Thread.start(session){ |session|
|
125
|
-
ser = false
|
126
|
-
while message = session.gets
|
127
|
-
toggle = true
|
128
|
-
message = message.strip
|
129
|
-
break if message =~ /^QUIT$/i
|
130
|
-
|
131
|
-
if message =~ /^HELP$/i and !ser
|
132
|
-
session.print "help:\r\n"
|
133
|
-
Arbi::cmd.each { |pair|
|
134
|
-
session.print "#{pair[0]}\r\n"
|
135
|
-
}
|
136
|
-
session.print "/^quit$/i\r\n"
|
137
|
-
session.print "/^version$/i\r\n"
|
138
|
-
session.print "/^help$/i\r\n"
|
139
|
-
session.print "END\r\n"
|
140
|
-
toggle = !toggle
|
141
|
-
end
|
142
|
-
|
143
|
-
if message =~ /^VERSION$/i and !ser
|
144
|
-
session.print "version:\r\nArbi (Client|Server) v#{VERSION}\r\nEND\r\n"
|
145
|
-
toggle = !toggle
|
146
|
-
end
|
147
|
-
|
148
|
-
if message =~ /^SERIAL$/i
|
149
|
-
ser = !ser
|
150
|
-
toggle = !toggle
|
151
|
-
end
|
152
|
-
|
153
|
-
Arbi::cmd.each { |pair|
|
154
|
-
if message =~ pair[0]
|
155
|
-
if ser
|
156
|
-
session.print pair[1].get_infos.inspect + "\r\n"
|
157
|
-
else
|
158
|
-
session.print (pair[1].class == Class ? pair[1].protocolize(pair[1].get_infos) : pair[1].class.protocolize(pair[1].get_infos))
|
159
|
-
end
|
160
|
-
toggle = !toggle
|
161
|
-
end
|
162
|
-
}
|
163
|
-
session.print (ser ? "{'error' => 'command desn\\'t exist'}" : "error:\r\nCommand doesn't exist\r\nEND\r\n") if toggle
|
164
|
-
end
|
165
|
-
@sessions -= [session]
|
166
|
-
session.close
|
167
|
-
}
|
168
|
-
@sessions.push session
|
169
|
-
end
|
32
|
+
def connection
|
33
|
+
@@connection.sock
|
170
34
|
end
|
171
35
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
@port = 6969
|
176
|
-
@command = "help\r\nquit\r\n"
|
177
|
-
parse_args
|
178
|
-
@sock = TCPSocket.new(@address, @port)
|
179
|
-
|
180
|
-
rescue Errno::ECONNREFUSED
|
181
|
-
puts "You have to start arbid demon first, or specify a correct port."
|
182
|
-
exit -2
|
183
|
-
end
|
184
|
-
|
185
|
-
def start
|
186
|
-
@sock.print @command
|
187
|
-
@command = @command.strip.split(/\r\n/).map(&:upcase)
|
188
|
-
@command.pop
|
189
|
-
toggle = false
|
190
|
-
while (line = @sock.gets)
|
191
|
-
puts (command = @command.shift) + ":"
|
192
|
-
buff = ""
|
193
|
-
while (l = @sock.gets).strip !~ /^END$/i do; buff << l; end
|
194
|
-
buff.gsub!(/END\s+$/m, '')
|
195
|
-
case line.strip
|
196
|
-
when /^error:$/i
|
197
|
-
puts "ERROR: #{buff}"
|
198
|
-
next
|
199
|
-
when /^help:$/i
|
200
|
-
puts buff
|
201
|
-
when /^version:$/i
|
202
|
-
puts buff
|
203
|
-
end
|
204
|
-
Arbi::cmd.each{|cmd|
|
205
|
-
puts (cmd[1].class == Class ? cmd[1].friendlize(buff) : cmd[1].class.friendlize(buff)) if command =~ cmd[0]
|
206
|
-
}
|
207
|
-
puts if @command != []
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
def close
|
212
|
-
@sock.close
|
213
|
-
end
|
214
|
-
|
215
|
-
def finalize
|
216
|
-
close
|
217
|
-
end
|
218
|
-
|
219
|
-
private
|
220
|
-
|
221
|
-
def parse_args
|
222
|
-
OptionParser.new do |o|
|
223
|
-
|
224
|
-
o.program_name = 'arbi'
|
225
|
-
o.banner = 'Arbi client, USAGE:'
|
226
|
-
|
227
|
-
o.on('-c', '--command COMMANDS', Array, 'Set commands to execute, default is \'help\'') do |cmd|
|
228
|
-
cmd.delete('quit')
|
229
|
-
@command = (cmd&cmd).push('quit').inject(''){|str, cmd| str<<"#{cmd}\r\n"}
|
230
|
-
end
|
231
|
-
|
232
|
-
o.on('-a', '--address ADDR', 'Set address to connect, default to "127.0.0.1"') do |addr|
|
233
|
-
@address = addr
|
234
|
-
end
|
235
|
-
|
236
|
-
o.on('-p', '--port PORT', 'Set port to connect, default to 6969') do |port|
|
237
|
-
@port = port
|
238
|
-
end
|
239
|
-
|
240
|
-
o.on('-V', '--version', 'Print version and exit') do
|
241
|
-
puts Arbi::show_version
|
242
|
-
exit 0
|
243
|
-
end
|
244
|
-
|
245
|
-
o.on_tail('-h', '--help', 'Print this help and exit') do
|
246
|
-
@help = o.to_s
|
247
|
-
puts @help
|
248
|
-
exit 0
|
249
|
-
end
|
250
|
-
|
251
|
-
end.parse!
|
252
|
-
|
253
|
-
rescue OptionParser::MissingArgument
|
254
|
-
puts "At least one argument is required for this option."
|
255
|
-
puts "See help for details."
|
256
|
-
exit -1
|
257
|
-
end
|
36
|
+
def get(what)
|
37
|
+
self.connect unless self.connected?
|
38
|
+
@@connection.get(what)
|
258
39
|
end
|
40
|
+
end
|
259
41
|
end
|
260
|
-
|
261
|
-
require 'arbi/plugins/batteries'
|
262
|
-
require 'arbi/plugins/cpu'
|
263
|
-
require 'arbi/plugins/diskspace'
|
264
|
-
require 'arbi/plugins/net'
|
265
|
-
require 'arbi/plugins/ram'
|
266
|
-
require 'arbi/plugins/thermal'
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
3
|
+
#
|
4
|
+
# This file is part of arbi.
|
5
|
+
#
|
6
|
+
# arbi is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# arbi is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with arbi. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'optparse'
|
21
|
+
require 'arbi/client'
|
22
|
+
require 'arbi/config'
|
23
|
+
require 'arbi/version'
|
24
|
+
|
25
|
+
module Arbi
|
26
|
+
|
27
|
+
module Cli
|
28
|
+
|
29
|
+
class Client
|
30
|
+
def initialize
|
31
|
+
@address = Arbi::Config[:client][:address]
|
32
|
+
@port = Arbi::Config[:client][:port]
|
33
|
+
@commands = Arbi::Config[:client][:default_cmd]
|
34
|
+
|
35
|
+
self.parse_args
|
36
|
+
|
37
|
+
@client = Arbi::Client.new(@address, @port)
|
38
|
+
|
39
|
+
@commands.each {|command|
|
40
|
+
puts("#{command.upcase}:\n" + @client.get(command).format + "\n\n") if command !~ /^(quit|exit)$/i
|
41
|
+
}
|
42
|
+
rescue Errno::ECONNREFUSED
|
43
|
+
puts "You have to start arbid daemon first, or specify a correct port."
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
def parse_args
|
49
|
+
OptionParser.new do |o|
|
50
|
+
o.program_name = 'arbi'
|
51
|
+
o.banner = "Arbi client v#{Arbi::VERSION}, USAGE:"
|
52
|
+
|
53
|
+
o.on('-c', '--config CONF', 'Select configurations path, default to /etc/arbi.conf') do |conf|
|
54
|
+
Arbi::Config.parse(conf)
|
55
|
+
end
|
56
|
+
|
57
|
+
o.on('-c', '--command COMMANDS', Array, 'Set commands to execute, default is \'help\'') do |cmd|
|
58
|
+
cmd.delete('quit')
|
59
|
+
@commands = (cmd & cmd).push('quit')
|
60
|
+
end
|
61
|
+
|
62
|
+
o.on('-a', '--address ADDR', 'Set address to connect, default to "127.0.0.1"') do |addr|
|
63
|
+
@address = addr
|
64
|
+
end
|
65
|
+
|
66
|
+
o.on('-p', '--port PORT', 'Set port to connect, default to 6969') do |port|
|
67
|
+
@port = port
|
68
|
+
end
|
69
|
+
|
70
|
+
o.on('-V', '--version', 'Print version and exit') do
|
71
|
+
puts "Arbi client v#{Arbi::VERSION}"
|
72
|
+
exit 0
|
73
|
+
end
|
74
|
+
|
75
|
+
o.on_tail('-h', '--help', 'Print this help and exit') do
|
76
|
+
puts o.to_s
|
77
|
+
exit 0
|
78
|
+
end
|
79
|
+
end.parse!
|
80
|
+
rescue OptionParser::MissingArgument
|
81
|
+
puts "At least one argument is required fro this option."
|
82
|
+
puts "See help for details."
|
83
|
+
exit 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft shura. [ shura1991@gmail.com ]
|
3
|
+
#
|
4
|
+
# This file is part of arbi.
|
5
|
+
#
|
6
|
+
# arbi is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# arbi is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with arbi. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'optparse'
|
21
|
+
require 'arbi/server'
|
22
|
+
require 'arbi/version'
|
23
|
+
|
24
|
+
module Arbi
|
25
|
+
|
26
|
+
module Cli
|
27
|
+
|
28
|
+
class Server
|
29
|
+
def initialize
|
30
|
+
@address = Arbi::Config[:server][:address]
|
31
|
+
@port = Arbi::Config[:server][:port]
|
32
|
+
|
33
|
+
self.parse_args
|
34
|
+
|
35
|
+
Arbi::Server.start(@address, @port)
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def parse_args
|
40
|
+
OptionParser.new do |o|
|
41
|
+
o.program_name = 'arbid'
|
42
|
+
o.banner = "Arbi server v#{Arbi::VERSION}, USAGE:"
|
43
|
+
|
44
|
+
o.on('-c', '--config CONF', 'Select configurations path, default to /etc/arbi.conf') do |conf|
|
45
|
+
Arbi::Config.parse(conf)
|
46
|
+
end
|
47
|
+
|
48
|
+
o.on('-a', '--bind-address ADDR', 'Address to bind, default to "127.0.0.1"') do |addr|
|
49
|
+
@address = addr
|
50
|
+
end
|
51
|
+
|
52
|
+
o.on('-p', '--port PORT', 'Port to use for server, default to 6969') do |port|
|
53
|
+
@port = port
|
54
|
+
end
|
55
|
+
|
56
|
+
o.on('-V', '--version', 'Print version and exit') do
|
57
|
+
puts "Arbi server v#{Arbi::VERSION}"
|
58
|
+
exit 0
|
59
|
+
end
|
60
|
+
|
61
|
+
o.on_tail('h', '--help', 'Print this help and exit') do
|
62
|
+
puts o.to_s
|
63
|
+
exit 0
|
64
|
+
end
|
65
|
+
end.parse!
|
66
|
+
rescue OptionParser::MissingArgument
|
67
|
+
puts "At least one argument is required for this option."
|
68
|
+
puts "See help for detail"
|
69
|
+
exit 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|