AMBARI-26020: upgrade Ambari Metrics to python3 (#126)

diff --git a/ambari-metrics-assembly/pom.xml b/ambari-metrics-assembly/pom.xml
index 1f5f10e..8f26a5e 100644
--- a/ambari-metrics-assembly/pom.xml
+++ b/ambari-metrics-assembly/pom.xml
@@ -41,13 +41,13 @@
     <storm-sink.dir>${project.basedir}/../ambari-metrics-storm-sink</storm-sink.dir>
     <flume-sink.dir>${project.basedir}/../ambari-metrics-flume-sink</flume-sink.dir>
     <kafka-sink.dir>${project.basedir}/../ambari-metrics-kafka-sink</kafka-sink.dir>
-    <python.ver>python &gt;= 2.6</python.ver>
-    <python.devel>python-devel</python.devel>
+    <python.ver>python3 &gt;= 3.0</python.ver>
+    <python.devel>python3-devel</python.devel>
     <deb.publisher>Apache</deb.publisher>
     <deb.section>universe/admin</deb.section>
     <deb.architecture>i386 amd64</deb.architecture>
     <deb.priority>extra</deb.priority>
-    <deb.python.ver>python (&gt;= 2.6)</deb.python.ver>
+    <deb.python.ver>python3 (&gt;= 3.0)</deb.python.ver>
     <deb.architecture>amd64</deb.architecture>
     <deb.dependency.list>${deb.python.ver},python-dev,gcc</deb.dependency.list>
     <hadoop.sink.jar>ambari-metrics-hadoop-sink-with-common-${project.version}.jar</hadoop.sink.jar>
diff --git a/ambari-metrics-assembly/src/main/package/deb/control/prerm b/ambari-metrics-assembly/src/main/package/deb/control/prerm
index f50d88a..a231fdb 100644
--- a/ambari-metrics-assembly/src/main/package/deb/control/prerm
+++ b/ambari-metrics-assembly/src/main/package/deb/control/prerm
@@ -17,7 +17,7 @@
 # during package update. See http://www.ibm.com/developerworks/library/l-rpm2/
 # for details
 
-RESOURCE_MONITORING_DIR=/usr/lib/python2.6/site-packages/resource_monitoring
+RESOURCE_MONITORING_DIR=/usr/lib/python3.9/site-packages/resource_monitoring
 PSUTIL_DIR="${RESOURCE_MONITORING_DIR}/psutil"
 
 
diff --git a/ambari-metrics-host-monitoring/conf/unix/ambari-metrics-monitor b/ambari-metrics-host-monitoring/conf/unix/ambari-metrics-monitor
index 7cde266..977fe20 100644
--- a/ambari-metrics-host-monitoring/conf/unix/ambari-metrics-monitor
+++ b/ambari-metrics-host-monitoring/conf/unix/ambari-metrics-monitor
@@ -18,7 +18,7 @@
 MONITOR_CONF_DIR=/etc/ambari-metrics-monitor/conf/
 METRIC_MONITOR=ambari-metrics-monitor
 
-RESOURCE_MONITORING_DIR=/usr/lib/python2.6/site-packages/resource_monitoring
+RESOURCE_MONITORING_DIR=/usr/lib/python3.9/site-packages/resource_monitoring
 METRIC_MONITOR_PY_SCRIPT=${RESOURCE_MONITORING_DIR}/main.py
 
 PIDFILE=/var/run/ambari-metrics-monitor/ambari-metrics-monitor.pid
@@ -30,20 +30,12 @@
 NOTOK=1
 
 # checking for default Python 2
-if [ -a /usr/bin/python2 ] && [ -z "$PYTHON" ]; then
-  PYTHON=/usr/bin/python2
+if [ -a /usr/bin/python3 ] && [ -z "$PYTHON" ]; then
+  PYTHON=/usr/bin/python3
 fi
 
-if [ -a /usr/bin/python2.7 ] && [ -z "${PYTHON}" ]; then
-  PYTHON=/usr/bin/python2.7
-fi
-
-if [ -a /usr/bin/python2.6 ] && [ -z "${PYTHON}" ]; then
-  PYTHON=/usr/bin/python2.6
-fi
-
-if [ "x$PYTHON" == "x" ]; then
-  PYTHON=/usr/bin/python
+if [ -a /usr/bin/python3.9 ] && [ -z "${PYTHON}" ]; then
+  PYTHON=/usr/bin/python3.9
 fi
 
 export PYTHON=${PYTHON}
diff --git a/ambari-metrics-host-monitoring/src/main/package/rpm/preremove.sh b/ambari-metrics-host-monitoring/src/main/package/rpm/preremove.sh
index 9789127..d191fe5 100644
--- a/ambari-metrics-host-monitoring/src/main/package/rpm/preremove.sh
+++ b/ambari-metrics-host-monitoring/src/main/package/rpm/preremove.sh
@@ -17,7 +17,7 @@
 # during package update. See http://www.ibm.com/developerworks/library/l-rpm2/
 # for details
 
-RESOURCE_MONITORING_DIR=/usr/lib/python2.6/site-packages/resource_monitoring
+RESOURCE_MONITORING_DIR=/usr/lib/python3.9/site-packages/resource_monitoring
 PSUTIL_DIR="${RESOURCE_MONITORING_DIR}/psutil"
 
 
diff --git a/ambari-metrics-host-monitoring/src/main/python/__init__.py b/ambari-metrics-host-monitoring/src/main/python/__init__.py
index adfc71c..a082e43 100644
--- a/ambari-metrics-host-monitoring/src/main/python/__init__.py
+++ b/ambari-metrics-host-monitoring/src/main/python/__init__.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/__init__.py b/ambari-metrics-host-monitoring/src/main/python/core/__init__.py
index 264a95d..8b1fff1 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/__init__.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/__init__.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
@@ -26,12 +26,13 @@
 IS_WINDOWS = platform.system() == "Windows"
 
 if not IS_WINDOWS:
-  for dir in os.walk(path).next()[1]:
-    if 'lib' in dir:
-      sys.path.insert(1, os.path.join(path, dir))
+  for root, dirs, files in os.walk(path):
+    for dir in dirs:
+      if 'lib' in dir:
+        sys.path.insert(1, os.path.join(path, dir))
 
 try:
   import psutil
 except ImportError:
-  print 'psutil binaries need to be built by running, psutil/build.py ' \
-        'manually or by running a, mvn clean package, command.'
+  print('psutil binaries need to be built by running, psutil/build.py ' \
+        'manually or by running a, mvn clean package, command.')
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/aggregator.py b/ambari-metrics-host-monitoring/src/main/python/core/aggregator.py
index 59cdd27..88af469 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/aggregator.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/aggregator.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -21,7 +21,7 @@
 import threading
 import subprocess
 import logging
-import urllib2
+import urllib.request, urllib.error, urllib.parse
 
 logger = logging.getLogger()
 class Aggregator(threading.Thread):
@@ -82,11 +82,11 @@
       if 0 == self._stop_handler.wait(self.SLEEP_TIME):
         break
       try:
-        conn = urllib2.urlopen(self.URL, timeout=self.CONNECTION_TIMEOUT)
+        conn = urllib.request.urlopen(self.URL, timeout=self.CONNECTION_TIMEOUT)
         self.set_is_ok(True)
       except (KeyboardInterrupt, SystemExit):
         raise
-      except Exception, e:
+      except Exception as e:
         self.set_is_ok(False)
         continue
       if conn.code != 200:
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/application_metric_map.py b/ambari-metrics-host-monitoring/src/main/python/core/application_metric_map.py
index 59d4af0..ed08a17 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/application_metric_map.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/application_metric_map.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -46,7 +46,7 @@
 
   def put_metric(self, application_id, metric_id_to_value_map, timestamp):
     with self.lock:
-      for metric_name, value in metric_id_to_value_map.iteritems():
+      for metric_name, value in metric_id_to_value_map.items():
       
         metric_map = self.app_metric_map.get(application_id)
         if not metric_map:
@@ -79,7 +79,7 @@
       local_metric_map = {}
   
       if application_id:
-        if self.app_metric_map.has_key(application_id):
+        if application_id in self.app_metric_map:
           local_metric_map = { application_id : self.app_metric_map[application_id] }
         else:
           logger.info("application_id: {0}, not present in the map.".format(application_id))
@@ -87,9 +87,9 @@
         local_metric_map = self.app_metric_map.copy()
       pass
   
-      for appId, metrics in local_metric_map.iteritems():
+      for appId, metrics in local_metric_map.items():
         current_app_id = "HOST" if "HOST" in appId else appId
-        for metricId, metricData in dict(metrics).iteritems():
+        for metricId, metricData in dict(metrics).items():
           # Create a timeline metric object
           result_instanceid = ""
           if set_instanceid:
@@ -116,14 +116,14 @@
 
   def get_start_time(self, app_id, metric_id):
     with self.lock:
-      if self.cached_metric_map.has_key(app_id):
-        if self.cached_metric_map.get(app_id).has_key(metric_id):
+      if app_id in self.cached_metric_map:
+        if metric_id in self.cached_metric_map.get(app_id):
           metrics = self.cached_metric_map.get(app_id).get(metric_id)
-          return min(metrics.iterkeys())
-      if self.app_metric_map.has_key(app_id):
-        if self.app_metric_map.get(app_id).has_key(metric_id):
+          return min(metrics.keys())
+      if app_id in self.app_metric_map:
+        if metric_id in self.app_metric_map.get(app_id):
           metrics = self.app_metric_map.get(app_id).get(metric_id)
-          return min(metrics.iterkeys())
+          return min(metrics.keys())
   pass
 
   def format_app_id(self, app_id, instance_id = None):
@@ -164,11 +164,11 @@
       # check if needs to be cached
       # in case there can't be any more datapoints in last minute just post the metrics,
       # otherwise need to cut off and cache the last uncompleted minute
-      max_time = max(metricData.iterkeys())
+      max_time = max(metricData.keys())
       if max_time % 60000 <= 60000 - 10000:
         max_minute = max_time / 60000
         metric_data_copy = metricData.copy()
-        for time,value in metric_data_copy.iteritems():
+        for time,value in metric_data_copy.items():
           if time / 60000 == max_minute:
             cached_metric_map = self.cached_metric_map.get(appId)
             if not cached_metric_map:
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/blacklisted_set.py b/ambari-metrics-host-monitoring/src/main/python/core/blacklisted_set.py
index dab54c0..57991d7 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/blacklisted_set.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/blacklisted_set.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -38,7 +38,7 @@
 
   def __iter__(self):
     for item in set.__iter__(self):
-      if time.time() > self.__dict.get(item):
+      if time.time() > self.__dict.get(item, 0):
         yield item
 
   def get_actual_size(self):
@@ -62,12 +62,12 @@
   hosts = [1, 2, 3, 4]
   bs = BlacklistedSet(hosts)
   bs.blacklist(4)
-  print bs
+  print(bs)
   for a in bs:
-    print a
+    print(a)
   time.sleep(2)
 
   bs.blacklist(1)
   bs.blacklist(5)
   for a in bs:
-    print a
+    print(a)
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py b/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py
index 18ade5b..043298e 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -18,8 +18,8 @@
 limitations under the License.
 '''
 
-import ConfigParser
-import StringIO
+import configparser
+import io
 import json
 import os
 
@@ -54,7 +54,7 @@
 
 configDefaults = ConfigDefaultsLinux()
 
-config = ConfigParser.RawConfigParser()
+config = configparser.RawConfigParser()
 
 CONFIG_DIR = configDefaults.get_config_dir()
 CONFIG_FILE_PATH = configDefaults.get_config_file_path()
@@ -147,17 +147,17 @@
 
   def __init__(self):
     global config_content
-    self.config = ConfigParser.RawConfigParser()
+    self.config = configparser.RawConfigParser()
     if os.path.exists(CONFIG_FILE_PATH):
       self.config.read(CONFIG_FILE_PATH)
     else:
-      self.config.readfp(StringIO.StringIO(config_content))
+      self.config.readfp(io.StringIO(config_content))
     pass
     if os.path.exists(METRIC_FILE_PATH):
       with open(METRIC_FILE_PATH, 'r') as f:
         self.metric_groups = json.load(f)
     else:
-      print 'No metric configs found at {0}'.format(METRIC_FILE_PATH)
+      print('No metric configs found at {0}'.format(METRIC_FILE_PATH))
       self.metric_groups = \
       {
         'host_metric_groups': [],
@@ -166,7 +166,7 @@
     pass
     self._ca_cert_file_path = CA_CERTS_FILE_PATH
     self.hostname_script = None
-    ambari_agent_config = ConfigParser.RawConfigParser()
+    ambari_agent_config = configparser.RawConfigParser()
     if os.path.exists(AMBARI_AGENT_CONF):
       try:
         ambari_agent_config.read(AMBARI_AGENT_CONF)
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/controller.py b/ambari-metrics-host-monitoring/src/main/python/core/controller.py
index 080eaca..7fa937e 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/controller.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/controller.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -20,15 +20,15 @@
 
 import logging
 import threading
-from Queue import Queue
+from queue import Queue
 from threading import Timer
-from application_metric_map import ApplicationMetricMap
-from event_definition import HostMetricCollectEvent, ProcessMetricCollectEvent
-from metric_collector import MetricsCollector
-from emitter import Emitter
-from host_info import HostInfo
-from aggregator import Aggregator
-from aggregator import AggregatorWatchdog
+from resource_monitoring.core.application_metric_map import ApplicationMetricMap
+from resource_monitoring.core.event_definition import HostMetricCollectEvent, ProcessMetricCollectEvent
+from resource_monitoring.core.metric_collector import MetricsCollector
+from resource_monitoring.core.emitter import Emitter
+from resource_monitoring.core.host_info import HostInfo
+from resource_monitoring.core.aggregator import Aggregator
+from resource_monitoring.core.aggregator import AggregatorWatchdog
 
 
 logger = logging.getLogger()
@@ -107,13 +107,13 @@
     try:
       host_metrics_groups = self.metrics_config['host_metric_groups']
       process_metrics_groups = self.metrics_config['process_metric_groups']
-    except KeyError, ke:
+    except KeyError as ke:
       logger.warn('Error loading metric groups.')
       raise ke
     pass
 
     if host_metrics_groups:
-      for name, properties in host_metrics_groups.iteritems():
+      for name, properties in host_metrics_groups.items():
         event = HostMetricCollectEvent(properties, name)
         logger.info('Adding event to cache, {0} : {1}'.format(name, properties))
         self.events_cache.append(event)
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/emitter.py b/ambari-metrics-host-monitoring/src/main/python/core/emitter.py
index 4c0dd96..d220b7a 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/emitter.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/emitter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -21,10 +21,10 @@
 import logging
 import threading
 
-from security import CachedHTTPSConnection, CachedHTTPConnection
-from blacklisted_set import BlacklistedSet
-from config_reader import ROUND_ROBIN_FAILOVER_STRATEGY
-from spnego_kerberos_auth import SPNEGOKerberosAuth
+from resource_monitoring.core.security import CachedHTTPSConnection, CachedHTTPConnection
+from resource_monitoring.core.blacklisted_set import BlacklistedSet
+from resource_monitoring.core.config_reader import ROUND_ROBIN_FAILOVER_STRATEGY
+from resource_monitoring.core.spnego_kerberos_auth import SPNEGOKerberosAuth
 
 logger = logging.getLogger()
 
@@ -80,7 +80,7 @@
     while True:
       try:
         self.submit_metrics()
-      except Exception, e:
+      except Exception as e:
         logger.warn('Unable to emit events. %s' % str(e))
         self.cookie_cached = {}
       pass
@@ -129,7 +129,7 @@
       if self.cookie_cached[connection.host]:
         headers["Cookie"] = self.cookie_cached[connection.host]
         logger.debug("Cookie: %s" % self.cookie_cached[connection.host])
-    except Exception, e:
+    except Exception as e:
       self.cookie_cached = {}
     pass
 
@@ -197,7 +197,7 @@
                      .format(response.status, response.reason))
         logger.debug(str(response.read()))
       return response
-    except Exception, e:
+    except Exception as e:
       logger.warn('Error sending metrics to server. %s' % str(e))
       self.cookie_cached = {}
       return None
@@ -213,7 +213,7 @@
   def compute_hash(self, hostname):
     hash = 11987
     length = len(hostname)
-    for i in xrange(0, length - 1):
+    for i in range(0, length - 1):
       hash = 31*hash + ord(hostname[i])
     return hash
 
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/event_definition.py b/ambari-metrics-host-monitoring/src/main/python/core/event_definition.py
index 8c905da..45c9c1a 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/event_definition.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/event_definition.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -54,7 +54,7 @@
     try:
       self.group_interval = group_config['collect_every']
       self.metrics = group_config['metrics']
-    except KeyError, ex:
+    except KeyError as ex:
       logger.warn('Unable to create event from metric group. {0}'.format(
         group_config))
       raise ex
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/host_info.py b/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
index 6198c53..b33ba46 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -69,7 +69,7 @@
       'cpu_intr': cpu_times.irq if hasattr(cpu_times, 'irq') else 0,
       'cpu_sintr': cpu_times.softirq if hasattr(cpu_times, 'softirq') else 0,
       'cpu_steal': cpu_times.steal if hasattr(cpu_times, 'steal') else 0,
-      'boottime': long(boot_time) if boot_time else 0
+      'boottime': int(boot_time) if boot_time else 0
     }
     if platform.system() != "Windows":
       load_avg = os.getloadavg()
@@ -157,7 +157,7 @@
     skip_virtual_interfaces = self.get_virtual_network_interfaces() if self.__config.get_virtual_interfaces_skip() == 'True' else []
     skip_network_patterns = self.__config.get_network_interfaces_skip_pattern()
     skip_network_patterns_list = skip_network_patterns.split(',') if skip_network_patterns and skip_network_patterns != 'None' else []
-    for interface, values in net_stats.iteritems():
+    for interface, values in net_stats.items():
       if interface != 'lo' and not interface in skip_virtual_interfaces:
         ignore_network = False
         for p in skip_network_patterns_list:
@@ -171,8 +171,8 @@
           }
 
     with self.__last_network_lock:
-      result = dict((k, (v - self.__last_network_data.get(k, 0)) / delta) for k, v in new_net_stats.iteritems())
-      result = dict((k, 0 if v < 0 else v) for k, v in result.iteritems())
+      result = dict((k, (v - self.__last_network_data.get(k, 0)) / delta) for k, v in new_net_stats.items())
+      result = dict((k, 0 if v < 0 else v) for k, v in result.items())
       self.__last_network_data = new_net_stats
 
     return result
@@ -199,7 +199,7 @@
       pass
       try:
         usage = psutil.disk_usage(part.mountpoint)
-      except Exception, e:
+      except Exception as e:
         logger.debug('Failed to read disk_usage for a mountpoint : ' + str(e))
         continue
 
@@ -267,7 +267,7 @@
     logger.debug('skip_disk_patterns: %s' % skip_disk_patterns)
     if not skip_disk_patterns or skip_disk_patterns == 'None':
       io_counters = psutil.disk_io_counters()
-      print io_counters
+      print(io_counters)
     else:
       sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
                                        'read_bytes', 'write_bytes',
@@ -277,14 +277,14 @@
       if not rawdict:
         raise RuntimeError("Couldn't find any physical disk")
       trimmed_dict = {}
-      for disk, fields in rawdict.items():
+      for disk, fields in list(rawdict.items()):
         ignore_disk = False
         for p in skip_disk_pattern_list:
           if re.match(p, disk):
             ignore_disk = True
         if not ignore_disk:
           trimmed_dict[disk] = sdiskio(*fields)
-      io_counters = sdiskio(*[sum(x) for x in zip(*trimmed_dict.values())])
+      io_counters = sdiskio(*[sum(x) for x in zip(*list(trimmed_dict.values()))])
 
     new_disk_stats = {
         'read_count' : io_counters.read_count if hasattr(io_counters, 'read_count') else 0,
@@ -309,7 +309,7 @@
     disk_io_counters = psutil.disk_io_counters(True)
     per_disk_io_counters = {}
 
-    sortByKey = lambda x: sorted(x.items(), key=operator.itemgetter(0))
+    sortByKey = lambda x: sorted(list(x.items()), key=operator.itemgetter(0))
 
     disk_counter = 0
     if disk_io_counters:
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/instance_type_provider.py b/ambari-metrics-host-monitoring/src/main/python/core/instance_type_provider.py
index 2e0a321..5eb1002 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/instance_type_provider.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/instance_type_provider.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/krberr.py b/ambari-metrics-host-monitoring/src/main/python/core/krberr.py
index c5e0163..0b3ce53 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/krberr.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/krberr.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/metering.py b/ambari-metrics-host-monitoring/src/main/python/core/metering.py
index bac71e6..842bfa9 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/metering.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/metering.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -21,7 +21,7 @@
 import logging
 import time
 import json
-from instance_type_provider import HostInstanceTypeProvider
+from resource_monitoring.core.instance_type_provider import HostInstanceTypeProvider
 
 logger = logging.getLogger()
 
@@ -50,7 +50,7 @@
   def get_metering_metrics(self, metrics):
     metering_metrics = {}
     curr_time = int(round(time.time() * 1000))
-    for metric_name, value in metrics.iteritems():
+    for metric_name, value in metrics.items():
       if metric_name in self.metering_metric_list:
         end_time_metric_key = self.metering_metric_key_prefix + "~" + metric_name + "~" + str(value) + "~" + self.METERING_ALIVE_TIME_METRIC_SUFFIX
         metering_metrics[end_time_metric_key] = curr_time
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py b/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py
index f728c2d..f0318b6 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/metric_collector.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -20,8 +20,8 @@
 
 import logging
 from time import time
-from event_definition import HostMetricCollectEvent, ProcessMetricCollectEvent
-from metering import MeteringMetricHandler
+from resource_monitoring.core.event_definition import HostMetricCollectEvent, ProcessMetricCollectEvent
+from resource_monitoring.core.metering import MeteringMetricHandler
 
 logger = logging.getLogger()
 
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/security.py b/ambari-metrics-host-monitoring/src/main/python/core/security.py
index e36e01d..bfb2131 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/security.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/security.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -21,17 +21,17 @@
 import logging
 import ssl
 import socket
-import httplib
+import http.client
 
 logger = logging.getLogger()
 
 # TODO merge this with security.py in ambari-agent and move to ambrari commons
 
-class VerifiedHTTPSConnection(httplib.HTTPSConnection):
+class VerifiedHTTPSConnection(http.client.HTTPSConnection):
   """ Connecting using ssl wrapped sockets """
 
   def __init__(self, host, port, timeout, ca_certs):
-    httplib.HTTPSConnection.__init__(self, host, port=port, timeout=timeout)
+    http.client.HTTPSConnection.__init__(self, host, port=port, timeout=timeout)
     self.ca_certs = ca_certs
 
   def connect(self):
@@ -85,7 +85,7 @@
     return self.httpconn.getresponse()
 
   def create_connection(self):
-    return httplib.HTTPConnection(self.host, self.port, self.timeout)
+    return http.client.HTTPConnection(self.host, self.port, self.timeout)
 
 class CachedHTTPSConnection(CachedHTTPConnection):
   """ Caches an ssl socket and uses a single https connection to the server. """
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/spnego_kerberos_auth.py b/ambari-metrics-host-monitoring/src/main/python/core/spnego_kerberos_auth.py
index e49712f..401f66d 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/spnego_kerberos_auth.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/spnego_kerberos_auth.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -19,14 +19,14 @@
 '''
 
 import logging
-import httplib
+import http.client
 import os
 
 logger = logging.getLogger()
 try:
   import kerberos
 except ImportError:
-  import krberr as kerberos
+  from resource_monitoring.core import krberr as kerberos
   logger.warn('import kerberos exception: %s' % str(ImportError))
 pass
 
@@ -70,7 +70,7 @@
     try:
       connection.request(method, service_url, body, headers)
       response = connection.getresponse()
-    except Exception, e:
+    except Exception as e:
       logger.warn('2nd HTTP request exception from server: %s' % str(e))
       return None
     pass
@@ -88,7 +88,7 @@
       if result == -1:
         logger.warn('authGSSClientInit result: {0}'.format(result))
         return None
-    except kerberos.GSSError, e:
+    except kerberos.GSSError as e:
       logger.warn('authGSSClientInit exception: %s' % str(e))
       return None
     pass
@@ -99,7 +99,7 @@
       if result == -1:
         logger.warn('authGSSClientStep result for authenticate client: {0}'.format(result))
         return None
-    except kerberos.GSSError, e:
+    except kerberos.GSSError as e:
       logger.warn('authGSSClientStep exception for authenticate client: %s' % str(e))
       return None
     pass
@@ -108,7 +108,7 @@
     try:
       negotiate_value = kerberos.authGSSClientResponse(self.krb_context)
       logger.debug("authGSSClientResponse response:{0}".format(negotiate_value))
-    except kerberos.GSSError, e:
+    except kerberos.GSSError as e:
       logger.warn('authGSSClientResponse exception: %s' % str(e))
       return None
     pass
@@ -127,7 +127,7 @@
       result = kerberos.authGSSClientStep(self.krb_context, negotiate_value)
       if result == -1:
         logger.warn('authGSSClientStep result for authenticate server: {0}'.format(result))
-    except kerberos.GSSError, e:
+    except kerberos.GSSError as e:
       logger.warn('authGSSClientStep exception for authenticate server: %s' % str(e))
       result = -1
     pass
@@ -138,7 +138,7 @@
     try:
       result = kerberos.authGSSClientClean(self.krb_context)
       logger.debug("authGSSClientClean result:{0}".format(result))
-    except kerberos.GSSError, e:
+    except kerberos.GSSError as e:
       logger.warn('authGSSClientClean exception: %s' % str(e))
       result = -1
     pass
diff --git a/ambari-metrics-host-monitoring/src/main/python/core/stop_handler.py b/ambari-metrics-host-monitoring/src/main/python/core/stop_handler.py
index ba77be6..134edf6 100644
--- a/ambari-metrics-host-monitoring/src/main/python/core/stop_handler.py
+++ b/ambari-metrics-host-monitoring/src/main/python/core/stop_handler.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/main/python/main.py b/ambari-metrics-host-monitoring/src/main/python/main.py
index 02914da..ef674ed 100644
--- a/ambari-metrics-host-monitoring/src/main/python/main.py
+++ b/ambari-metrics-host-monitoring/src/main/python/main.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -23,9 +23,14 @@
 import os
 import sys
 import signal
-from core.controller import Controller
-from core.config_reader import Configuration, PID_OUT_FILE
-from core.stop_handler import bind_signal_handlers
+
+current_dir = os.path.dirname(os.path.abspath(__file__))
+parent_dir = os.path.dirname(current_dir)
+sys.path.append(parent_dir)
+
+from resource_monitoring.core.config_reader import Configuration, PID_OUT_FILE
+from resource_monitoring.core.stop_handler import bind_signal_handlers
+from resource_monitoring.core.controller import Controller
 
 logger = logging.getLogger()
 
@@ -65,8 +70,8 @@
   logger.info('Starting Server RPC Thread: %s' % ' '.join(sys.argv))
   controller.start()
 
-  print "Server out at: " + main_config.ams_monitor_out_file()
-  print "Server log at: " + main_config.ams_monitor_log_file()
+  print("Server out at: " + main_config.ams_monitor_out_file())
+  print("Server log at: " + main_config.ams_monitor_log_file())
 
   save_pid(os.getpid(), PID_OUT_FILE)
 
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/Makefile b/ambari-metrics-host-monitoring/src/main/python/psutil/Makefile
index b812527..59b0862 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/Makefile
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/Makefile
@@ -3,7 +3,7 @@
 # $ make install PYTHON=python3.3
 
 # You can set these variables from the command line.
-PYTHON    = python
+PYTHON    = python3
 TSCRIPT   = test/test_psutil.py
 
 all: test
@@ -26,7 +26,7 @@
 	$(PYTHON) setup.py build
 
 install: build
-	if test $(PYTHON) = python2.4; then \
+	if test $(PYTHON) = python3.9; then \
 		$(PYTHON) setup.py install; \
 	elif test $(PYTHON) = python2.5; then \
 		$(PYTHON) setup.py install; \
@@ -35,8 +35,8 @@
 	fi
 
 uninstall:
-	if test $(PYTHON) = python2.4; then \
-		pip-2.4 uninstall -y -v psutil; \
+	if test $(PYTHON) = python3.9; then \
+		pip-3.9 uninstall -y -v psutil; \
 	else \
 		cd ..; $(PYTHON) -m pip uninstall -y -v psutil; \
 	fi
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/build.py b/ambari-metrics-host-monitoring/src/main/python/psutil/build.py
index 09fb411..66bcd06 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/build.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/build.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -37,7 +37,7 @@
   cwd = os.getcwd()
   os.chdir(path)
 
-  print 'Executing make at location: %s ' % path
+  print('Executing make at location: %s ' % path)
 
   if sys.platform.startswith("win"):
     # Windows
@@ -50,7 +50,7 @@
   os.chdir(cwd)
 
   if returncode != 0:
-    print 'psutil build failed. Please find build output at: %s' % build_out_path
+    print('psutil build failed. Please find build output at: %s' % build_out_path)
   pass
 
 if __name__ == '__main__':
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/docs/conf.py b/ambari-metrics-host-monitoring/src/main/python/psutil/docs/conf.py
index 0c6608a..417f0ec 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/docs/conf.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/docs/conf.py
@@ -16,8 +16,8 @@
 import os
 
 
-PROJECT_NAME = u"psutil"
-AUTHOR = u"Giampaolo Rodola'"
+PROJECT_NAME = "psutil"
+AUTHOR = "Giampaolo Rodola'"
 THIS_YEAR = str(datetime.datetime.now().year)
 HERE = os.path.abspath(os.path.dirname(__file__))
 
@@ -68,7 +68,7 @@
 
 # General information about the project.
 project = PROJECT_NAME
-copyright = u'2009-%s, %s' % (THIS_YEAR, AUTHOR)
+copyright = '2009-%s, %s' % (THIS_YEAR, AUTHOR)
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
@@ -214,7 +214,7 @@
 # (source start file, target name, title, author, documentclass [howto/manual]).
 latex_documents = [
     ('index', '%s.tex' % PROJECT_NAME,
-     u'%s documentation' % PROJECT_NAME, AUTHOR),
+     '%s documentation' % PROJECT_NAME, AUTHOR),
 ]
 
 # The name of an image file (relative to this directory) to place at the top of
