virtop 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/virtop +119 -0
- metadata +96 -0
data/bin/virtop
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'libvirt'
|
5
|
+
require 'ncurses'
|
6
|
+
require 'uri'
|
7
|
+
rescue LoadError => e
|
8
|
+
$stderr.puts( e.message )
|
9
|
+
exit( 1 )
|
10
|
+
end
|
11
|
+
|
12
|
+
if( ARGV.size < 1 )
|
13
|
+
url = 'qemu:///system'
|
14
|
+
else
|
15
|
+
uri = URI.parse( ARGV.first )
|
16
|
+
|
17
|
+
if( uri.scheme == 'qemu+ssh' and uri.path == '' )
|
18
|
+
raise( Exception.new( 'invalid url specified' ) )
|
19
|
+
else
|
20
|
+
url = uri.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class LetsExit < Exception
|
25
|
+
end
|
26
|
+
|
27
|
+
module Libvirt
|
28
|
+
class Connect
|
29
|
+
def domains
|
30
|
+
ret = Array.new
|
31
|
+
|
32
|
+
self.list_domains.each do |id|
|
33
|
+
ret.push(
|
34
|
+
self.lookup_domain_by_id( id )
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
ret
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Domain
|
43
|
+
def to_s
|
44
|
+
self.name
|
45
|
+
end
|
46
|
+
|
47
|
+
def state
|
48
|
+
case( self.info.state )
|
49
|
+
when 1
|
50
|
+
">"
|
51
|
+
when 3
|
52
|
+
"||"
|
53
|
+
else
|
54
|
+
"?"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def mem
|
59
|
+
( self.info.memory / 1024 ).to_s + "M"
|
60
|
+
end
|
61
|
+
|
62
|
+
def mem_max
|
63
|
+
( self.info.max_mem / 1024 ).to_s + "M"
|
64
|
+
end
|
65
|
+
|
66
|
+
def cpu_num
|
67
|
+
self.info.nr_virt_cpu.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def cpu_time
|
71
|
+
self.info.cpu_time.to_s
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
begin
|
77
|
+
c = Libvirt::open( url )
|
78
|
+
rescue Libvirt::ConnectionError
|
79
|
+
$stderr.puts( 'connection failed' )
|
80
|
+
exit( 1 )
|
81
|
+
end
|
82
|
+
|
83
|
+
begin
|
84
|
+
n = Ncurses.initscr
|
85
|
+
|
86
|
+
Ncurses.cbreak
|
87
|
+
Ncurses.noecho
|
88
|
+
Ncurses.halfdelay( 10 )
|
89
|
+
|
90
|
+
while( true )
|
91
|
+
Ncurses.clear
|
92
|
+
|
93
|
+
n.intrflush( false )
|
94
|
+
n.keypad( true )
|
95
|
+
|
96
|
+
n.addstr(
|
97
|
+
"name\t\tstate\tmem\tmem_max\tcpu_num\tcpu_time\n\n"
|
98
|
+
)
|
99
|
+
|
100
|
+
c.domains.each do |domain|
|
101
|
+
n.addstr(
|
102
|
+
domain.name + "\t" +
|
103
|
+
domain.state + "\t" +
|
104
|
+
domain.mem + "\t" +
|
105
|
+
domain.mem_max + "\t" +
|
106
|
+
domain.cpu_num + "\t" +
|
107
|
+
domain.cpu_time + "\n"
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
n.refresh
|
112
|
+
raise( LetsExit ) if( n.getch == 113 )
|
113
|
+
end
|
114
|
+
rescue LetsExit
|
115
|
+
ensure
|
116
|
+
Ncurses.echo
|
117
|
+
Ncurses.cbreak
|
118
|
+
Ncurses.endwin
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virtop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- henning mueller
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-05-28 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ruby-libvirt
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
version: 0.1.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: ncurses
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: virtop provides an overview of virtual machines runned with a solution abstracted by libvirt.
|
52
|
+
email: henning@orgizm.net
|
53
|
+
executables:
|
54
|
+
- virtop
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- bin/virtop
|
61
|
+
has_rdoc: true
|
62
|
+
homepage:
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.7
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: The top for virtual machines (libvirt).
|
95
|
+
test_files: []
|
96
|
+
|