AMBARI-18705 : All host metrics not being collected by AMS if user does not have permissions to read mount point. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0c5bcbba Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0c5bcbba Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0c5bcbba Branch: refs/heads/branch-feature-AMBARI-18634 Commit: 0c5bcbba5d44e915a5487a855f364bfe8cab6b72 Parents: 00ce02a Author: Aravindan Vijayan <[email protected]> Authored: Wed Oct 26 16:57:34 2016 -0700 Committer: Aravindan Vijayan <[email protected]> Committed: Wed Oct 26 16:57:34 2016 -0700 ---------------------------------------------------------------------- .../src/main/python/core/host_info.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/0c5bcbba/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py ---------------------------------------------------------------------- diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py index 632c86b..7992cff 100644 --- a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py +++ b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py @@ -178,6 +178,7 @@ class HostInfo(): max_percent_usage = ('', 0) partition_count = 0 + devices = set() for part in psutil.disk_partitions(all=False): if os.name == 'nt': if 'cdrom' in part.opts or part.fstype == '': @@ -187,8 +188,15 @@ class HostInfo(): continue pass pass - usage = psutil.disk_usage(part.mountpoint) - + try: + usage = psutil.disk_usage(part.mountpoint) + except Exception, e: + logger.error('Failed to read disk_usage for a mountpoint : ' + str(e)) + continue + + if part.device in devices: # Skip devices already seen. + continue + devices.add(part.device) combined_disk_total += usage.total if hasattr(usage, 'total') else 0 combined_disk_used += usage.used if hasattr(usage, 'used') else 0 combined_disk_free += usage.free if hasattr(usage, 'free') else 0
