virtop 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/virtop +17 -11
- data/lib/libvirt/connect.rb +44 -1
- data/lib/libvirt/domain.rb +7 -0
- data/lib/virtop.rb +1 -1
- metadata +7 -7
data/bin/virtop
CHANGED
@@ -78,6 +78,7 @@ begin
|
|
78
78
|
Ncurses.noecho
|
79
79
|
Ncurses.halfdelay( 10 )
|
80
80
|
|
81
|
+
# Default sorting by first column (domain name).
|
81
82
|
sortBy = 0
|
82
83
|
|
83
84
|
while( true )
|
@@ -86,25 +87,23 @@ begin
|
|
86
87
|
n.intrflush( false )
|
87
88
|
n.keypad( true )
|
88
89
|
|
89
|
-
|
90
|
-
|
90
|
+
# Add topmost meta information lines to ncurses screen.
|
91
91
|
n.addstr(
|
92
92
|
c.hostname.upcase +
|
93
93
|
"\n" +
|
94
|
-
' cores ' +
|
95
|
-
' cpus '
|
96
|
-
'
|
97
|
-
' arch '
|
94
|
+
' cores ' + c.cores +
|
95
|
+
' cpus ' + c.cpus +
|
96
|
+
' ghz ' + c.ghz +
|
97
|
+
' arch ' + c.arch +
|
98
98
|
"\n" +
|
99
|
-
' mem '
|
100
|
-
'
|
101
|
-
' sockets ' + info.sockets.to_s +
|
102
|
-
' threads ' + info.threads.to_s +
|
99
|
+
' mem ' + c.mem +
|
100
|
+
' free ' + c.memfree +
|
103
101
|
"\n" +
|
104
|
-
' version ' + c.
|
102
|
+
' version ' + c.version +
|
105
103
|
"\n\n"
|
106
104
|
)
|
107
105
|
|
106
|
+
# Initialize table (columns).
|
108
107
|
t = Table.new(
|
109
108
|
'NAME',
|
110
109
|
'STATE',
|
@@ -114,6 +113,7 @@ begin
|
|
114
113
|
'CPU_TIME'
|
115
114
|
)
|
116
115
|
|
116
|
+
# Add information of each domain to table.
|
117
117
|
c.domains.each do |d|
|
118
118
|
t.add_row(
|
119
119
|
d.name,
|
@@ -125,16 +125,22 @@ begin
|
|
125
125
|
)
|
126
126
|
end
|
127
127
|
|
128
|
+
# Sort table by chosen column.
|
128
129
|
t.sort_by( sortBy )
|
129
130
|
|
131
|
+
# Convert table to array of padded strings and add them to ncurses
|
132
|
+
# screen.
|
130
133
|
t.format.each do |line|
|
131
134
|
n.addstr( line )
|
132
135
|
end
|
133
136
|
|
137
|
+
# Wait for single char user input.
|
134
138
|
char = n.getch
|
135
139
|
case( char )
|
140
|
+
# Key '1' till '6'
|
136
141
|
when 49..54
|
137
142
|
sortBy = char - 49
|
143
|
+
# Key 'q'
|
138
144
|
when 113
|
139
145
|
raise( LetsExit )
|
140
146
|
end
|
data/lib/libvirt/connect.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Extend Libvirt::Connect with a method which returns all available domains as
|
2
|
-
# an array.
|
2
|
+
# an array and several methods to access the host info more easily.
|
3
3
|
class Libvirt::Connect
|
4
|
+
# Returns array of domain objects.
|
4
5
|
def domains
|
5
6
|
ret = Array.new
|
6
7
|
|
@@ -12,4 +13,46 @@ class Libvirt::Connect
|
|
12
13
|
|
13
14
|
ret
|
14
15
|
end
|
16
|
+
|
17
|
+
# Returns number of cores as string.
|
18
|
+
def cores
|
19
|
+
self.node_get_info.cores.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns number of CPUs as string.
|
23
|
+
def cpus
|
24
|
+
self.node_get_info.cpus.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns clock speed in GHz.
|
28
|
+
def ghz
|
29
|
+
"%.2f" % ( self.node_get_info.mhz / 1000.0 )
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns CPU architecture.
|
33
|
+
def arch
|
34
|
+
self.node_get_info.model
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns total memory in mebibytes as string.
|
38
|
+
def mem
|
39
|
+
( self.node_get_info.memory / 1024 ).to_s + 'M'
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns memory which is not allocated to virtual machines in mebibytes as
|
43
|
+
# string.
|
44
|
+
def memfree
|
45
|
+
memUsed = 0
|
46
|
+
|
47
|
+
self.domains.each do |domain|
|
48
|
+
memUsed += domain.info.memory
|
49
|
+
end
|
50
|
+
|
51
|
+
( ( self.node_get_info.memory - memUsed ) / 1024 ).to_s + 'M'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the libvirt version number.
|
55
|
+
def version
|
56
|
+
self.libversion.to_s
|
57
|
+
end
|
15
58
|
end
|
data/lib/libvirt/domain.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# Extend Libvirt::Domain with different methods for human readable display of
|
2
2
|
# the domain state.
|
3
3
|
class Libvirt::Domain
|
4
|
+
# Default string representation of domain object is the domain's name.
|
4
5
|
def to_s
|
5
6
|
self.name
|
6
7
|
end
|
7
8
|
|
9
|
+
# Return state as string symbol.
|
8
10
|
def state
|
9
11
|
case( self.info.state )
|
10
12
|
when 1
|
@@ -16,18 +18,23 @@ class Libvirt::Domain
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
# Return current memory assignment in mebibytes as string.
|
19
22
|
def mem
|
20
23
|
( self.info.memory / 1024 ).to_s + "M"
|
21
24
|
end
|
22
25
|
|
26
|
+
# Return maximum memory assignment in mebibytes as string.
|
23
27
|
def mem_max
|
24
28
|
( self.info.max_mem / 1024 ).to_s + "M"
|
25
29
|
end
|
26
30
|
|
31
|
+
# Return the number of assigned virtual CPUs as string.
|
27
32
|
def cpu_num
|
28
33
|
self.info.nr_virt_cpu.to_s
|
29
34
|
end
|
30
35
|
|
36
|
+
# Return time the virtual domain's CPU was scheduled as string formatted
|
37
|
+
# d-hh:mm:ss.
|
31
38
|
def cpu_time
|
32
39
|
t = self.info.cpu_time / 10**9
|
33
40
|
|
data/lib/virtop.rb
CHANGED
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: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- henning mueller
|
@@ -44,11 +44,11 @@ extra_rdoc_files: []
|
|
44
44
|
|
45
45
|
files:
|
46
46
|
- bin/virtop
|
47
|
-
- lib/libvirt/connect.rb
|
48
|
-
- lib/libvirt/domain.rb
|
49
|
-
- lib/virtop.rb
|
50
|
-
- lib/virtop/table.rb
|
51
47
|
- lib/virtop/letsexit.rb
|
48
|
+
- lib/virtop/table.rb
|
49
|
+
- lib/virtop.rb
|
50
|
+
- lib/libvirt/domain.rb
|
51
|
+
- lib/libvirt/connect.rb
|
52
52
|
- README.rdoc
|
53
53
|
has_rdoc: true
|
54
54
|
homepage:
|