提交 5f52c03f 编写于 作者: N nicolargo

Display debug message if dep lib is not found #1224

上级 5fdedbf8
......@@ -19,6 +19,7 @@ Enhancements and new features:
* Context switches bottleneck identification #1212
* Take advantage of the PSUtil issue #1025 (Add process_iter(attrs, ad_value)) #1105
* Nice Process Priority Configuration #1218
* Display debug message if dep lib is not found #1224
Bugs corrected:
......
......@@ -74,9 +74,9 @@ class AmpsList(object):
try:
amp = __import__(os.path.basename(amp_script)[:-3])
except ImportError as e:
logger.warning("Cannot load {}, you need to install an external Python package ({})".format(os.path.basename(amp_script), e))
logger.warning("Missing Python Lib ({}), cannot load {} AMP".format(e, amp_conf_name))
except Exception as e:
logger.warning("Cannot load {} ({})".format(os.path.basename(amp_script), e))
logger.warning("Cannot load {} AMP ({})".format(amp_conf_name, e))
else:
# Add the AMP to the dictionary
# The key is the AMP name
......
......@@ -23,19 +23,22 @@ Supported Cloud API:
- AWS EC2 (class ThreadAwsEc2Grabber, see bellow)
"""
try:
import requests
except ImportError:
cloud_tag = False
else:
cloud_tag = True
import threading
from glances.compat import iteritems, to_ascii
from glances.plugins.glances_plugin import GlancesPlugin
from glances.logger import logger
# Import plugin specific dependency
try:
import requests
except ImportError as e:
import_error_tag = True
# Display debu message if import KeyError
logger.warning("Missing Python Lib ({}), Cloud plugin is disable".format(e))
else:
import_error_tag = False
class Plugin(GlancesPlugin):
"""Glances' cloud plugin.
......@@ -85,16 +88,17 @@ class Plugin(GlancesPlugin):
self.reset()
# Requests lib is needed to get stats from the Cloud API
if not cloud_tag:
if import_error_tag:
return self.stats
# Update the stats
if self.input_method == 'local':
self.stats = self.aws_ec2.stats
# Example:
# self.stats = {'ami-id': 'ami-id',
# 'instance-id': 'instance-id',
# 'instance-type': 'instance-type',
# 'region': 'placement/availability-zone'}
self.stats = self.aws_ec2.stats
return self.stats
......@@ -149,8 +153,7 @@ class ThreadAwsEc2Grabber(threading.Thread):
Infinite loop, should be stopped by calling the stop() method
"""
if not cloud_tag:
logger.debug("cloud plugin - Requests lib is not installed")
if import_error_tag:
self.stop()
return False
......
......@@ -33,10 +33,11 @@ from glances.plugins.glances_plugin import GlancesPlugin
try:
import docker
except ImportError as e:
logger.debug("Docker library not found (%s). Glances cannot grab Docker info." % e)
docker_tag = False
import_error_tag = True
# Display debu message if import KeyError
logger.warning("Missing Python Lib ({}), Docker plugin is disable".format(e))
else:
docker_tag = True
import_error_tag = False
class Plugin(GlancesPlugin):
......@@ -92,9 +93,7 @@ class Plugin(GlancesPlugin):
def connect(self):
"""Connect to the Docker server."""
global docker_tag
if not docker_tag:
if import_error_tag:
return None
return docker.from_env()
......@@ -124,7 +123,7 @@ class Plugin(GlancesPlugin):
self.reset()
# The Docker-py lib is mandatory
if not docker_tag:
if import_error_tag:
return self.stats
if self.input_method == 'local':
......
......@@ -26,7 +26,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# The snmpd.conf needs to be edited.
# Add the following to enable it on all disk
......
......@@ -26,11 +26,11 @@ from glances.plugins.glances_plugin import GlancesPlugin
try:
import pynvml
except Exception as e:
logger.error("Could not import pynvml. NVIDIA stats will not be collected.")
logger.debug("pynvml error: {}".format(e))
gpu_nvidia_tag = False
import_error_tag = True
# Display debu message if import KeyError
logger.warning("Missing Python Lib ({}), Nvidia GPU plugin is disable".format(e))
else:
gpu_nvidia_tag = True
import_error_tag = False
class Plugin(GlancesPlugin):
......@@ -58,7 +58,7 @@ class Plugin(GlancesPlugin):
def init_nvidia(self):
"""Init the NVIDIA API."""
if not gpu_nvidia_tag:
if import_error_tag:
self.nvml_ready = False
try:
......
......@@ -23,22 +23,18 @@ import threading
from json import loads
from glances.compat import iterkeys, urlopen, queue
from glances.globals import BSD
from glances.logger import logger
from glances.timer import Timer
from glances.plugins.glances_plugin import GlancesPlugin
# XXX *BSDs: Segmentation fault (core dumped)
# -- https://bitbucket.org/al45tair/netifaces/issues/15
# Also used in the ports_list script
if not BSD:
try:
import netifaces
netifaces_tag = True
except ImportError:
netifaces_tag = False
# Import plugin specific dependency
try:
import netifaces
except ImportError as e:
import_error_tag = True
logger.warning("Missing Python Lib ({}), IP plugin is disable".format(e))
else:
netifaces_tag = False
import_error_tag = False
# List of online services to retreive public IP address
# List of tuple (url, json, key)
......@@ -85,7 +81,7 @@ class Plugin(GlancesPlugin):
# Reset stats
self.reset()
if self.input_method == 'local' and netifaces_tag:
if self.input_method == 'local' and not import_error_tag:
# Update stats using the netifaces lib
try:
default_gw = netifaces.gateways()['default'][netifaces.AF_INET]
......
......@@ -26,12 +26,6 @@ import socket
import time
import numbers
try:
import requests
requests_tag = True
except ImportError:
requests_tag = False
from glances.globals import WINDOWS, MACOS, BSD
from glances.ports_list import GlancesPortsList
from glances.web_list import GlancesWebList
......@@ -40,6 +34,13 @@ from glances.compat import bool_type
from glances.logger import logger
from glances.plugins.glances_plugin import GlancesPlugin
try:
import requests
requests_tag = True
except ImportError as e:
requests_tag = False
logger.warning("Missing Python Lib ({}), Ports plugin is limited to port scanning".format(e))
class Plugin(GlancesPlugin):
"""Glances ports scanner plugin."""
......
......@@ -20,18 +20,18 @@
"""Quicklook plugin."""
from glances.cpu_percent import cpu_percent
from glances.logger import logger
from glances.outputs.glances_bars import Bar
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
cpuinfo_tag = False
# Import plugin specific dependency
try:
from cpuinfo import cpuinfo
except ImportError:
# Correct issue #754
# Waiting for a correction on the upstream Cpuinfo lib
pass
except ImportError as e:
cpuinfo_tag = False
logger.warning("Missing Python Lib ({}), Quicklook plugin will not display CPU info".format(e))
else:
cpuinfo_tag = True
......
......@@ -23,11 +23,14 @@ from glances.compat import iterkeys
from glances.logger import logger
from glances.plugins.glances_plugin import GlancesPlugin
# pymdstat only available on GNU/Linux OS
# Import plugin specific dependency
try:
from pymdstat import MdStat
except ImportError:
logger.debug("pymdstat library not found. Glances cannot grab RAID info.")
except ImportError as e:
import_error_tag = True
logger.warning("Missing Python Lib ({}), Raid plugin is disable".format(e))
else:
import_error_tag = False
class Plugin(GlancesPlugin):
......@@ -57,6 +60,9 @@ class Plugin(GlancesPlugin):
# Reset stats
self.reset()
if import_error_tag:
return self.stats
if self.input_method == 'local':
# Update stats using the PyMDstat lib (https://github.com/nicolargo/pymdstat)
try:
......
......@@ -31,11 +31,11 @@ import psutil
try:
from wifi.scan import Cell
from wifi.exceptions import InterfaceError
except ImportError:
logger.debug("Wifi library not found. Glances cannot grab Wifi info.")
wifi_tag = False
except ImportError as e:
import_error_tag = True
logger.warning("Missing Python Lib ({}), Wifi plugin is disable".format(e))
else:
wifi_tag = True
import_error_tag = False
class Plugin(GlancesPlugin):
......@@ -81,7 +81,7 @@ class Plugin(GlancesPlugin):
self.reset()
# Exist if we can not grab the stats
if not wifi_tag:
if import_error_tag:
return self.stats
if self.input_method == 'local':
......@@ -167,7 +167,7 @@ class Plugin(GlancesPlugin):
ret = []
# Only process if stats exist and display plugin enable...
if not self.stats or not wifi_tag or self.is_disable():
if not self.stats or import_error_tag or self.is_disable():
return ret
# Max size for the interface name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册