Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'MonitorManagementClient' object has no attribute 'metric_definitions' #1743

Closed
the1bit opened this issue Jan 9, 2018 · 4 comments
Labels
ARM question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@the1bit
Copy link

the1bit commented Jan 9, 2018

Hi,

I would like to manage the Azure subscription related metrics and alerts from Python. I have started the discovering of capabilities of this area and I am facing an serious issue.
I am following this article: https://docs.microsoft.com/en-us/python/api/overview/azure/monitoring?view=azure-python
After this line I receive an error message.
for metric in client.metric_definitions.list(resource_id): # azure.monitor.models.MetricDefinition print("{}: id={}, unit={}".format( metric.name.localized_value, metric.name.value, metric.unit ))

The error message is this:
AttributeError: 'MonitorManagementClient' object has no attribute 'metric_definitions'

Then I checked the client object and I relaized there is not "metric_definitions" in "MonitorManagementClient"

>>> dir(client)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_client', '_deserialize', '_serialize', 'activity_log_alerts', 'alert_rule_incidents', 'alert_rules', 'autoscale_settings', 'config', 'log_profiles', 'service_diagnostic_settings']

Package version: azure-mgmt-monitor (0.4.0)

May be this is my fault. Please help me to correct me if I am wrong...

Thank you for your support in this matter.

@lmazuel
Copy link
Member

lmazuel commented Jan 9, 2018

Hum, that's strange, there is definitely metric_definitions in this class. Based on your content, you have the 0.3.0 version installed. Could you:

  • print(azure.mgmt.monitor.__version__)
  • do a pip freeze to see the entire package suite?
    Thanks

@lmazuel lmazuel added question The issue doesn't require a change to the product in order to be resolved. Most issues start as that ARM Waiting answer labels Jan 9, 2018
@the1bit
Copy link
Author

the1bit commented Jan 10, 2018

Hi,

Yes, I found the class related information in the source.
Here are the results you requested:

  • print(azure.mgmt.monitor.__version__) : 0.2.1
  • Packages by pip freeze
    azure-batch==3.0.0
    azure-common==1.1.8
    azure-datalake-store==0.0.17
    azure-graphrbac==0.30.0
    azure-keyvault==0.3.7
    azure-mgmt==1.0.0
    azure-mgmt-authorization==0.30.0
    azure-mgmt-batch==4.0.0
    azure-mgmt-cdn==0.30.3
    azure-mgmt-cognitiveservices==1.0.0
    azure-mgmt-compute==1.0.0
    azure-mgmt-containerregistry==0.2.1
    azure-mgmt-datalake-analytics==0.1.6
    azure-mgmt-datalake-nspkg==2.0.0
    azure-mgmt-datalake-store==0.1.6
    azure-mgmt-devtestlabs==2.0.0
    azure-mgmt-dns==1.0.1
    azure-mgmt-documentdb==0.1.3
    azure-mgmt-iothub==0.2.2
    azure-mgmt-keyvault==0.31.0
    azure-mgmt-logic==2.1.0
    azure-mgmt-monitor==0.4.0
    azure-mgmt-network==1.0.0
    azure-mgmt-nspkg==2.0.0
    azure-mgmt-rdbms==0.1.0
    azure-mgmt-redis==4.1.1
    azure-mgmt-resource==1.1.0
    azure-mgmt-scheduler==1.1.3
    azure-mgmt-sql==0.5.3
    azure-mgmt-storage==1.0.0
    azure-mgmt-trafficmanager==0.30.0
    azure-mgmt-web==0.32.0
    azure-nspkg==2.0.0
    azure-servicebus==0.21.1
    azure-servicefabric==5.6.130
    azure-servicemanagement-legacy==0.20.6
    azure-storage==0.34.3

Thank you for your support.

@the1bit
Copy link
Author

the1bit commented Jan 10, 2018

Hi,

I guess I have found the solution. Unfortunately I do not know how did it happen.

  1. I checked the version of packages: pip freeze (result: azure-mgmt-monitor==0.4.0)
  2. I tried to uninstall the whole "azure-mgmt-monitor" package: pip uninstall azure-mgmt-monitor
  3. I checked the version of packages again: pip freeze (result: azure-mgmt-monitor==0.2.1)
  4. I tried to uninstall the whole "azure-mgmt-monitor" package again: pip uninstall azure-mgmt-monitor
  5. The "azure-mgmt-monitor" was gone now.
  6. Reinstall "azure-mgmt-monitor" package: pip install azure-mgmt-monitor
  7. I checked the version of packages again: pip freeze (result: azure-mgmt-monitor==0.4.0)

Finally I have checked the "metric_definitions" attribute at "MonitorManagementClient" object.
>>> dir(client)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_client', '_deserialize', '_serialize', 'action_groups', 'activity_log_alerts', 'activity_logs', 'alert_rule_incidents', 'alert_rules', 'autoscale_settings', 'config', 'diagnostic_settings', 'diagnostic_settings_category', 'event_categories', 'log_profiles', 'metric_definitions', 'metrics', 'operations', 'tenant_activity_logs']

This means we win and the required version of "azure-mgmt-monitor" is available from now.

Do you have any idea how it could happen?

Thank you for your help again.

@lmazuel
Copy link
Member

lmazuel commented Jan 10, 2018

This can happen if you use an old version of virtualenv, and you install the package in the system and then in the virtualenv. This flag was by default in old versions:
https://virtualenv.pypa.io/en/stable/userguide/#the-system-site-packages-option

But since you didn't talk about virtualenv, I guess it's not that.

One other solution would be if your "pip" does not use your default "python". To be sure your pip and your Python are the same, "python -m pip" will execute the pip installed for your Python.

The best way to have known, would have been to check azure.mgmt.monitor.__file__ the both times; to see where both versions were installed.

@lmazuel lmazuel closed this as completed Jan 10, 2018
@bsiegel bsiegel added the Service Attention Workflow: This issue is responsible by Azure service team. label Sep 26, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ARM question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants