mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
New xm uptime command.
From Alex Brett <alex.brett@xensource.com> Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
4db258f902
commit
7857edbe76
2 files changed
+62
No files matched your search
@@ -1090,6 +1090,9 @@ The \path{xm list} command also supports a long output format when the
|
||||
\path{-l} switch is used. This outputs the full details of the
|
||||
running domains in \xend's SXP configuration format.
|
||||
|
||||
If you want to know how long your domains have been running for, then
|
||||
you can use the \verb_# xm uptime_ command.
|
||||
|
||||
|
||||
You can get access to the console of a particular domain using
|
||||
the \verb_# xm console_ command (e.g.\ \verb_# xm console myVM_).
|
||||
|
||||
@@ -31,6 +31,7 @@ import warnings
|
||||
warnings.filterwarnings('ignore', category=FutureWarning)
|
||||
import xmlrpclib
|
||||
import traceback
|
||||
import datetime
|
||||
|
||||
import xen.xend.XendProtocol
|
||||
|
||||
@@ -70,6 +71,7 @@ save_help = "save <DomId> <File> Save domain state (and config)
|
||||
shutdown_help ="shutdown <DomId> [-w][-a][-R|-H] Shutdown a domain"
|
||||
top_help = "top Monitor system and domains in real-time"
|
||||
unpause_help = "unpause <DomId> Unpause a paused domain"
|
||||
uptime_help = "uptime [-s|--short] [DomId, ...] List uptime for domains"
|
||||
|
||||
help_spacer = """
|
||||
"""
|
||||
@@ -149,6 +151,7 @@ short_command_list = [
|
||||
"shutdown",
|
||||
"top",
|
||||
"unpause",
|
||||
"uptime",
|
||||
"vcpu-set",
|
||||
]
|
||||
|
||||
@@ -172,6 +175,7 @@ domain_commands = [
|
||||
"sysrq",
|
||||
"top",
|
||||
"unpause",
|
||||
"uptime",
|
||||
"vcpu-list",
|
||||
"vcpu-pin",
|
||||
"vcpu-set",
|
||||
@@ -412,6 +416,7 @@ def parse_doms_info(info):
|
||||
'vcpus' : get_info('online_vcpus', int, 0),
|
||||
'state' : get_info('state', str, '??'),
|
||||
'cpu_time' : get_info('cpu_time', float, 0),
|
||||
'up_time' : get_info('up_time', float, -1),
|
||||
'seclabel' : security.get_security_printlabel(info),
|
||||
}
|
||||
|
||||
@@ -818,6 +823,59 @@ def xm_console(args):
|
||||
domid = int(sxp.child_value(info, 'domid', '-1'))
|
||||
console.execConsole(domid)
|
||||
|
||||
def xm_uptime(args):
|
||||
short_mode = 0
|
||||
|
||||
try:
|
||||
(options, params) = getopt.gnu_getopt(args, 's', ['short'])
|
||||
except getopt.GetoptError, opterr:
|
||||
err(opterr)
|
||||
sys.exit(1)
|
||||
|
||||
for (k, v) in options:
|
||||
if k in ['-s', '--short']:
|
||||
short_mode = 1
|
||||
|
||||
doms = getDomains(params)
|
||||
|
||||
if short_mode == 0:
|
||||
print 'Name ID Uptime'
|
||||
|
||||
for dom in doms:
|
||||
d = parse_doms_info(dom)
|
||||
if d['dom'] > 0:
|
||||
uptime = int(round(d['up_time']))
|
||||
else:
|
||||
f=open('/proc/uptime', 'r')
|
||||
upfile = f.read()
|
||||
uptime = int(round(float(upfile.split(' ')[0])))
|
||||
f.close()
|
||||
|
||||
days = int(uptime / 86400)
|
||||
uptime -= (days * 86400)
|
||||
hours = int(uptime / 3600)
|
||||
uptime -= (hours * 3600)
|
||||
minutes = int(uptime / 60)
|
||||
uptime -= (minutes * 60)
|
||||
seconds = uptime
|
||||
|
||||
upstring = ""
|
||||
if days > 0:
|
||||
upstring += str(days) + " day"
|
||||
if days > 1:
|
||||
upstring += "s"
|
||||
upstring += ", "
|
||||
upstring += '%(hours)2d:%(minutes)02d' % vars()
|
||||
|
||||
if short_mode:
|
||||
now = datetime.datetime.now()
|
||||
upstring = now.strftime(" %H:%M:%S") + " up " + upstring
|
||||
upstring += ", " + d['name'] + " (" + str(d['dom']) + ")"
|
||||
else:
|
||||
upstring += ':%(seconds)02d' % vars()
|
||||
upstring = ("%(name)-32s %(dom)3d " % d) + upstring
|
||||
|
||||
print upstring
|
||||
|
||||
def xm_top(args):
|
||||
arg_check(args, "top", 0)
|
||||
@@ -1117,6 +1175,7 @@ commands = {
|
||||
"save": xm_save,
|
||||
"reboot": xm_reboot,
|
||||
"shutdown": xm_shutdown,
|
||||
"uptime": xm_uptime,
|
||||
"list": xm_list,
|
||||
# memory commands
|
||||
"mem-max": xm_mem_max,
|
||||
|
||||