vpsadmin-client 3.0.0.master.20220809.pre.0.4bb004b0 → 3.0.0.master.20221118.pre.0.ac358990

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b441c7f4575b1c83f0b44e030e487f5a21314f28044379aa020bb65437315764
4
- data.tar.gz: 83a6e16dfb20baf6188f09ec4d92e3887c957e0bbd884b4143d95a49f958f86a
3
+ metadata.gz: c96e4a445e58d056aa30c081314b6e073862d629f508a74543a7db53078118f4
4
+ data.tar.gz: bca5be7e91d7f0d2325f73412dc12c10ea7708691fe8c8b45159584aad2b7193
5
5
  SHA512:
6
- metadata.gz: a421f897c7a466b86914ecc77db3f077175b25118ae198e059f8a3c2213002d46e652734588da5f21401ec19b6d34ddd1f577d6244cc3de8631aae79267e0442
7
- data.tar.gz: 16fd9d780cf499e8af47cb9dd21592ea01e6ac76717883a3d88cfe0f108d1c579396bd4b08450e5e2a1c5ea6d5aeca5cf6f23bba47a27e27a9c566f2fcd102e0
6
+ metadata.gz: fb1306cd663e600794415114e4e1bae334011cf8d0d323ae1b11422d4bcbada5a30a6d62790d6f50a768248a4a18b50617d7e1b43fbb0cf87ec1dfd621edae42
7
+ data.tar.gz: 97f984970bb433168d35fe3466adbb9abecdbc56829da668d7f3bcb7c8526a1bc6c8b1923f5c8247e584a0532dd40d4bdd4d9e454f2f16a2a8b1c95e8210ba0f
@@ -1,15 +1,15 @@
1
1
  require 'curses'
2
2
 
3
3
  module VpsAdmin::CLI::Commands
4
- class IpTrafficTop < BackupDataset
4
+ class NetworkTop < HaveAPI::CLI::Command
5
5
  include Curses
6
6
 
7
7
  REFRESH_RATE = 10
8
- FILTERS = %i(limit ip_address ip_version environment location network ip_range node vps)
8
+ FILTERS = %i(limit user environment location node vps network_interface)
9
9
 
10
- cmd :ip_traffic, :top
10
+ cmd :network, :top
11
11
  args ''
12
- desc 'Live IP traffic monitor'
12
+ desc 'Live network traffic monitor'
13
13
 
14
14
  def options(opts)
