virtop 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/virtop +22 -13
- data/lib/libvirt/connect.rb +15 -0
- data/lib/libvirt/domain.rb +41 -0
- data/lib/virtop.rb +7 -1
- data/lib/virtop/letsexit.rb +1 -1
- data/lib/virtop/table.rb +48 -0
- metadata +7 -6
- data/lib/virtop/libvirt/connect.rb +0 -17
- data/lib/virtop/libvirt/domain.rb +0 -48
data/bin/virtop
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Require
|
4
|
-
# not be loaded.
|
3
|
+
# Require uri module and print out exception message if it could not be loaded.
|
5
4
|
begin
|
6
|
-
require( 'libvirt' )
|
7
5
|
require( 'uri' )
|
8
6
|
rescue LoadError => e
|
9
7
|
$stderr.puts( e.message )
|
@@ -27,9 +25,10 @@ EOF
|
|
27
25
|
exit( 1 )
|
28
26
|
end
|
29
27
|
|
30
|
-
# Require virtop module.
|
28
|
+
# Require and include virtop module. It will require libvirt.
|
31
29
|
$:.unshift( File.join( File.dirname( __FILE__ ), '../lib' ) )
|
32
30
|
require( 'virtop' )
|
31
|
+
include Virtop
|
33
32
|
|
34
33
|
# Connection URL will be qemu:///system if nothing else is given as the first
|
35
34
|
# parameter.
|
@@ -68,22 +67,32 @@ begin
|
|
68
67
|
n.intrflush( false )
|
69
68
|
n.keypad( true )
|
70
69
|
|
71
|
-
|
72
|
-
|
70
|
+
t = Table.new(
|
71
|
+
'name',
|
72
|
+
'state',
|
73
|
+
'mem',
|
74
|
+
'mem_max',
|
75
|
+
'cpu_num',
|
76
|
+
'cpu_time'
|
73
77
|
)
|
74
78
|
|
75
79
|
c.domains.each do |domain|
|
76
|
-
|
77
|
-
domain.name
|
78
|
-
domain.state
|
79
|
-
domain.mem
|
80
|
-
domain.mem_max
|
81
|
-
domain.cpu_num
|
82
|
-
domain.cpu_time
|
80
|
+
t.add_row(
|
81
|
+
domain.name,
|
82
|
+
domain.state,
|
83
|
+
domain.mem,
|
84
|
+
domain.mem_max,
|
85
|
+
domain.cpu_num,
|
86
|
+
domain.cpu_time
|
83
87
|
)
|
84
88
|
end
|
85
89
|
|
90
|
+
t.format.each do |line|
|
91
|
+
n.addstr( line )
|
92
|
+
end
|
93
|
+
|
86
94
|
n.refresh
|
95
|
+
|
87
96
|
raise( LetsExit ) if( n.getch == 113 )
|
88
97
|
end
|
89
98
|
rescue LetsExit
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Extend Libvirt::Connect with a method which returns all available domains as
|
2
|
+
# an array.
|
3
|
+
class Libvirt::Connect
|
4
|
+
def domains
|
5
|
+
ret = Array.new
|
6
|
+
|
7
|
+
self.list_domains.each do |id|
|
8
|
+
ret.push(
|
9
|
+
self.lookup_domain_by_id( id )
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
ret
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Extend Libvirt::Domain with different methods for human readable display of
|
2
|
+
# the domain state.
|
3
|
+
class Libvirt::Domain
|
4
|
+
def to_s
|
5
|
+
self.name
|
6
|
+
end
|
7
|
+
|
8
|
+
def state
|
9
|
+
case( self.info.state )
|
10
|
+
when 1
|
11
|
+
">"
|
12
|
+
when 3
|
13
|
+
"||"
|
14
|
+
else
|
15
|
+
"?"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def mem
|
20
|
+
( self.info.memory / 1024 ).to_s + "M"
|
21
|
+
end
|
22
|
+
|
23
|
+
def mem_max
|
24
|
+
( self.info.max_mem / 1024 ).to_s + "M"
|
25
|
+
end
|
26
|
+
|
27
|
+
def cpu_num
|
28
|
+
self.info.nr_virt_cpu.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def cpu_time
|
32
|
+
t = self.info.cpu_time / 10**9
|
33
|
+
|
34
|
+
s = ( t % 60 ).to_s
|
35
|
+
m = ( t / 60 % 60 ).to_s
|
36
|
+
h = ( t / 60 / 60 % 24 ).to_s
|
37
|
+
d = ( t / 60 / 60 / 24 % 365 ).to_s
|
38
|
+
|
39
|
+
"%i-%02i:%02i:%02i" % [d, h, m, s]
|
40
|
+
end
|
41
|
+
end
|
data/lib/virtop.rb
CHANGED
data/lib/virtop/letsexit.rb
CHANGED
data/lib/virtop/table.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class Virtop::Table
|
2
|
+
def initialize( *args )
|
3
|
+
@header = args
|
4
|
+
@rows = []
|
5
|
+
@widths = [0] * args.size
|
6
|
+
end
|
7
|
+
|
8
|
+
def header
|
9
|
+
@header.to_s + "\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_row( *args )
|
13
|
+
raise( Exception ) if( args.size != @header.size )
|
14
|
+
@rows.push( args )
|
15
|
+
end
|
16
|
+
|
17
|
+
def each_row
|
18
|
+
@rows.each do |row|
|
19
|
+
yield( row.to_s )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def format
|
24
|
+
update_widths!
|
25
|
+
|
26
|
+
a = []
|
27
|
+
|
28
|
+
( [ @header ] + @rows ).each do |row|
|
29
|
+
line = ''
|
30
|
+
@header.size.times do |i|
|
31
|
+
line += row[i].ljust( @widths[i] + 2 )
|
32
|
+
end
|
33
|
+
a.push( line + "\n" )
|
34
|
+
end
|
35
|
+
|
36
|
+
a.insert( 1, "\n" )
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def update_widths!
|
42
|
+
@header.size.times do |i|
|
43
|
+
( [ @header ] + @rows ).each do |row|
|
44
|
+
@widths[i] = row[i].size if( @widths[i] < row[i].size)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- henning mueller
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-23 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -45,9 +45,10 @@ extra_rdoc_files: []
|
|
45
45
|
files:
|
46
46
|
- bin/virtop
|
47
47
|
- lib/virtop.rb
|
48
|
-
- lib/virtop/libvirt/connect.rb
|
49
|
-
- lib/virtop/libvirt/domain.rb
|
50
48
|
- lib/virtop/letsexit.rb
|
49
|
+
- lib/virtop/table.rb
|
50
|
+
- lib/libvirt/connect.rb
|
51
|
+
- lib/libvirt/domain.rb
|
51
52
|
- README
|
52
53
|
has_rdoc: true
|
53
54
|
homepage:
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Extend Libvirt::Connect with a method which returns all available domains as
|
2
|
-
# an array.
|
3
|
-
module Libvirt
|
4
|
-
class Connect
|
5
|
-
def domains
|
6
|
-
ret = Array.new
|
7
|
-
|
8
|
-
self.list_domains.each do |id|
|
9
|
-
ret.push(
|
10
|
-
self.lookup_domain_by_id( id )
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
ret
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# Extend Libvirt::Domain with different methods for human readable display of
|
2
|
-
# the domain state.
|
3
|
-
module Libvirt
|
4
|
-
class Domain
|
5
|
-
def to_s
|
6
|
-
self.name
|
7
|
-
end
|
8
|
-
|
9
|
-
def state
|
10
|
-
case( self.info.state )
|
11
|
-
when 1
|
12
|
-
">"
|
13
|
-
when 3
|
14
|
-
"||"
|
15
|
-
else
|
16
|
-
"?"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def mem
|
21
|
-
( self.info.memory / 1024 ).to_s + "M"
|
22
|
-
end
|
23
|
-
|
24
|
-
def mem_max
|
25
|
-
( self.info.max_mem / 1024 ).to_s + "M"
|
26
|
-
end
|
27
|
-
|
28
|
-
def cpu_num
|
29
|
-
self.info.nr_virt_cpu.to_s
|
30
|
-
end
|
31
|
-
|
32
|
-
def cpu_time
|
33
|
-
t = self.info.cpu_time / 10**9
|
34
|
-
|
35
|
-
s = ( t % 60 ).to_s
|
36
|
-
m = ( t / 60 % 60 ).to_s
|
37
|
-
h = ( t / 60 / 60 % 24 ).to_s
|
38
|
-
d = ( t / 60 / 60 / 24 % 365 ).to_s
|
39
|
-
|
40
|
-
str = d != '0' ? d + '-' : ''
|
41
|
-
str += h != '0' ? "%02i:" % h : ''
|
42
|
-
str += "%02i:" % m
|
43
|
-
str += s
|
44
|
-
|
45
|
-
str
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|