@@ -246,7 +246,7 @@
 # One entry per manual page. List of tuples
 # (source start file, name, description, authors, manual section).
 man_pages = [
-    ('index', PROJECT_NAME, u'%s documentation' % PROJECT_NAME, [AUTHOR], 1)
+    ('index', PROJECT_NAME, '%s documentation' % PROJECT_NAME, [AUTHOR], 1)
 ]
 
 # If true, show URL addresses after external links.
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/disk_usage.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/disk_usage.py
index 787cb0f..0c6ff84 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/disk_usage.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/disk_usage.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/free.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/free.py
index 95e11fb..0114783 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/free.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/free.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/iotop.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/iotop.py
index 47f1ca5..3a1f10f 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/iotop.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/iotop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/killall.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/killall.py
index b548e7b..7b5a38c 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/killall.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/killall.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/meminfo.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/meminfo.py
index 671f907..a404702 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/meminfo.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/meminfo.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/netstat.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/netstat.py
index 70bc231..d9d9cbe 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/netstat.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/netstat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/nettop.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/nettop.py
index 857285c..2cc03b2 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/nettop.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/nettop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # $Id: iotop.py 1160 2011-10-14 18:50:36Z g.rodola@gmail.com $
 #
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/pmap.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/pmap.py
index 1936c0b..ee39cf9 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/pmap.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/pmap.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/process_detail.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/process_detail.py
index 371142c..50b686f 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/process_detail.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/process_detail.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/top.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/top.py
index 479c797..93ac6c5 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/top.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/top.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/who.py b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/who.py
index 8ffbc81..a1bc155 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/examples/who.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/examples/who.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/__init__.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/__init__.py
index 3068b10..166a2c1 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/__init__.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/__init__.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
@@ -10,7 +10,7 @@
 in Python.
 """
 
-from __future__ import division
+
 
 __author__ = "Giampaolo Rodola'"
 __version__ = "2.1.1"
@@ -754,7 +754,7 @@
                         pass
             else:
                 # Windows only (faster)
-                for pid, ppid in ppid_map.items():
+                for pid, ppid in list(ppid_map.items()):
                     if ppid == self.pid:
                         try:
                             child = Process(pid)
@@ -775,7 +775,7 @@
                     except NoSuchProcess:
                         pass
             else:
-                for pid, ppid in ppid_map.items():
+                for pid, ppid in list(ppid_map.items()):
                     try:
                         p = Process(pid)
                         table[ppid].append(p)
@@ -925,7 +925,7 @@
                 path = tupl[2]
                 nums = tupl[3:]
                 try:
-                    d[path] = map(lambda x, y: x + y, d[path], nums)
+                    d[path] = list(map(lambda x, y: x + y, d[path], nums))
                 except KeyError:
                     d[path] = nums
             nt = _psplatform.pmmap_grouped
@@ -1725,11 +1725,11 @@
     if not rawdict:
         raise RuntimeError("couldn't find any physical disk")
     if perdisk:
-        for disk, fields in rawdict.items():
+        for disk, fields in list(rawdict.items()):
             rawdict[disk] = _nt_sys_diskio(*fields)
         return rawdict
     else:
-        return _nt_sys_diskio(*[sum(x) for x in zip(*rawdict.values())])
+        return _nt_sys_diskio(*[sum(x) for x in zip(*list(rawdict.values()))])
 
 
 # =====================================================================
@@ -1759,11 +1759,11 @@
     if not rawdict:
         raise RuntimeError("couldn't find any network interface")
     if pernic:
-        for nic, fields in rawdict.items():
+        for nic, fields in list(rawdict.items()):
             rawdict[nic] = _nt_sys_netio(*fields)
         return rawdict
     else:
-        return _nt_sys_netio(*[sum(x) for x in zip(*rawdict.values())])
+        return _nt_sys_netio(*[sum(x) for x in zip(*list(rawdict.values()))])
 
 
 def net_connections(kind='inet'):
@@ -1979,7 +1979,7 @@
 
 
 _replace_module()
-del property, memoize, division, _replace_module
+del property, memoize, _replace_module
 if sys.version_info < (3, 0):
     del num
 
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_common.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_common.py
index 3d2f27c..88708cb 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_common.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_common.py
@@ -6,7 +6,7 @@
 
 """Common objects shared by all _ps* modules."""
 
-from __future__ import division
+
 import errno
 import os
 import socket
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_compat.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_compat.py
index b6ac933..11a98bb 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_compat.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_compat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psbsd.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psbsd.py
index 5663736..62d51d6 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psbsd.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psbsd.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pslinux.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pslinux.py
index d20b267..407fd90 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pslinux.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pslinux.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
@@ -6,7 +6,7 @@
 
 """Linux platform implementation."""
 
-from __future__ import division
+
 
 import base64
 import errno
@@ -1061,7 +1061,7 @@
 
     @wrap_exceptions
     def cpu_affinity_get(self):
-        from_bitmask = lambda x: [i for i in xrange(64) if (1 << i) & x]
+        from_bitmask = lambda x: [i for i in range(64) if (1 << i) & x]
         bitmask = cext.proc_cpu_affinity_get(self.pid)
         return from_bitmask(bitmask)
 
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psosx.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psosx.py
index 8953867..8b21ae1 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psosx.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psosx.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psposix.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psposix.py
index 1188c9f..3a68b03 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psposix.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_psposix.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py
index bc18427..ba8143a 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pswindows.py b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pswindows.py
index 1a786f1..ee56109 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pswindows.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pswindows.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
@@ -444,7 +444,7 @@
 
     @wrap_exceptions
     def cpu_affinity_get(self):
-        from_bitmask = lambda x: [i for i in xrange(64) if (1 << i) & x]
+        from_bitmask = lambda x: [i for i in range(64) if (1 << i) & x]
         bitmask = cext.proc_cpu_affinity_get(self.pid)
         return from_bitmask(bitmask)
 
diff --git a/ambari-metrics-host-monitoring/src/main/python/psutil/setup.py b/ambari-metrics-host-monitoring/src/main/python/psutil/setup.py
index 98b24a1..cb7835f 100644
--- a/ambari-metrics-host-monitoring/src/main/python/psutil/setup.py
+++ b/ambari-metrics-host-monitoring/src/main/python/psutil/setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
diff --git a/ambari-metrics-host-monitoring/src/main/unix/ambari-python-wrap b/ambari-metrics-host-monitoring/src/main/unix/ambari-python-wrap
index 72041ef..099fee6 100755
--- a/ambari-metrics-host-monitoring/src/main/unix/ambari-python-wrap
+++ b/ambari-metrics-host-monitoring/src/main/unix/ambari-python-wrap
@@ -17,24 +17,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-export PYTHONPATH=/usr/lib/python2.6/site-packages:$PYTHONPATH
+export PYTHONPATH=/usr/lib/python3.9/site-packages:$PYTHONPATH
 
-# checking for default Python 2
-if [ -a /usr/bin/python2 ] && [ -z "$PYTHON" ]; then
-  PYTHON=/usr/bin/python2
+# checking for default Python 3
+if [ -a /usr/bin/python3 ] && [ -z "$PYTHON" ]; then
+  PYTHON=/usr/bin/python3
 fi
 
-if [ -a /usr/bin/python2.7 ] && [ -z "$PYTHON" ]; then
-  PYTHON=/usr/bin/python2.7
-fi
-
-if [ -a /usr/bin/python2.6 ] && [ -z "$PYTHON" ]; then
-  PYTHON=/usr/bin/python2.6
-fi
-
-# if no preferable python versions found, try to use system one. Hoping it's Python 2
-if [[ -z "$PYTHON" ]]; then
-  PYTHON=/usr/bin/python
+if [ -a /usr/bin/python3.9 ] && [ -z "$PYTHON" ]; then
+  PYTHON=/usr/bin/python3.9
 fi
 
 # execute script
diff --git a/ambari-metrics-host-monitoring/src/test/python/core/TestApplicationMetricMap.py b/ambari-metrics-host-monitoring/src/test/python/core/TestApplicationMetricMap.py
index d9ea55d..08af2ea 100644
--- a/ambari-metrics-host-monitoring/src/test/python/core/TestApplicationMetricMap.py
+++ b/ambari-metrics-host-monitoring/src/test/python/core/TestApplicationMetricMap.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/test/python/core/TestEmitter.py b/ambari-metrics-host-monitoring/src/test/python/core/TestEmitter.py
index aa83026..bce5e75 100644
--- a/ambari-metrics-host-monitoring/src/test/python/core/TestEmitter.py
+++ b/ambari-metrics-host-monitoring/src/test/python/core/TestEmitter.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py b/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py
index 1b249c7..058a57e 100644
--- a/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py
+++ b/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/test/python/core/TestMetricCollector.py b/ambari-metrics-host-monitoring/src/test/python/core/TestMetricCollector.py
index 64df3e6..d6593aa 100644
--- a/ambari-metrics-host-monitoring/src/test/python/core/TestMetricCollector.py
+++ b/ambari-metrics-host-monitoring/src/test/python/core/TestMetricCollector.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-host-monitoring/src/test/python/mock/docs/conf.py b/ambari-metrics-host-monitoring/src/test/python/mock/docs/conf.py
index 62f0491..51ca069 100644
--- a/ambari-metrics-host-monitoring/src/test/python/mock/docs/conf.py
+++ b/ambari-metrics-host-monitoring/src/test/python/mock/docs/conf.py
@@ -65,8 +65,8 @@
 master_doc = 'index'
 
 # General substitutions.
-project = u'Mock'
-copyright = u'2007-2012, Michael Foord & the mock team'
+project = 'Mock'
+copyright = '2007-2012, Michael Foord & the mock team'
 
 # The default replacements for |version| and |release|, also used in various
 # other places throughout the built documents.
@@ -187,8 +187,8 @@
 # Grouping the document tree into LaTeX files. List of tuples
 # (source start file, target name, title, author, document class [howto/manual]).
 latex_documents = [
-  ('index', 'Mock.tex', u'Mock Documentation',
-   u'Michael Foord', 'manual'),
+  ('index', 'Mock.tex', 'Mock Documentation',
+   'Michael Foord', 'manual'),
 ]
 
 # The name of an image file (relative to this directory) to place at the top of
diff --git a/ambari-metrics-host-monitoring/src/test/python/mock/mock.py b/ambari-metrics-host-monitoring/src/test/python/mock/mock.py
index 2a3f869..accf619 100644
--- a/ambari-metrics-host-monitoring/src/test/python/mock/mock.py
+++ b/ambari-metrics-host-monitoring/src/test/python/mock/mock.py
@@ -86,7 +86,7 @@
     next
 except NameError:
     def next(obj):
-        return obj.next()
+        return obj.__next__()
 
 
 BaseExceptions = (BaseException,)
@@ -616,7 +616,7 @@
         self.call_args_list = _CallList()
         self.method_calls = _CallList()
 
-        for child in self._mock_children.values():
+        for child in list(self._mock_children.values()):
             if isinstance(child, _SpecState):
                 continue
             child.reset_mock()
@@ -635,7 +635,7 @@
 
         >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
         >>> mock.configure_mock(**attrs)"""
-        for arg, val in sorted(kwargs.items(),
+        for arg, val in sorted(list(kwargs.items()),
                                # we sort on the number of dots so that
                                # attributes are set before we set attributes on
                                # attributes
@@ -1216,7 +1216,7 @@
             # not in Python 3
             patched.compat_co_firstlineno = getattr(
                 func, "compat_co_firstlineno",
-                func.func_code.co_firstlineno
+                func.__code__.co_firstlineno
             )
         return patched
 
@@ -1764,7 +1764,7 @@
     '__hash__': lambda self: object.__hash__(self),
     '__str__': lambda self: object.__str__(self),
     '__sizeof__': lambda self: object.__sizeof__(self),
-    '__unicode__': lambda self: unicode(object.__str__(self)),
+    '__unicode__': lambda self: str(object.__str__(self)),
 }
 
 _return_values = {
@@ -1951,7 +1951,7 @@
     formatted_args = ''
     args_string = ', '.join([repr(arg) for arg in args])
     kwargs_string = ', '.join([
-        '%s=%r' % (key, value) for key, value in kwargs.items()
+        '%s=%r' % (key, value) for key, value in list(kwargs.items())
     ])
     if args_string:
         formatted_args = args_string
diff --git a/ambari-metrics-host-monitoring/src/test/python/unitTests.py b/ambari-metrics-host-monitoring/src/test/python/unitTests.py
index f4aa845..7fb1b54 100644
--- a/ambari-metrics-host-monitoring/src/test/python/unitTests.py
+++ b/ambari-metrics-host-monitoring/src/test/python/unitTests.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
diff --git a/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py b/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py
index 492764b..5a2daf6 100644
--- a/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py
+++ b/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 ############################################################################
 #
 # Licensed to the Apache Software Foundation (ASF) under one
@@ -175,18 +175,18 @@
 
 if __name__ == "__main__":
     setPath()
-    print "phoenix_class_path:", phoenix_class_path
-    print "hbase_conf_dir:", hbase_conf_dir
-    print "hbase_conf_path:", hbase_conf_path
-    print "current_dir:", current_dir
-    print "phoenix_jar_path:", phoenix_jar_path
-    print "phoenix_client_jar:", phoenix_client_jar
-    print "phoenix_test_jar_path:", phoenix_test_jar_path
-    print "hadoop_common_jar_path:", hadoop_common_jar_path
-    print "hadoop_common_jar:", hadoop_common_jar
-    print "hadoop_hdfs_jar_path:", hadoop_hdfs_jar_path
-    print "hadoop_hdfs_jar:", hadoop_hdfs_jar
-    print "testjar:", testjar
-    print "phoenix_queryserver_jar:", phoenix_queryserver_jar
-    print "phoenix_thin_client_jar:", phoenix_thin_client_jar
-    print "hadoop_classpath:", hadoop_classpath
+    print("phoenix_class_path:", phoenix_class_path)
+    print("hbase_conf_dir:", hbase_conf_dir)
+    print("hbase_conf_path:", hbase_conf_path)
+    print("current_dir:", current_dir)
+    print("phoenix_jar_path:", phoenix_jar_path)
+    print("phoenix_client_jar:", phoenix_client_jar)
+    print("phoenix_test_jar_path:", phoenix_test_jar_path)
+    print("hadoop_common_jar_path:", hadoop_common_jar_path)
+    print("hadoop_common_jar:", hadoop_common_jar)
+    print("hadoop_hdfs_jar_path:", hadoop_hdfs_jar_path)
+    print("hadoop_hdfs_jar:", hadoop_hdfs_jar)
+    print("testjar:", testjar)
+    print("phoenix_queryserver_jar:", phoenix_queryserver_jar)
+    print("phoenix_thin_client_jar:", phoenix_thin_client_jar)
+    print("hadoop_classpath:", hadoop_classpath)
diff --git a/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py b/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py
index 852f264..ef064ba 100644
--- a/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py
+++ b/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 ############################################################################
 #
 # Licensed to the Apache Software Foundation (ASF) under one
@@ -57,9 +57,9 @@
 #phoenix_utils.setPath()
 
 if len(sys.argv) < 2:
-    print "Zookeeper not specified. \nUsage: sqlline.py <zookeeper> \
+    print("Zookeeper not specified. \nUsage: sqlline.py <zookeeper> \
 <optional_sql_file> \nExample: \n 1. sqlline.py localhost:2181:/hbase \n 2. sqlline.py \
-localhost:2181:/hbase ../examples/stock_symbol.sql"
+localhost:2181:/hbase ../examples/stock_symbol.sql")
     sys.exit()
 
 sqlfile = ""
@@ -79,7 +79,7 @@
 
 PATH_PREFIX = '/usr/lib/ambari-metrics-collector/'
 if not os.path.exists(PATH_PREFIX):
-  print 'Fatal Error: ' + PATH_PREFIX + ' not a valid path.'
+  print('Fatal Error: ' + PATH_PREFIX + ' not a valid path.')
   sys.exit(1)
 
 current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -93,7 +93,7 @@
     " -n none -p none --color=" + colorSetting + " --fastConnect=false --verbose=true \
 --isolation=TRANSACTION_READ_COMMITTED " + sqlfile
 
-print 'java command: %s' % str(java_cmd)
+print('java command: %s' % str(java_cmd))
 
 childProc = subprocess.Popen(java_cmd, shell=True)
 #Wait for child process exit
diff --git a/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/__init__.py b/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/__init__.py
index 38e1a5e..ec4a97c 100644
--- a/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/__init__.py
+++ b/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/__init__.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
diff --git a/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/properties.py b/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/properties.py
index 8e00762..878f4de 100644
--- a/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/properties.py
+++ b/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/properties.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -87,7 +87,7 @@
         first, last = m.span()
         sepidx = last - 1
       while line[-1] == '\\':
-        nextline = i.next()
+        nextline = next(i)
         nextline = nextline.strip()
         lineno += 1
         line = line[:-1] + nextline
@@ -114,7 +114,7 @@
     oldvalue = self.unescape(oldvalue)
     value = self.unescape(value)
     self._props[key] = None if value is None else value.strip()
-    if self._keymap.has_key(key):
+    if key in self._keymap:
       oldkey = self._keymap.get(key)
       self._origprops[oldkey] = None if oldvalue is None else oldvalue.strip()
     else:
@@ -129,20 +129,20 @@
     return newvalue
 
   def removeOldProp(self, key):
-    if self._origprops.has_key(key):
+    if key in self._origprops:
       del self._origprops[key]
     pass
 
   def removeProp(self, key):
-    if self._props.has_key(key):
+    if key in self._props:
       del self._props[key]
     pass
 
   def load(self, stream):
     if type(stream) is not file:
-      raise TypeError, 'Argument should be a file object!'
+      raise TypeError('Argument should be a file object!')
     if stream.mode != 'r':
-      raise ValueError, 'Stream should be opened in read-only mode!'
+      raise ValueError('Stream should be opened in read-only mode!')
     try:
       self.fileName = os.path.abspath(stream.name)
       lines = stream.readlines()
@@ -154,7 +154,7 @@
     return self._props.get(key, '')
 
   def propertyNames(self):
-    return self._props.keys()
+    return list(self._props.keys())
 
   def getPropertyDict(self):
     return self._props
@@ -168,10 +168,15 @@
     except KeyError:
       if hasattr(self._props, name):
         return getattr(self._props, name)
+      else:
+        raise NotImplementedError("The method '{}' is not implemented.".format(name))
+
+  def __contains__(self, key):
+    return key in self._props
 
   def sort_props(self):
     tmp_props = {}
-    for key in sorted(self._props.iterkeys()):
+    for key in sorted(self._props.keys()):
       tmp_props[key] = self._props[key]
     self._props = tmp_props
     pass
@@ -179,7 +184,7 @@
   def sort_origprops(self):
     tmp_props = self._origprops.copy()
     self._origprops.clear()
-    for key in sorted(tmp_props.iterkeys()):
+    for key in sorted(tmp_props.keys()):
       self._origprops[key] = tmp_props[key]
     pass
 
@@ -187,7 +192,7 @@
     """ Write the properties list to the stream 'out' along
     with the optional 'header' """
     if out.mode[0] != 'w':
-      raise ValueError, 'Steam should be opened in write mode!'
+      raise ValueError('Steam should be opened in write mode!')
     try:
       out.write(''.join(('#', ASF_LICENSE_HEADER, '\n')))
       out.write(''.join(('#', header, '\n')))
@@ -195,7 +200,7 @@
       tstamp = time.strftime('%a %b %d %H:%M:%S %Z %Y', time.localtime())
       out.write(''.join(('#', tstamp, '\n')))
       # Write properties from the pristine dictionary
-      for prop, val in self._origprops.items():
+      for prop, val in list(self._origprops.items()):
         if val is not None:
           out.write(''.join((prop, '=', val, '\n')))
       out.close()
@@ -206,7 +211,7 @@
     """ Write the properties list to the stream 'out' along
     with the optional 'header' """
     if out.mode[0] != 'w':
-      raise ValueError, 'Steam should be opened in write mode!'
+      raise ValueError('Steam should be opened in write mode!')
     try:
       out.write(''.join(('#', ASF_LICENSE_HEADER, '\n')))
       out.write(''.join(('#', header, '\n')))
@@ -214,7 +219,7 @@
       tstamp = time.strftime('%a %b %d %H:%M:%S %Z %Y', time.localtime())
       out.write(''.join(('#', tstamp, '\n')))
       # Write properties from the pristine dictionary
-      for key in sorted(self._origprops.iterkeys()):
+      for key in sorted(self._origprops.keys()):
         val = self._origprops[key]
         if val is not None:
           out.write(''.join((key, '=', val, '\n')))
diff --git a/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/serviceConfiguration.py b/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/serviceConfiguration.py
index 5e73e24..0348d6a 100644
--- a/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/serviceConfiguration.py
+++ b/ambari-metrics-timelineservice/src/main/python/ambari_metrics_collector/serviceConfiguration.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -82,7 +82,7 @@
   if conf_file is None:
     err = 'File %s not found in search path $%s: %s' % (AMS_PROPERTIES_FILE,
                                                         AMS_CONF_VAR, get_conf_dir())
-    print err
+    print(err)
     raise FatalException(1, err)
   else:
     print_info_msg('Loading properties from ' + conf_file)
@@ -96,8 +96,8 @@
   try:
     properties = Properties()
     properties.load(open(conf_file))
-  except (Exception), e:
-    print 'Could not read "%s": %s' % (conf_file, e)
+  except (Exception) as e:
+    print('Could not read "%s": %s' % (conf_file, e))
     return -1
   return properties
 
diff --git a/ambari-metrics-timelineservice/src/main/python/amc_service.py b/ambari-metrics-timelineservice/src/main/python/amc_service.py
index a19fd11..592a93d 100644
--- a/ambari-metrics-timelineservice/src/main/python/amc_service.py
+++ b/ambari-metrics-timelineservice/src/main/python/amc_service.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -136,7 +136,7 @@
   options.exit_message = None
 
   statusStr = AMCollectorService.QueryStatus()
-  print "Ambari Metrics Collector is " + statusStr
+  print("Ambari Metrics Collector is " + statusStr)
 
 
 def setup(options):
diff --git a/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py b/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py
index 2040959..ebd1ded 100644
--- a/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py
+++ b/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -80,7 +80,7 @@
 
   @classmethod
   def Install(cls, startupMode = "auto", username = None, password = None):
-    print "Installing service %s" % (cls._svc_name_)
+    print("Installing service %s" % (cls._svc_name_))
 
     # Configure master.xml, which drives the java subprocess32
     java_path = get_java_exe_path()
@@ -120,18 +120,18 @@
                                         None,
                                         username,
                                         password)
-        print "Service installed"
+        print("Service installed")
         win32service.CloseServiceHandle(hs)
       finally:
         win32service.CloseServiceHandle(hscm)
-    except win32service.error, exc:
+    except win32service.error as exc:
       if exc.winerror==winerror.ERROR_SERVICE_EXISTS:
         cls.Update(username, password)
       else:
-        print "Error installing service: %s (%d)" % (exc.strerror, exc.winerror)
+        print("Error installing service: %s (%d)" % (exc.strerror, exc.winerror))
         err = exc.winerror
-    except ValueError, msg: # Can be raised by custom option handler.
-      print "Error installing service: %s" % str(msg)
+    except ValueError as msg: # Can be raised by custom option handler.
+      print("Error installing service: %s" % str(msg))
       err = -1
       # xxx - maybe I should remove after _any_ failed install - however,
       # xxx - it may be useful to help debug to leave the service as it failed.
@@ -141,7 +141,7 @@
       try:
         RemoveService(cls._svc_name_)
       except win32api.error:
-        print "Warning - could not remove the partially installed service."
+        print("Warning - could not remove the partially installed service.")
 
   @classmethod
   def Update(cls, startupMode = "auto", username = None, password = None):
@@ -170,7 +170,7 @@
                                          username,
                                          password,
                                          cls._svc_display_name_)
-        print "Service updated"
+        print("Service updated")
       finally:
         win32service.CloseServiceHandle(hs)
     finally:
diff --git a/ambari-metrics-timelineservice/src/main/python/main.py b/ambari-metrics-timelineservice/src/main/python/main.py
index 2467ea3..ec12a22 100644
--- a/ambari-metrics-timelineservice/src/main/python/main.py
+++ b/ambari-metrics-timelineservice/src/main/python/main.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -122,7 +122,7 @@
   suspend_mode = 'y' if SUSPEND_START_MODE else 'n'
   command = command_base.format(java_class_path, java_heap_max, suspend_mode)
   if not os.path.exists(PID_DIR):
-    os.makedirs(PID_DIR, 0755)
+    os.makedirs(PID_DIR, 0o755)
 
   #Ignore the requirement to run as root. In Windows, by default the child process inherits the security context
   # and the environment from the parent process.
@@ -132,7 +132,7 @@
   procJava = subprocess32.Popen(param_list, env=os.environ)
 
   #wait for server process for SERVER_START_TIMEOUT seconds
-  print "Waiting for server start..."
+  print("Waiting for server start...")
 
   pidJava = procJava.pid
   if pidJava <= 0:
@@ -146,9 +146,9 @@
     raise FatalException(-1, AMC_DIE_MSG.format(exitcode, SERVER_OUT_FILE))
   else:
     save_pid(pidJava, PID_OUT_FILE)
-    print "Server PID at: " + PID_OUT_FILE
-    print "Server out at: " + SERVER_OUT_FILE
-    print "Server log at: " + SERVER_LOG_FILE
+    print("Server PID at: " + PID_OUT_FILE)
+    print("Server out at: " + SERVER_OUT_FILE)
+    print("Server log at: " + SERVER_LOG_FILE)
 
   if scmStatus is not None:
     scmStatus.reportStarted()
@@ -167,7 +167,7 @@
   init_service_debug(options)
 
   if len(args) == 0:
-    print parser.print_help()
+    print(parser.print_help())
     parser.error("No action entered")
 
   action = args[0]
@@ -203,7 +203,7 @@
       print_warning_msg(e.reason)
 
   if options.exit_message is not None:
-    print options.exit_message
+    print(options.exit_message)
 
 
 if __name__ == "__main__":
diff --git a/ambari-metrics-timelineservice/src/main/resources/scripts/ams_query.py b/ambari-metrics-timelineservice/src/main/resources/scripts/ams_query.py
index 0247990..d130f31 100644
--- a/ambari-metrics-timelineservice/src/main/resources/scripts/ams_query.py
+++ b/ambari-metrics-timelineservice/src/main/resources/scripts/ams_query.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''
 Licensed to the Apache Software Foundation (ASF) under one
@@ -18,7 +18,7 @@
 limitations under the License.
 '''
 
-import urllib2
+import urllib.request, urllib.error, urllib.parse
 import signal
 import sys
 import optparse
@@ -92,11 +92,11 @@
   (options, args) = parser.parse_args()
 
   if options.host is None:
-    print "Ambari Metrics host name is required (--host or -h)"
+    print("Ambari Metrics host name is required (--host or -h)")
     exit(-1)
 
   if options.node_names is None:
-    print "cluster nodes are required (--nodes or -n)"
+    print("cluster nodes are required (--nodes or -n)")
     exit(3)
 
   global start_time_secs, metrics_test_host, hostnames
@@ -121,8 +121,8 @@
   hostname = ','.join(hostnames)
   qs = QuerySender(metrics_test_host, True)
   for metric_name in all_metrics:
-    print
-    print 'Querying for ' + metric_name + ' metrics'
+    print()
+    print('Querying for ' + metric_name + ' metrics')
     current_time_secs = start_time_secs
     qs.query_all_app_metrics(hostname, metric_name,
                              all_metrics[metric_name],
@@ -136,7 +136,7 @@
 
 
 def print_all_metrics(metrics):
-  print 'Metrics Summary'
+  print('Metrics Summary')
   for app_id in sorted(metrics):
     first = True
     for single_query_metrics in metrics[app_id]:
@@ -147,12 +147,12 @@
 def print_app_metrics(app_id, metric_timing, header=False):
   #header
   if header:
-    print app_id + ': ' + ','.join(sorted(metric_timing.keys()))
+    print(app_id + ': ' + ','.join(sorted(metric_timing.keys())))
   #vals
-  print app_id + ':',
+  print(app_id + ':', end=' ')
   for key in sorted(metric_timing):
-    print '%.3f,' % metric_timing[key],
-  print
+    print('%.3f,' % metric_timing[key], end=' ')
+  print()
 
 
 class QuerySender:
@@ -163,14 +163,14 @@
   def query_all_app_metrics(self, hostname, app_id, metrics, current_time_secs):
     metric_timing = {}
     for key in metrics:
-      print 'Getting metrics for', key
+      print('Getting metrics for', key)
       query_time = time.time()
 
       metric_names = ','.join(metrics[key])
       self.query(hostname, app_id, metric_names, current_time_secs)
       query_time_elapsed = time.time() - query_time
 
-      print 'Query for "%s" took %s' % (key, query_time_elapsed)
+      print('Query for "%s" took %s' % (key, query_time_elapsed))
       metric_timing[key] = query_time_elapsed
 
     add_query_metrics_for_app_id(app_id, metric_timing)
@@ -179,21 +179,21 @@
 
   def query(self, hostname, app_id, metric_names, current_time_secs):
     url = self.create_url(hostname, metric_names, app_id, current_time_secs)
-    print url
+    print(url)
     response = self.send(url)
     if self.print_responses:
-      print response
+      print(response)
     pass
 
   def send(self, url):
-    request = urllib2.Request(url)
+    request = urllib.request.Request(url)
     try:
-      response = urllib2.urlopen(request, timeout=int(30))
+      response = urllib.request.urlopen(request, timeout=int(30))
       response = response.read()
       return response
 
-    except urllib2.URLError as e:
-      print e.reason
+    except urllib.error.URLError as e:
+      print(e.reason)
 
   def create_url(self, hostname, metric_names, app_id, current_time_secs):
     server = AMS_URL.format(self.metrics_address,
diff --git a/pom.xml b/pom.xml
index a8ecba5..5a1b6f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,8 +35,8 @@
   </modules>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <python.ver>python &gt;= 2.6</python.ver>
-    <deb.python.ver>python (&gt;= 2.6)</deb.python.ver>
+    <python.ver>python3 &gt;= 3.0</python.ver>
+    <deb.python.ver>python3 (&gt;= 3.0)</deb.python.ver>
     <slf4j.version>2.0.0</slf4j.version>
     <zookeeper.version>3.5.9</zookeeper.version>
     <kafka.version>2.8.1</kafka.version>
@@ -53,7 +53,7 @@
     <grafana.tar>https://dl.grafana.com/oss/release/grafana-9.5.6.linux-amd64.tar.gz</grafana.tar>
     <phoenix.tar>http://repo.bigtop.apache.org.s3.amazonaws.com/bigtop-stack-binary/3.2.0/centos-7/x86_64/phoenix-hbase-2.4-5.1.2-bin.tar.gz</phoenix.tar>
     <phoenix.folder>phoenix-hbase-2.4-5.1.2-bin</phoenix.folder>
-    <resmonitor.install.dir>/usr/lib/python2.6/site-packages/resource_monitoring</resmonitor.install.dir>
+    <resmonitor.install.dir>/usr/lib/python3.9/site-packages/resource_monitoring</resmonitor.install.dir>
     <powermock.version>1.6.2</powermock.version>
     <distMgmtSnapshotsId>apache.snapshots.https</distMgmtSnapshotsId>
     <distMgmtSnapshotsName>Apache Development Snapshot Repository</distMgmtSnapshotsName>