From 9cd82488fe523b51fbb7e06d901356accf55b0b8 Mon Sep 17 00:00:00 2001 From: Paul Cuzner Date: Wed, 23 Aug 2017 14:54:15 +1200 Subject: [PATCH] iscsi: trigger stats only when iscsi is active look for the iscsi dir in sysfs to determine when to send the iscsi stats. If the iscsi base dir is not there the collector will just send the version of gwcli --- collectors/iscsi.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/collectors/iscsi.py b/collectors/iscsi.py index 74d29cb..3c85a1e 100644 --- a/collectors/iscsi.py +++ b/collectors/iscsi.py @@ -104,7 +104,7 @@ class ISCSIGateway(BaseCollector): if 'rtslib_fb.root' not in sys.modules.keys(): try: - import rtslib_fb.root as RTSRoot + from rtslib_fb.root import RTSRoot except ImportError: raise @@ -242,19 +242,28 @@ class ISCSIGateway(BaseCollector): start = time.time() # populate gateway instance with the latest configuration from rtslib - self.refresh() - - # Overtime they'll be churn in client and disks so we need to drop - # any entries from prior runs that are no longer seen in the iscsi - # configuration with the prune method - self.prune() + stats = {} + if os.path.exists('/sys/kernel/config/target/iscsi'): + self.refresh() + + # Overtime they'll be churn in client and disks so we need to drop + # any entries from prior runs that are no longer seen in the iscsi + # configuration with the prune method + self.prune() + stats = self.dump() + else: + msg = "iSCSI Gateway is not active on this host" + self.logger.warning(msg) + self.error = True + self.error_msgs = [msg] + stats = {"iscsi": { + "ceph_version": self.version + } + } end = time.time() self.logger.info("LIO stats took {}s".format(end - start)) - return self.dump() + return stats - @classmethod - def probe(cls): - return os.path.exists('/sys/kernel/config/target/iscsi') -- 2.47.3