15
15
  @opts = {
@@ -24,24 +24,8 @@ module VpsAdmin::CLI::Commands
24
24
  @opts[:limit] = v
25
25
  end
26
26
 
27
- opts.on('--ip-address ADDR', 'ADDR or ID of IP addresses to monitor') do |v|
28
- id = ip_address_id(v)
29
-
30
- if id
31
- @opts[:ip_address] = id
32
-
33
- else
34
- warn "IP address '#{v}' not found"
35
- exit(1)
36
- end
37
- end
38
-
39
- opts.on('--ip-version VER', [4, 6], 'Filter IP addresses by version') do |v|
40
- @opts[:ip_version] = v
41
- end
42
-
43
- (FILTERS - %i(limit ip_address ip_version)).each do |f|
44
- opts.on("--#{f.to_s.gsub(/_/, '-')} ID", Integer, "Filter IP addresses by #{f}") do |v|
27
+ (FILTERS - %i(limit)).each do |f|
28
+ opts.on("--#{f.to_s.gsub(/_/, '-')} ID", Integer, "Filter network interfaces by #{f}") do |v|
45
29
  @opts[f] = v
46
30
  end
47
31
  end
@@ -49,12 +33,13 @@ module VpsAdmin::CLI::Commands
49
33
 
50
34
  def exec(args)
51
35
  if @global_opts[:list_output]
52
- exclude = %i(id ip_address user updated_at delta)
36
+ exclude = %i(id network_interface updated_at delta)
53
37
 
54
- @api.ip_traffic_monitor.actions[:index].params.each_key do |name|
38
+ @api.network_interface_monitor.actions[:index].params.each_key do |name|
55
39
  next if exclude.include?(name)
56
40
  puts name
57
41
  end
42
+
58
43
  exit
59
44
  end
60
45
 
@@ -113,9 +98,8 @@ module VpsAdmin::CLI::Commands
113
98
  def set_global_opts
114
99
  if @global_opts[:output]
115
100
  @params = @global_opts[:output].split(',').map(&:to_sym)
116
-
117
101
  else
118
- @params = %i(bytes_in bytes_out bytes)
102
+ @params = %i(bytes bytes_in bytes_out packets packets_in packets_out)
119
103
  end
120
104
 
121
105
  if @global_opts[:sort]
@@ -158,7 +142,7 @@ module VpsAdmin::CLI::Commands
158
142
  params = {
159
143
  limit: limit > 0 ? limit : 25,
160
144
  order: "#{@sort_desc ? '-' : ''}#{@sort_param}",
161
- meta: {includes: 'ip_address__network_interface'}
145
+ meta: {includes: 'network_interface'},
162
146
  }
163
147
 
164
148
  FILTERS.each do |f|
@@ -167,7 +151,7 @@ module VpsAdmin::CLI::Commands
167
151
  params[f] = @opts[f]
168
152
  end
169
153
 
170
- @data = @api.ip_traffic_monitor.list(params)
154
+ @data = @api.network_interface_monitor.list(params)
171
155
  end
172
156
 
173
157
  def render(t, refresh)
@@ -177,7 +161,7 @@ module VpsAdmin::CLI::Commands
177
161
  end
178
162
 
179
163
  setpos(0, 0)
180
- addstr("#{File.basename($0)} ip_traffic top - #{t.strftime('%H:%M:%S')}, ")
164
+ addstr("#{File.basename($0)} network top - #{t.strftime('%H:%M:%S')}, ")
181
165
  addstr("next update at #{(t + REFRESH_RATE).strftime('%H:%M:%S')}")
182
166
 
183
167
  attron(color_pair(1))
@@ -202,12 +186,12 @@ module VpsAdmin::CLI::Commands
202
186
 
203
187
  def header
204
188
  unless @header
205
- fmt = (['%-30s', '%6s'] + @columns.map { |c| "%#{c[:width]}s" }).join(' ')
189
+ fmt = (['%8s', '%-15s'] + @columns.map { |c| "%#{c[:width]}s" }).join(' ')
206
190
 
207
191
  @header = sprintf(
208
192
  fmt,
209
- 'IP Address',
210
193
  'VPS',
194
+ 'Interface',
211
195
  *@columns.map { |c| c[:title] },
212
196
  )
213
197
 
@@ -219,22 +203,22 @@ module VpsAdmin::CLI::Commands
219
203
 
220
204
  def print_row(data)
221
205
  addstr(sprintf(
222
- '%-30s %6s',
223
- data.ip_address.addr,
224
- data.ip_address.network_interface.vps_id
206
+ '%8s %-15s',
207
+ data.network_interface.vps_id,
208
+ data.network_interface.name,
225
209
  ))
226
210
 
227
211
  @columns.each do |c|
228
212
  p = c[:name]
229
213
 
230
214
  attron(A_BOLD) if p == @sort_param
231
- addstr(sprintf(" %#{c[:width]}s", unitize(data.send(p), data.delta)))
215
+ addstr(sprintf(" %#{c[:width]}s", unitize_param(p, data.send(p), data.delta)))
232
216
  attroff(A_BOLD) if p == @sort_param
233
217
  end
234
218
  end
235
219
 
236
220
  def stats
237
- fields = %i(packets bytes public_bytes private_bytes)
221
+ fields = %i(bytes packets)
238
222
  stats = {}
239
223
  delta_sum = 0
240
224
 
@@ -263,32 +247,30 @@ module VpsAdmin::CLI::Commands
263
247
  setpos(lines-5, 0)
264
248
  addstr('─' * cols)
265
249
 
266
- fmt = '%10s %10s %10s %14s %14s'
250
+ fmt = '%10s %10s %10s'
267
251
  unit = @opts[:unit].to_s.capitalize
268
252
 
269
253
  setpos(lines-4, 0)
270
254
  addstr(sprintf(
271
255
  fmt,
272
256
  '',
273
- 'Packets/s',
274
257
  "#{unit}/s",
275
- "Public#{unit}/s",
276
- "Private#{unit}/s"
258
+ 'Packets/s',
277
259
  ))
278
260
 
279
261
  setpos(lines-3, 0)
280
- addstr(sprintf(fmt, 'In', *fields.map { |f| unitize(stats[:"#{f}_in"], avg_delta) }))
262
+ addstr(sprintf(fmt, 'In', *fields.map { |f| unitize_param(f, stats[:"#{f}_in"], avg_delta) }))
281
263
 
282
264
  setpos(lines-2, 0)
283
- addstr(sprintf(fmt, 'Out', *fields.map { |f| unitize(stats[:"#{f}_out"], avg_delta) }))
265
+ addstr(sprintf(fmt, 'Out', *fields.map { |f| unitize_param(f, stats[:"#{f}_out"], avg_delta) }))
284
266
 
285
267
  setpos(lines-1, 0)
286
268
  attron(A_BOLD)
287
- addstr(sprintf(fmt, 'Total', *fields.map { |f| unitize(stats[:"#{f}_in"] + stats[:"#{f}_out"], avg_delta) }))
269
+ addstr(sprintf(fmt, 'Total', *fields.map { |f| unitize_param(f, stats[:"#{f}_in"] + stats[:"#{f}_out"], avg_delta) }))
288
270
  attroff(A_BOLD)
289
271
  end
290
272
 
291
- def unitize(n, delta)
273
+ def unitize_bytes(n, delta)
292
274
  if @opts[:unit] == :bytes
293
275
  per_s = n / delta.to_f
294
276
  else
@@ -296,7 +278,7 @@ module VpsAdmin::CLI::Commands
296
278
  end
297
279
 
298
280
  bits = 39
299
- units = %i(T G M K)
281
+ units = %w(T G M k)
300
282
 
301
283
  units.each do |u|
302
284
  threshold = 2 << bits
@@ -309,6 +291,31 @@ module VpsAdmin::CLI::Commands
309
291
  per_s.round(2).to_s
310
292
  end
311
293
 
294
+ def unitize_number(n, delta)
295
+ per_s = n / delta.to_f
296
+ threshold = 1_000_000_000_000
297
+ units = %w(T G M k)
298
+
299
+ units.each do |u|
300
+ return "#{(per_s / threshold).round(2)}#{u}" if per_s >= threshold
301
+
302
+ threshold /= 1000
303
+ end
304
+
305
+ per_s.round(2).to_s
306
+ end
307
+
308
+ def unitize_param(param, n, delta)
309
+ case param
310
+ when :bytes, :bytes_in, :bytes_out
311
+ unitize_bytes(n, delta)
312
+ when :packets, :packets_in, :packets_out
313
+ unitize_number(n, delta)
314
+ else
315
+ fail "unknown param to unitize: #{param.inspect}"
316
+ end
317
+ end
318
+
312
319
  def sort_next(n)
313
320
  cur_i = @params.index(@sort_param)
314
321
  next_i = cur_i + n
data/lib/vpsadmin/cli.rb CHANGED
@@ -22,4 +22,4 @@ require 'vpsadmin/cli/commands/snapshot_download'
22
22
  require 'vpsadmin/cli/commands/snapshot_send'
23
23
  require 'vpsadmin/cli/commands/backup_dataset'
24
24
  require 'vpsadmin/cli/commands/backup_vps'
25
- require 'vpsadmin/cli/commands/ip_traffic_top'
25
+ require 'vpsadmin/cli/commands/network_top'
@@ -1,5 +1,5 @@
1
1
  module VpsAdmin
2
2
  module Client
3
- VERSION = '3.0.0.master.20220809-0.4bb004b0'
3
+ VERSION = '3.0.0.master.20221118-0.ac358990'
4
4
  end
5
5
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler'
22
22
  spec.add_development_dependency 'rake'
23
23
 
24
- spec.add_runtime_dependency 'haveapi-client', '~> 0.15.1'
24
+ spec.add_runtime_dependency 'haveapi-client', '~> 0.16.1'
25
25
  spec.add_runtime_dependency 'json'
26
26
  spec.add_runtime_dependency 'curses'
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vpsadmin-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.master.20220809.pre.0.4bb004b0
4
+ version: 3.0.0.master.20221118.pre.0.ac358990
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.15.1
47
+ version: 0.16.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.15.1
54
+ version: 0.16.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +100,7 @@ files:
100
100
  - lib/vpsadmin/cli/commands/backup_dataset.rb
101
101
  - lib/vpsadmin/cli/commands/backup_vps.rb
102
102
  - lib/vpsadmin/cli/commands/base_download.rb
103
- - lib/vpsadmin/cli/commands/ip_traffic_top.rb
103
+ - lib/vpsadmin/cli/commands/network_top.rb
104
104
  - lib/vpsadmin/cli/commands/snapshot_download.rb
105
105
  - lib/vpsadmin/cli/commands/snapshot_send.rb
106
106
  - lib/vpsadmin/cli/commands/vps_migrate_many.rb