mirror of https://github.com/nicolargo/glances
Update log message
parent
c1a4022475
commit
9584749532
|
@ -58,16 +58,22 @@ def __signal_handler(signal, frame):
|
||||||
|
|
||||||
def end():
|
def end():
|
||||||
"""Stop Glances."""
|
"""Stop Glances."""
|
||||||
logger.info("Stop Glances (with CTRL-C)")
|
|
||||||
if core.is_standalone():
|
if core.is_standalone():
|
||||||
# Stop the standalone (CLI)
|
# Stop the standalone (CLI)
|
||||||
standalone.end()
|
standalone.end()
|
||||||
|
logger.info("Stop Glances (with CTRL-C)")
|
||||||
elif core.is_client():
|
elif core.is_client():
|
||||||
# Stop the client
|
# Stop the client
|
||||||
client.end()
|
client.end()
|
||||||
|
logger.info("Stop Glances client (with CTRL-C)")
|
||||||
elif core.is_server():
|
elif core.is_server():
|
||||||
# Stop the server
|
# Stop the server
|
||||||
server.end()
|
server.end()
|
||||||
|
logger.info("Stop Glances server (with CTRL-C)")
|
||||||
|
elif core.is_webserver():
|
||||||
|
# Stop the Web server
|
||||||
|
webserver.end()
|
||||||
|
logger.info("Stop Glances web server(with CTRL-C)")
|
||||||
|
|
||||||
# The end...
|
# The end...
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -84,7 +90,7 @@ def main():
|
||||||
gettext.install(gettext_domain, locale_dir)
|
gettext.install(gettext_domain, locale_dir)
|
||||||
|
|
||||||
# Share global var
|
# Share global var
|
||||||
global core, standalone, client, server
|
global core, standalone, client, server, webserver
|
||||||
|
|
||||||
# Create the Glances main instance
|
# Create the Glances main instance
|
||||||
core = GlancesMain()
|
core = GlancesMain()
|
||||||
|
@ -118,7 +124,7 @@ def main():
|
||||||
|
|
||||||
# Test if client and server are in the same major version
|
# Test if client and server are in the same major version
|
||||||
if not client.login():
|
if not client.login():
|
||||||
print(_("Error: The server version is not compatible with the client"))
|
logger.critical(_("The server version is not compatible with the client"))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# Start the client loop
|
# Start the client loop
|
||||||
|
|
|
@ -29,7 +29,7 @@ except ImportError: # Python 2
|
||||||
from xmlrpclib import ServerProxy, ProtocolError, Fault
|
from xmlrpclib import ServerProxy, ProtocolError, Fault
|
||||||
|
|
||||||
# Import Glances libs
|
# Import Glances libs
|
||||||
from glances.core.glances_globals import version
|
from glances.core.glances_globals import version, logger
|
||||||
from glances.core.glances_stats import GlancesStatsClient
|
from glances.core.glances_stats import GlancesStatsClient
|
||||||
from glances.outputs.glances_curses import GlancesCurses
|
from glances.outputs.glances_curses import GlancesCurses
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class GlancesClient(object):
|
||||||
try:
|
try:
|
||||||
self.client = ServerProxy(uri)
|
self.client = ServerProxy(uri)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(_("Error: Couldn't create socket {0}: {1}").format(uri, e))
|
logger.error(_("Couldn't create socket {0}: {1}").format(uri, e))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
def set_mode(self, mode='glances'):
|
def set_mode(self, mode='glances'):
|
||||||
|
@ -88,14 +88,17 @@ class GlancesClient(object):
|
||||||
client_version = self.client.init()
|
client_version = self.client.init()
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
# Fallback to SNMP
|
# Fallback to SNMP
|
||||||
print (_("Info: Connection to Glances server failed. Trying fallback to SNMP..."))
|
logger.error(_("Connection to Glances server failed"))
|
||||||
self.set_mode('snmp')
|
self.set_mode('snmp')
|
||||||
|
fallbackmsg = _("Trying fallback to SNMP...")
|
||||||
|
print(fallbackmsg)
|
||||||
|
logger.info(fallbackmsg)
|
||||||
except ProtocolError as err:
|
except ProtocolError as err:
|
||||||
# Others errors
|
# Others errors
|
||||||
if str(err).find(" 401 ") > 0:
|
if str(err).find(" 401 ") > 0:
|
||||||
print(_("Error: Connection to server failed: Bad password"))
|
logger.error(_("Connection to server failed (Bad password)"))
|
||||||
else:
|
else:
|
||||||
print(_("Error: Connection to server failed: {0}").format(err))
|
logger.error(_("Connection to server failed ({0})").format(err))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
if self.get_mode() == 'glances' and version[:3] == client_version[:3]:
|
if self.get_mode() == 'glances' and version[:3] == client_version[:3]:
|
||||||
|
@ -103,8 +106,8 @@ class GlancesClient(object):
|
||||||
self.stats = GlancesStatsClient()
|
self.stats = GlancesStatsClient()
|
||||||
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
|
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
|
||||||
else:
|
else:
|
||||||
print (_("Info: Trying to grab stats by SNMP..."))
|
|
||||||
self.set_mode('snmp')
|
self.set_mode('snmp')
|
||||||
|
logger.info(_("Trying to grab stats by SNMP..."))
|
||||||
|
|
||||||
if self.get_mode() == 'snmp':
|
if self.get_mode() == 'snmp':
|
||||||
# Fallback to SNMP if needed
|
# Fallback to SNMP if needed
|
||||||
|
@ -114,7 +117,7 @@ class GlancesClient(object):
|
||||||
self.stats = GlancesStatsClientSNMP(args=self.args)
|
self.stats = GlancesStatsClientSNMP(args=self.args)
|
||||||
|
|
||||||
if not self.stats.check_snmp():
|
if not self.stats.check_snmp():
|
||||||
print(_("Error: Connection to SNMP server failed"))
|
logger.error(_("Connection to SNMP server failed"))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
else:
|
else:
|
||||||
# Unknow mode...
|
# Unknow mode...
|
||||||
|
@ -138,7 +141,8 @@ class GlancesClient(object):
|
||||||
elif self.get_mode() == 'snmp':
|
elif self.get_mode() == 'snmp':
|
||||||
return self.update_snmp()
|
return self.update_snmp()
|
||||||
else:
|
else:
|
||||||
print(_("Error: Unknown server mode: {0}").format(self.get_mode()))
|
self.end()
|
||||||
|
logger.critical(_("Unknown server mode: {0}").format(self.get_mode()))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
def update_glances(self):
|
def update_glances(self):
|
||||||
|
@ -188,8 +192,6 @@ class GlancesClient(object):
|
||||||
|
|
||||||
# Update the screen
|
# Update the screen
|
||||||
self.screen.update(self.stats, cs_status=cs_status)
|
self.screen.update(self.stats, cs_status=cs_status)
|
||||||
# print self.stats
|
|
||||||
# print self.stats.getAll()
|
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
"""End of the client session."""
|
"""End of the client session."""
|
||||||
|
|
|
@ -33,6 +33,9 @@ LOGGING_CFG = {
|
||||||
'formatters': {
|
'formatters': {
|
||||||
'standard': {
|
'standard': {
|
||||||
'format': '%(asctime)s -- %(levelname)s -- %(message)s'
|
'format': '%(asctime)s -- %(levelname)s -- %(message)s'
|
||||||
|
},
|
||||||
|
'short': {
|
||||||
|
'format': '%(levelname)s: %(message)s'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'handlers': {
|
'handlers': {
|
||||||
|
@ -43,9 +46,9 @@ LOGGING_CFG = {
|
||||||
'filename': '/tmp/glances.log'
|
'filename': '/tmp/glances.log'
|
||||||
},
|
},
|
||||||
'console':{
|
'console':{
|
||||||
'level':'CRITICAL',
|
'level':'ERROR',
|
||||||
'class':'logging.StreamHandler',
|
'class':'logging.StreamHandler',
|
||||||
'formatter': 'standard'
|
'formatter': 'short'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
|
|
|
@ -32,7 +32,7 @@ except ImportError: # Python 2
|
||||||
from SimpleXMLRPCServer import SimpleXMLRPCServer
|
from SimpleXMLRPCServer import SimpleXMLRPCServer
|
||||||
|
|
||||||
# Import Glances libs
|
# Import Glances libs
|
||||||
from glances.core.glances_globals import version
|
from glances.core.glances_globals import version, logger
|
||||||
from glances.core.glances_stats import GlancesStatsServer
|
from glances.core.glances_stats import GlancesStatsServer
|
||||||
from glances.core.glances_timer import Timer
|
from glances.core.glances_timer import Timer
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class GlancesXMLRPCServer(SimpleXMLRPCServer):
|
||||||
try:
|
try:
|
||||||
self.address_family = socket.getaddrinfo(bind_address, bind_port)[0][0]
|
self.address_family = socket.getaddrinfo(bind_address, bind_port)[0][0]
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
print(_("Error: Couldn't open socket: {0}").format(e))
|
logger.error(_("Couldn't open socket: {0}").format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
SimpleXMLRPCServer.__init__(self, (bind_address, bind_port),
|
SimpleXMLRPCServer.__init__(self, (bind_address, bind_port),
|
||||||
|
@ -170,7 +170,6 @@ class GlancesInstance(object):
|
||||||
|
|
||||||
The goal is to dynamically generate the API get'Stats'() methods.
|
The goal is to dynamically generate the API get'Stats'() methods.
|
||||||
"""
|
"""
|
||||||
# print "DEBUG: Call method: %s" % item
|
|
||||||
header = 'get'
|
header = 'get'
|
||||||
# Check if the attribute starts with 'get'
|
# Check if the attribute starts with 'get'
|
||||||
if item.startswith(header):
|
if item.startswith(header):
|
||||||
|
@ -200,7 +199,7 @@ class GlancesServer(object):
|
||||||
try:
|
try:
|
||||||
self.server = GlancesXMLRPCServer(args.bind_address, args.port, requestHandler)
|
self.server = GlancesXMLRPCServer(args.bind_address, args.port, requestHandler)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(_("Error: Cannot start Glances server: {0}").format(e))
|
logger.error(_("Cannot start Glances server: {0}").format(e))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
# The users dict
|
# The users dict
|
||||||
|
|
|
@ -19,11 +19,15 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
# Import Glances libs
|
||||||
|
from glances.core.glances_globals import logger
|
||||||
|
|
||||||
|
# Import mandatory PySNMP lib
|
||||||
try:
|
try:
|
||||||
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("PySNMP library not found.")
|
logger.critical(_("PySNMP library not found."))
|
||||||
print("Install using pip: # pip install pysnmp")
|
print(_("Install using pip: # pip install pysnmp"))
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,16 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
# Import Glances libs
|
||||||
|
from glances.core.glances_globals import logger
|
||||||
|
|
||||||
|
# Import mandatory Bottle lib
|
||||||
try:
|
try:
|
||||||
from bottle import Bottle, template, static_file, TEMPLATE_PATH
|
from bottle import Bottle, template, static_file, TEMPLATE_PATH
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print('Bottle module not found. Glances cannot start in web server mode.')
|
logger.critical('Bottle module not found. Glances cannot start in web server mode.')
|
||||||
sys.exit(1)
|
print(_("Install it using pip: # pip install bottle"))
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
class GlancesBottle(object):
|
class GlancesBottle(object):
|
||||||
|
@ -83,7 +88,10 @@ class GlancesBottle(object):
|
||||||
# Init stats
|
# Init stats
|
||||||
self.stats = stats
|
self.stats = stats
|
||||||
|
|
||||||
self._app.run(host=self.args.bind_address, port=self.args.port)
|
bindmsg = _("Glances web server started on http://{}:{}/").format(self.args.bind_address, self.args.port)
|
||||||
|
logger.info(bindmsg)
|
||||||
|
print(bindmsg)
|
||||||
|
self._app.run(host=self.args.bind_address, port=self.args.port, quiet=not self.args.debug)
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
"""End the bottle."""
|
"""End the bottle."""
|
||||||
|
|
|
@ -248,7 +248,7 @@ class GlancesCurses(object):
|
||||||
return self.pressedkey
|
return self.pressedkey
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
"""Shutdown the curses window."""
|
"""Shutdown the curses window."""
|
||||||
if hasattr(curses, 'echo'):
|
if hasattr(curses, 'echo'):
|
||||||
curses.echo()
|
curses.echo()
|
||||||
if hasattr(curses, 'nocbreak'):
|
if hasattr(curses, 'nocbreak'):
|
||||||
|
|
Loading…
Reference in New Issue