Made psutil optional for the use of the @system command on Windows.
This commit is contained in:
parent
5389373776
commit
9e8c307bc4
2 changed files with 22 additions and 20 deletions
|
|
@ -668,33 +668,35 @@ class CmdServerLoad(MuxCommand):
|
||||||
|
|
||||||
os_windows = os.name == "nt"
|
os_windows = os.name == "nt"
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
loadtable = EvTable("property", "statistic", align="l")
|
|
||||||
|
|
||||||
if os_windows:
|
if os_windows:
|
||||||
# Windows requires the psutil module to get statistics like this
|
# Windows requires the psutil module to get statistics like this
|
||||||
try:
|
try:
|
||||||
import psutil
|
import psutil
|
||||||
|
has_psutil = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
string = "The psutil module is not installed: Process " \
|
has_psutil = False
|
||||||
" listings are only available under Linux/Unix."
|
|
||||||
self.caller.msg(string)
|
|
||||||
return
|
|
||||||
|
|
||||||
loadavg = psutil.cpu_percent()
|
if has_psutil:
|
||||||
_mem = psutil.virtual_memory()
|
loadavg = psutil.cpu_percent()
|
||||||
rmem = _mem.used
|
_mem = psutil.virtual_memory()
|
||||||
vmem = "N/A on Windows"
|
rmem = _mem.used
|
||||||
pmem = _mem.percent
|
vmem = "N/A on Windows"
|
||||||
rusage = "N/A on Windows"
|
pmem = _mem.percent
|
||||||
|
rusage = "N/A on Windows"
|
||||||
|
|
||||||
if "mem" in self.switches:
|
if "mem" in self.switches:
|
||||||
string = "Memory usage: {w%g{n MB (%g%%)"
|
string = "Memory usage: {w%g{n MB (%g%%)"
|
||||||
self.caller.msg(string % (rmem, pmem))
|
self.caller.msg(string % (rmem, pmem))
|
||||||
return
|
return
|
||||||
# Display table
|
# Display table
|
||||||
loadtable.add_row("Server load", "%g" % loadavg)
|
loadtable = EvTable("property", "statistic", align="l")
|
||||||
loadtable.add_row("Process ID", "%g" % pid),
|
loadtable.add_row("Server load", "%g" % loadavg)
|
||||||
loadtable.add_row("Memory usage","%g MB (%g%%)" % (rmem, pmem))
|
loadtable.add_row("Process ID", "%g" % pid),
|
||||||
|
loadtable.add_row("Memory usage","%g MB (%g%%)" % (rmem, pmem))
|
||||||
|
else:
|
||||||
|
loadtable = "Not available on Windows without 'psutil' library " \
|
||||||
|
"(install with {wpip install psutil{n)."
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Linux / BSD (OSX)
|
# Linux / BSD (OSX)
|
||||||
|
|
@ -715,6 +717,7 @@ class CmdServerLoad(MuxCommand):
|
||||||
self.caller.msg(string % (rmem, pmem, vmem))
|
self.caller.msg(string % (rmem, pmem, vmem))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
loadtable = EvTable("property", "statistic", align="l")
|
||||||
loadtable.add_row("Server load (1 min)", "%g" % loadavg)
|
loadtable.add_row("Server load (1 min)", "%g" % loadavg)
|
||||||
loadtable.add_row("Process ID", "%g" % pid),
|
loadtable.add_row("Process ID", "%g" % pid),
|
||||||
loadtable.add_row("Memory usage","%g MB (%g%%)" % (rmem, pmem))
|
loadtable.add_row("Memory usage","%g MB (%g%%)" % (rmem, pmem))
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
# windows specific
|
# windows specific
|
||||||
pypiwin32
|
pypiwin32
|
||||||
psutil >= 2.2
|
|
||||||
# general
|
# general
|
||||||
django >= 1.7
|
django >= 1.7
|
||||||
twisted >= 12.0
|
twisted >= 12.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue