Repository: ambari Updated Branches: refs/heads/trunk a982836df -> 5d06a3130
AMBARI-10263. Collect disk io counters using Metric Monitor service. (swagle) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5d06a313 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5d06a313 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5d06a313 Branch: refs/heads/trunk Commit: 5d06a31309bb6ced2aef16116860e4aba9c0b571 Parents: a982836 Author: Siddharth Wagle <[email protected]> Authored: Fri Mar 27 17:11:08 2015 -0700 Committer: Siddharth Wagle <[email protected]> Committed: Fri Mar 27 17:11:08 2015 -0700 ---------------------------------------------------------------------- .../src/main/python/core/host_info.py | 19 +++++++++++++++++ .../src/main/python/core/metric_collector.py | 2 ++ .../src/test/python/core/TestHostInfo.py | 22 ++++++++++++++++++++ ambari-metrics/pom.xml | 2 +- 4 files changed, 44 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/5d06a313/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 6dd8466..057b5b6 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 @@ -247,6 +247,25 @@ class HostInfo(): pass pass + def get_disk_io_counters(self): + # read_count: number of reads + # write_count: number of writes + # read_bytes: number of bytes read + # write_bytes: number of bytes written + # read_time: time spent reading from disk (in milliseconds) + # write_time: time spent writing to disk (in milliseconds) + + io_counters = psutil.disk_io_counters() + + return { + 'read_count' : io_counters.read_count if hasattr(io_counters, 'read_count') else 0, + 'write_count' : io_counters.write_count if hasattr(io_counters, 'write_count') else 0, + 'read_bytes' : io_counters.read_bytes if hasattr(io_counters, 'read_bytes') else 0, + 'write_bytes' : io_counters.write_bytes if hasattr(io_counters, 'write_bytes') else 0, + 'read_time' : io_counters.read_time if hasattr(io_counters, 'read_time') else 0, + 'write_time' : io_counters.write_time if hasattr(io_counters, 'write_time') else 0 + } + def get_hostname(self): global cached_hostname if cached_hostname is not None: http://git-wip-us.apache.org/repos/asf/ambari/blob/5d06a313/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py ---------------------------------------------------------------------- diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py index a830a1f..c28fd03 100644 --- a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py +++ b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py @@ -58,6 +58,7 @@ class MetricsCollector(): elif 'disk' in event.get_group_name(): metrics = self.host_info.get_combined_disk_usage() + metrics.update(self.host_info.get_disk_io_counters()) elif 'network' in event.get_group_name(): metrics = self.host_info.get_network_info() @@ -75,6 +76,7 @@ class MetricsCollector(): metrics.update(self.host_info.get_network_info()) metrics.update(self.host_info.get_mem_info()) metrics.update(self.host_info.get_process_info()) + metrics.update(self.host_info.get_disk_io_counters()) else: logger.warn('Unknown metric group.') http://git-wip-us.apache.org/repos/asf/ambari/blob/5d06a313/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py ---------------------------------------------------------------------- diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py b/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py index 102ea44..bdedc2e 100644 --- a/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py +++ b/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py @@ -23,6 +23,7 @@ from host_info import HostInfo import platform from unittest import TestCase from mock.mock import patch, MagicMock +import collections logger = logging.getLogger() @@ -129,3 +130,24 @@ class TestHostInfo(TestCase): self.assertEqual(cdu['disk_used'], "0.00") self.assertEqual(cdu['disk_free'], "0.00") self.assertEqual(cdu['disk_percent'], "0.00") + + @patch("psutil.disk_io_counters") + def testDiskIOCounters(self, io_mock): + + Counters = collections.namedtuple('sdiskio', ['read_count', 'write_count', + 'read_bytes', 'write_bytes', + 'read_time', 'write_time']) + io_mock.return_value = Counters(0, 1, 2, 3, 4, 5) + + hostinfo = HostInfo(MagicMock()) + + disk_counters = hostinfo.get_disk_io_counters() + + self.assertEqual(disk_counters['read_count'], 0) + self.assertEqual(disk_counters['write_count'], 1) + self.assertEqual(disk_counters['read_bytes'], 2) + self.assertEqual(disk_counters['write_bytes'], 3) + self.assertEqual(disk_counters['read_time'], 4) + self.assertEqual(disk_counters['write_time'], 5) + + http://git-wip-us.apache.org/repos/asf/ambari/blob/5d06a313/ambari-metrics/pom.xml ---------------------------------------------------------------------- diff --git a/ambari-metrics/pom.xml b/ambari-metrics/pom.xml index 9fe5ce2..6df0d00 100644 --- a/ambari-metrics/pom.xml +++ b/ambari-metrics/pom.xml @@ -50,7 +50,7 @@ <repository> <id>apache-hadoop</id> <name>hdp</name> - <url>http://54.235.92.15/nexus/content/groups/public/</url> + <url>http://repo.hortonworks.com/content/groups/public/</url> </repository> </repositories> <dependencyManagement>
