mirror of https://github.com/nicolargo/glances
Patch for Mac OS X compat
parent
4b317a6233
commit
6554c8752d
|
@ -17,6 +17,9 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
Init the Glances software
|
||||
"""
|
||||
|
||||
# Import system lib
|
||||
import sys
|
||||
|
@ -26,7 +29,7 @@ import sys
|
|||
from glances.core.glances_main import GlancesMain
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
def main():
|
||||
# Create the Glances main instance
|
||||
core = GlancesMain()
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
# Execute with
|
||||
# $ python glances/__main__.py (2.6+)
|
||||
# $ python -m glances (2.7+)
|
||||
"""
|
||||
Allow user to run Glances as a module from a dir or zip file
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
__appname__ = 'glances'
|
||||
|
||||
from ..core.glances_globals import *
|
||||
# Import Glances lib
|
||||
from glances.core.glances_globals import *
|
||||
|
||||
# Import system libs
|
||||
import os
|
||||
|
|
|
@ -27,10 +27,10 @@ import argparse
|
|||
# Import Glances libs
|
||||
# !!! Todo: rename class
|
||||
# GlancesExemple
|
||||
from ..core.glances_globals import __appname__, __version__, __author__, __license__
|
||||
from ..core.glances_globals import *
|
||||
from ..core.glances_config import Config
|
||||
from ..core.glances_stats import GlancesStats, GlancesStatsServer
|
||||
from glances.core.glances_globals import __appname__, __version__, __author__, __license__
|
||||
from glances.core.glances_globals import *
|
||||
from glances.core.glances_config import Config
|
||||
from glances.core.glances_stats import GlancesStats, GlancesStatsServer
|
||||
|
||||
class GlancesMain(object):
|
||||
"""
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Import Glances libs
|
||||
from ..core.glances_stats import GlancesStats
|
||||
from ..outputs.glances_curses import glancesCurses
|
||||
from glances.core.glances_stats import GlancesStats
|
||||
from glances.outputs.glances_curses import glancesCurses
|
||||
|
||||
|
||||
class GlancesStandalone():
|
||||
|
|
|
@ -28,8 +28,8 @@ except ImportError:
|
|||
sys.exit(1)
|
||||
|
||||
# Import Glances lib
|
||||
from ..core.glances_timer import Timer
|
||||
from ..core.glances_globals import glances_logs
|
||||
from glances.core.glances_timer import Timer
|
||||
from glances.core.glances_globals import glances_logs
|
||||
|
||||
|
||||
class glancesCurses:
|
||||
|
@ -100,7 +100,7 @@ class glancesCurses:
|
|||
if self.hascolors:
|
||||
# Colors text styles
|
||||
self.no_color = curses.color_pair(1)
|
||||
self.default_color = curses.color_pair(3) | A_BOLD
|
||||
self.default_color = curses.color_pair(3) | A_BOLD
|
||||
self.ifCAREFUL_color = curses.color_pair(4) | A_BOLD
|
||||
self.ifWARNING_color = curses.color_pair(5) | A_BOLD
|
||||
self.ifCRITICAL_color = curses.color_pair(2) | A_BOLD
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
# Import system lib
|
||||
from datetime import datetime
|
||||
|
||||
# Import Glances lib
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.core.glances_globals import glances_logs
|
||||
|
||||
|
||||
|
|
|
@ -17,17 +17,19 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
Batinfo (batterie) plugin
|
||||
"""
|
||||
|
||||
# Import system libs
|
||||
# batinfo library (optional; Linux-only)
|
||||
try:
|
||||
import batinfo
|
||||
except:
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Import Glances lib
|
||||
from glances_plugin import GlancesPlugin
|
||||
# from glances.core.glances_timer import getTimeSinceLastUpdate
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
@ -40,6 +42,8 @@ class Plugin(GlancesPlugin):
|
|||
def __init__(self):
|
||||
GlancesPlugin.__init__(self)
|
||||
|
||||
#!!! TODO: display plugin...
|
||||
|
||||
# Init the sensor class
|
||||
self.glancesgrabbat = glancesGrabBat()
|
||||
|
||||
|
@ -63,6 +67,7 @@ class glancesGrabBat:
|
|||
try:
|
||||
self.bat = batinfo.batteries()
|
||||
self.initok = True
|
||||
self.bat_list = []
|
||||
self.__update__()
|
||||
except Exception:
|
||||
self.initok = False
|
||||
|
@ -97,6 +102,6 @@ class glancesGrabBat:
|
|||
bsum = bsum + int(self.bat_list[bcpt].capacity)
|
||||
except ValueError:
|
||||
return []
|
||||
bcpt = bcpt + 1
|
||||
bcpt = bcpt + 1
|
||||
# Return the global percent
|
||||
return int(bsum / bcpt)
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
# Import system libs
|
||||
# Check for PSUtil already done in the glances_core script
|
||||
from psutil import NUM_CPUS
|
||||
from psutil import cpu_count
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
@ -41,16 +41,26 @@ class Plugin(GlancesPlugin):
|
|||
# The core number is displayed by the load plugin
|
||||
self.display_curse = False
|
||||
|
||||
# Return a dict (with both physical and log cpu number) instead of a integer
|
||||
self.stats = None
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Update core stats
|
||||
"""
|
||||
|
||||
# !!! Note: The PSUtil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
|
||||
# !!! TODO: We had to return a dict (with both hys and log cpu number) instead of a integer
|
||||
# The PSUtil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
|
||||
# Return a dict with:
|
||||
# - phys: physical cores only (hyper thread CPUs are excluded)
|
||||
# - log: logical CPUs in the system
|
||||
# Return None if undefine
|
||||
core_stats = {}
|
||||
try:
|
||||
self.stats = NUM_CPUS
|
||||
except Exception:
|
||||
self.stats = None
|
||||
core_stats["phys"] = cpu_count(logical=False)
|
||||
core_stats["log"] = cpu_count()
|
||||
except NameError:
|
||||
core_stats = None
|
||||
|
||||
self.stats = core_stats
|
||||
|
||||
return self.stats
|
||||
|
|
|
@ -26,7 +26,6 @@ from psutil import disk_io_counters
|
|||
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.core.glances_globals import is_Mac
|
||||
from glances.core.glances_timer import getTimeSinceLastUpdate
|
||||
|
||||
|
||||
|
|
|
@ -21,9 +21,8 @@
|
|||
# Import system libs
|
||||
import socket
|
||||
|
||||
# Import Glances lib
|
||||
from glances_plugin import GlancesPlugin
|
||||
# from glances.core.glances_timer import getTimeSinceLastUpdate
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
@ -70,6 +69,7 @@ class glancesGrabHDDTemp:
|
|||
self.initok = False
|
||||
else:
|
||||
self.initok = True
|
||||
self.hddtemp_list = []
|
||||
|
||||
def __update__(self):
|
||||
"""
|
||||
|
|
|
@ -88,7 +88,7 @@ class Plugin(GlancesPlugin):
|
|||
msg = "{0:4} ".format(_("LOAD"))
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
# Core number
|
||||
msg = "{0:3}-core".format(self.core_plugin.update())
|
||||
msg = "{0:3}-core".format(self.core_plugin.update()["log"])
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# New line
|
||||
ret.append(self.curse_new_line())
|
||||
|
@ -104,7 +104,7 @@ class Plugin(GlancesPlugin):
|
|||
ret.append(self.curse_add_line(msg))
|
||||
msg = "{0}".format(format(self.stats['min5'], '>5.2f'))
|
||||
ret.append(self.curse_add_line(
|
||||
msg, self.get_alert_log(self.stats['min5'], max=100 * self.core_plugin.update())))
|
||||
msg, self.get_alert_log(self.stats['min5'], max=100 * self.core_plugin.update()["log"])))
|
||||
# New line
|
||||
ret.append(self.curse_new_line())
|
||||
# 15min load
|
||||
|
@ -112,6 +112,6 @@ class Plugin(GlancesPlugin):
|
|||
ret.append(self.curse_add_line(msg))
|
||||
msg = "{0}".format(format(self.stats['min15'], '>5.2f'))
|
||||
ret.append(self.curse_add_line(
|
||||
msg, self.get_alert_log(self.stats['min15'], max=100 * self.core_plugin.update())))
|
||||
msg, self.get_alert_log(self.stats['min15'], max=100 * self.core_plugin.update()["log"])))
|
||||
|
||||
return ret
|
||||
|
|
|
@ -150,7 +150,7 @@ class Plugin(GlancesPlugin):
|
|||
msg = "{0}".format(format(self.auto_unit(self.stats['free'], '>6')))
|
||||
ret.append(self.curse_add_line(msg))
|
||||
# Cached memory usage
|
||||
if ('free' in self.stats):
|
||||
if ('cached' in self.stats):
|
||||
msg = " {0:8}".format(_("cached:"))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
msg = "{0}".format(format(self.auto_unit(self.stats['cached']), '>6'))
|
||||
|
|
|
@ -26,8 +26,6 @@ from glances.core.glances_monitor_list import monitorList as glancesMonitorList
|
|||
class Plugin(GlancesPlugin):
|
||||
"""
|
||||
Glances's monitor Plugin
|
||||
|
||||
Only for display
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
@ -42,6 +40,10 @@ class Plugin(GlancesPlugin):
|
|||
# Enter -1 to diplay bottom
|
||||
self.line_curse = 3
|
||||
|
||||
# Init stats
|
||||
self.glances_monitors = None
|
||||
self.stats = []
|
||||
|
||||
def load_limits(self, config):
|
||||
"""
|
||||
Load the monitored list from the conf file
|
||||
|
@ -54,6 +56,10 @@ class Plugin(GlancesPlugin):
|
|||
Nothing to do here
|
||||
Just return the global glances_log
|
||||
"""
|
||||
# Check if the glances_monitor instance is init
|
||||
if (self.glances_monitors == None):
|
||||
return self.stats
|
||||
|
||||
# Update the monitored list (result of command)
|
||||
self.glances_monitors.update()
|
||||
|
||||
|
@ -62,7 +68,7 @@ class Plugin(GlancesPlugin):
|
|||
|
||||
return self.stats
|
||||
|
||||
def get_alert(self, nbprocess=0, countmin=None, countmax=None):
|
||||
def get_alert(self, nbprocess=0, countmin=None, countmax=None, header="", log=False):
|
||||
# Return the alert status relative to the process number
|
||||
if (nbprocess is None):
|
||||
return 'OK'
|
||||
|
@ -88,6 +94,10 @@ class Plugin(GlancesPlugin):
|
|||
# Init the return message
|
||||
ret = []
|
||||
|
||||
# Stats exist ?
|
||||
if (self.stats == []):
|
||||
return ret
|
||||
|
||||
# Build the string message
|
||||
for m in self.stats:
|
||||
msg = "{0:<16} ".format(str(m['description']))
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
# Import system libs
|
||||
from datetime import datetime
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
|
|
@ -17,13 +17,16 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
CPU stats (per cpu)
|
||||
"""
|
||||
|
||||
# Import system libs
|
||||
# Check for PSUtil already done in the glances_core script
|
||||
from psutil import cpu_times
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
@ -45,6 +48,11 @@ class Plugin(GlancesPlugin):
|
|||
# Enter -1 to diplay bottom
|
||||
self.line_curse = 1
|
||||
|
||||
# Init stats
|
||||
self.stats = []
|
||||
self.percputime_total_new = []
|
||||
self.percputime_new = []
|
||||
|
||||
def update(self):
|
||||
"""
|
||||
Update Per CPU stats
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.core.glances_globals import glances_processes, process_auto_by
|
||||
|
||||
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Import sys libs
|
||||
from datetime import timedelta
|
||||
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.core.glances_globals import glances_processes, process_auto_by
|
||||
|
||||
|
||||
|
@ -73,7 +75,7 @@ class Plugin(GlancesPlugin):
|
|||
sort_style = 'BOLD'
|
||||
|
||||
# Header
|
||||
msg = "{0:15}".format(_(""))
|
||||
msg = "{0:15}".format(" ")
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = "{0:>6}".format(_("CPU%"))
|
||||
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_percent' else 'DEFAULT'))
|
||||
|
@ -151,20 +153,26 @@ class Plugin(GlancesPlugin):
|
|||
msg = " "
|
||||
msg = "{0:>9}".format(msg)
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
# IO read
|
||||
io_rs = (p['io_counters'][0] - p['io_counters'][2]) / p['time_since_update']
|
||||
if (io_rs == 0):
|
||||
msg = "{0:>6}".format("0")
|
||||
# IO read/write
|
||||
if ('io_counters' in p):
|
||||
# IO read
|
||||
io_rs = (p['io_counters'][0] - p['io_counters'][2]) / p['time_since_update']
|
||||
if (io_rs == 0):
|
||||
msg = "{0:>6}".format("0")
|
||||
else:
|
||||
msg = "{0:>6}".format(self.auto_unit(io_rs, low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
# IO write
|
||||
io_ws = (p['io_counters'][1] - p['io_counters'][3]) / p['time_since_update']
|
||||
if (io_ws == 0):
|
||||
msg = "{0:>6}".format("0")
|
||||
else:
|
||||
msg = "{0:>6}".format(self.auto_unit(io_ws, low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
else:
|
||||
msg = "{0:>6}".format(self.auto_unit(io_rs, low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
# IO write
|
||||
io_ws = (p['io_counters'][1] - p['io_counters'][3]) / p['time_since_update']
|
||||
if (io_ws == 0):
|
||||
msg = "{0:>6}".format("0")
|
||||
else:
|
||||
msg = "{0:>6}".format(self.auto_unit(io_ws, low_precision=False))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
msg = "{0:>6}".format("?")
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
# Command line
|
||||
msg = " {0}".format(p['cmdline'])
|
||||
ret.append(self.curse_add_line(msg, optional=True))
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
# Check for PSUtil already done in the glances_core script
|
||||
from psutil import __version__ as __psutil_version__
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
@ -43,5 +43,5 @@ class Plugin(GlancesPlugin):
|
|||
# Return PsUtil version as a tuple
|
||||
try:
|
||||
self.stats = tuple([int(num) for num in __psutil_version__.split('.')])
|
||||
except Exception:
|
||||
except NameError:
|
||||
self.stats = None
|
||||
|
|
|
@ -27,8 +27,8 @@ except ImportError:
|
|||
|
||||
# Import Glances lib
|
||||
from glances.core.glances_globals import is_python3
|
||||
from glances_hddtemp import Plugin as HddTempPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
# from glances.core.glances_timer import getTimeSinceLastUpdate
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ Glances system plugin
|
|||
import os
|
||||
import platform
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ except:
|
|||
|
||||
from datetime import datetime
|
||||
|
||||
# from ..plugins.glances_plugin import GlancesPlugin
|
||||
from glances_plugin import GlancesPlugin
|
||||
# Import Glances libs
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
|
@ -57,12 +57,14 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
try:
|
||||
# For PsUtil >= 0.7.0
|
||||
self.uptime = datetime.now() - datetime.fromtimestamp(get_boot_time())
|
||||
except:
|
||||
self.uptime = datetime.now() - datetime.fromtimestamp(BOOT_TIME)
|
||||
uptime = datetime.now() - datetime.fromtimestamp(get_boot_time())
|
||||
except NameError:
|
||||
uptime = datetime.now() - datetime.fromtimestamp(BOOT_TIME)
|
||||
else:
|
||||
uptime = '.UNKNOW'
|
||||
|
||||
# Convert uptime to string (because datetime is not JSONifi)
|
||||
self.stats = str(self.uptime).split('.')[0]
|
||||
self.stats = str(uptime).split('.')[0]
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue