Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Ambari-Metrics-Monitor: Cannot import name _common(Python)?

Highlighted

Ambari-Metrics-Monitor: Cannot import name _common(Python)?

New Contributor

I have an 3-node HDP cluster running Ambari 2.2.0 with HDP 2.2.4. I just recently upgraded from Ambari 1.7.0 in which the server now uses Ambari-Metrics-Collector. The overall issue is that the metrics MONITOR fails to start on one of the three nodes (which happens to be the NN machine and the machine from which the metrics COLLECTOR is installed). The collector and the monitors start fine everywhere else. The error in short that accompanies the failure is:

ImportError: cannot import name _common

The metrics log contains:

[root@psnet-hdp-vm1 ~]# cat /var/log/ambari-metrics-monitor/ambari-metrics-monitor.out
psutil binaries need to be built by running, psutil/build.py manually or by running a, mvn clean package, command.
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/resource_monitoring/main.py", line 27, in <module>
    from core.controller import Controller
  File "/usr/lib/python2.6/site-packages/resource_monitoring/core/controller.py", line 28, in <module>
    from metric_collector import MetricsCollector
  File "/usr/lib/python2.6/site-packages/resource_monitoring/core/metric_collector.py", line 23, in <module>
    from host_info import HostInfo
  File "/usr/lib/python2.6/site-packages/resource_monitoring/core/host_info.py", line 22, in <module>
    import psutil
  File "/usr/lib/python2.6/site-packages/resource_monitoring/psutil/build/lib.linux-x86_64-2.7/psutil/__init__.py", line 89, in <module>
    import psutil._pslinux as _psplatform
  File "/usr/lib/python2.6/site-packages/resource_monitoring/psutil/build/lib.linux-x86_64-2.7/psutil/_pslinux.py", line 20, in <module>
    from psutil import _common
ImportError: cannot import name _common

So, in general this looks to be some type of Python versioning issue. The overall environment uses Python 2.6, BUT what is interesting is that when I first upgraded this cluster the agent on the problematic node attempted to use Python version 2.7 (which is installed as a pyenv for another application running on the server called "Dataiku" and is supposed to be env specific.) To fix this I used a remedy I have been using for some time now which is to update the ambari-env.sh files with PYTHON=/usr/bin/Python2.6. This has always worked fine. But here, it seems some problems were possibly left over. Note I also added the PYTHON variable to the ambari-metrics env configuration.

Also, whether it matters:

$root~ python -V

Python 2.7.10

$user~ python -V

Python 2.6.6

Any ideas as to why this may be happening and how to remedy this, or how to force AMS to use Python 2.6.6 because although after adding the PYTHON var in the conf (it will actually say using /usr/bin/Python2.6 when executing), I suspect that it is still trying to run with Python2.7 which is causing the error?

Note ALSO how psutil points to directories such as:

/usr/lib/python2.6/site-packages/resource_monitoring/psutil/build/lib.linux-x86_64-2.7/

Instead of:

/usr/lib/python2.6/site-packages/resource_monitoring/psutil/build/lib.linux-x86_64-2.6/

Is it attempting to use Python2.7 libs that aren't compatible? Maybe I can alias the Python version to be Python2.6 and reinstall the metrics monitor via yum?

Thanks and I greatly, greatly appreciate the feedback!

Matthew R. McBride

Big Data Solutions Engineer

9 REPLIES 9
Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

Mentor

Excellent investigative approach, look in site-packages for symlinks to the wrong version of Python. I would try to reinstall agent/monitor after cleaning up the symlinks. also, you're running HDP 2.2.4 and Ambari 2.2. At the least, consider upgrading to latest 2.2 release, I think it's 2.2.9. It may or may not be related but 2.2.4 is ancient and Ambari 2.2 is fairly new.

Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

New Contributor

Hey thanks very much for the feedback! This approach makes sense and I will go ahead and give it a shot. What is the best method for re-installing the monitor and collector. Via yum? Something like:

...clean all 2.7 links in site-packages

$root~ alias python=/usr/bin/python2.6.6

$root~ yum remove amabri-metrics-monitor

$root~ yum remove ambari-metrics-collector

$root~ python -V

Python 2.6.6

$root~ yum install ambari-metrics-collector

$root~ yum install amabri-metrics-monitor

Does this resemble the correct corse of action?

Thanks again!!

Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

New Contributor

Yep. Makes sense. Thanks!

Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

New Contributor

Hey, can you provide an update on this? I'm having same issue in 5 of 8 nodes in my architecture. The 3 nodes in which the monitor is running fine are DataNodes.

Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

Expert Contributor

The /usr/sbin/ambari-metrics-monitor, checks if PYTHON env variable is set.

Can you try to set it in ams-env (from the UI) and restart the metrics-monitor:

export PYTHON=/usr/bin/python2.6

This should compile psutil with python2.6, as far as root cause of the issue, you have it nailed, AFAIK.

Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

Expert Contributor

You might have to delete the psutil build dir in order to compile:

rm -rf /usr/lib/python2.6/site-packages/resource_monitoring/psutil/build/*

Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

Guru

@Matthew McBride @Artem Ervits: Did you fix this issue and if yes then can you please explain how as I am also getting same issue but I have same python version across my cluster.

[user@knoxservre~]$ cat /var/log/ambari-metrics-monitor/ambari-metrics-monitor.out

psutil binaries need to be built by running, psutil/build.py manually or by running a, mvn clean package, command.

Traceback (most recent call last):

File "/usr/lib/python2.6/site-packages/resource_monitoring/main.py", line 27, in <module>

from core.controller import Controller

File "/usr/lib/python2.6/site-packages/resource_monitoring/core/controller.py", line 28, in <module>

from metric_collector import MetricsCollector

File "/usr/lib/python2.6/site-packages/resource_monitoring/core/metric_collector.py", line 23, in <module>

from host_info import HostInfo

File "/usr/lib/python2.6/site-packages/resource_monitoring/core/host_info.py", line 22, in <module>

import psutil

File "/usr/lib/python2.6/site-packages/resource_monitoring/psutil/build/lib.linux-x86_64-2.6/psutil/__init__.py", line 89, in <module>

import psutil._pslinux as _psplatform

File "/usr/lib/python2.6/site-packages/resource_monitoring/psutil/build/lib.linux-x86_64-2.6/psutil/_pslinux.py", line 20, in <module>

from psutil import _common

ImportError: cannot import name _common

Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

Explorer
Highlighted

Re: Ambari-Metrics-Monitor: Cannot import name _common(Python)?

Explorer

@Matthew McBride : @Saurabh

Would installing virtualenv solve the python version issue

as in this link - https://community.hortonworks.com/answers/10771/view.html , also address the issue of ps utils

Ambari-Metrics-Monitor: Cannot import name _common(Python)

?.

Don't have an account?
Coming from Hortonworks? Activate your account here