You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ds...@apache.org on 2014/12/04 14:24:25 UTC

ambari git commit: AMBARI-8528 Investigate and fix missing graphs (dsen)

Repository: ambari
Updated Branches:
  refs/heads/trunk 3a8e1c5e1 -> 61687ead9


AMBARI-8528 Investigate and fix missing graphs (dsen)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/61687ead
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/61687ead
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/61687ead

Branch: refs/heads/trunk
Commit: 61687ead92f7bc638d6d5c50dd5aed047344e087
Parents: 3a8e1c5
Author: Dmytro Sen <ds...@apache.org>
Authored: Thu Dec 4 15:24:04 2014 +0200
Committer: Dmytro Sen <ds...@apache.org>
Committed: Thu Dec 4 15:24:04 2014 +0200

----------------------------------------------------------------------
 .../src/main/python/core/host_info.py           | 23 ++++++++++++++++
 .../src/main/python/core/metric_collector.py    |  4 +++
 .../src/test/python/core/TestHostInfo.py        | 29 ++++++++++++++++++++
 .../metrics/timeline/PhoenixTransactSQL.java    |  6 ++--
 4 files changed, 60 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/61687ead/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 6d47485..5bc4afb 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
@@ -58,6 +58,29 @@ class HostInfo():
     }
   pass
 
+  def get_process_info(self):
+    """
+    Return processes statistics at current time
+    """
+
+    STATUS_RUNNING = "running"
+
+    proc_stats = psutil.process_iter()
+
+    proc_run = 0
+    proc_total = 0
+    for proc in proc_stats:
+      proc_total += 1
+      if STATUS_RUNNING == proc.status():
+        proc_run += 1
+    pass
+
+    return {
+      'proc_run': proc_run,
+      'proc_total': proc_total
+    }
+  pass
+
   def get_mem_info(self):
     """
     Return memory statistics at current time

http://git-wip-us.apache.org/repos/asf/ambari/blob/61687ead/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 8b82e20..05e94be 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
@@ -65,12 +65,16 @@ class MetricsCollector():
     elif 'mem' in event.get_group_name():
       metrics = self.host_info.get_mem_info()
 
+    elif 'process' in event.get_group_name():
+      metrics = self.host_info.get_process_info()
+
     elif 'all' in event.get_group_name():
       metrics = {}
       metrics.update(self.host_info.get_cpu_times())
       metrics.update(self.host_info.get_combined_disk_usage())
       metrics.update(self.host_info.get_network_info())
       metrics.update(self.host_info.get_mem_info())
+      metrics.update(self.host_info.get_process_info())
 
     else:
       logger.warn('Unknown metric group.')

http://git-wip-us.apache.org/repos/asf/ambari/blob/61687ead/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 e1baabf..757edbe 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
@@ -82,6 +82,35 @@ class TestHostInfo(TestCase):
     self.assertEqual(cpu['mem_cached'], 'cached')
     self.assertEqual(cpu['swap_free'], 'free')
 
+
+  @patch("psutil.process_iter")
+  def testProcessInfo(self, process_iter_mock):
+
+    def side_effect_running():
+      return 'running'
+
+    class Proc:
+      def status(self):
+        return 'some_status'
+
+    p1 = Proc()
+    p1.status = side_effect_running
+    p2 = Proc()
+    p2.status = side_effect_running
+    p3 = Proc()
+    p4 = Proc()
+
+    processes = [p1, p2, p3, p4]
+
+    process_iter_mock.return_value = processes
+
+    hostinfo = HostInfo()
+
+    procs = hostinfo.get_process_info()
+
+    self.assertEqual(procs['proc_run'], 2)
+    self.assertEqual(procs['proc_total'], len(processes))
+
   @patch("psutil.disk_usage")
   @patch("psutil.disk_partitions")
   def testCombinedDiskUsage(self, dp_mock, du_mock):

http://git-wip-us.apache.org/repos/asf/ambari/blob/61687ead/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
index 0d53f5f..aef71e1 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixTransactSQL.java
@@ -297,8 +297,10 @@ public class PhoenixTransactSQL {
     }
 
     LOG.debug("SQL => " + sb.toString() + ", condition => " + condition);
-    PreparedStatement stmt = connection.prepareStatement(sb.toString());
-    int pos = 1;
+    String query = String.format(sb.toString(),
+      PhoenixTransactSQL.getNaiveTimeRangeHint(condition.getStartTime(),
+        NATIVE_TIME_RANGE_DELTA));
+    PreparedStatement stmt = connection.prepareStatement(query);    int pos = 1;
     if (condition.getMetricNames() != null) {
       for (; pos <= condition.getMetricNames().size(); pos++) {
         stmt.setString(pos, condition.getMetricNames().get(pos - 1));