Describe the bug
I want to get VM CPU usage,
So I run MonitorClient(credentials, subscription_id).metrics.list()
But get error message:
AttributeError
'coroutine' object has no attribute 'token'
To Reproduce
Steps to reproduce the behavior:
-
Install package
azure-identity==1.4.0
azure-core==1.8.1
azure-mgmt-monitor==1.0.1
-
My credentials from ServicePrincipalCredentials
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
tenant = tenant_id,
client_id= app_id,
secret = password
)
- Get monitor_client
from azure.mgmt.monitor import MonitorClient
monitor_client = MonitorClient(credentials, subscription_id)
- Call metrics.list()
metrics_data = monitor_client.metrics.list(
resource_id,
timespan="{}/{}".format('2020-09-25T00:00:00', '2020-09-25T02:00:00'),
interval='PT1M',
metricnames='Percentage CPU',
aggregation='Average'
)
- Get Error
AttributeError
'ServicePrincipalCredentials' object has no attribute 'get_token'
- Change credentials from ClientSecretCredential
Reference by azure-mgmt-monitor/tests/test_cli_mgmt_monitor.py
from azure.identity.aio import ClientSecretCredential
credentials = ClientSecretCredential(
tenant = tenant_id,
client_id= app_id,
secret = password
)
- Run same code in step 2 and 3 again, Get error
AttributeError
'coroutine' object has no attribute 'token'
Expected behavior
Get VM CPU usage
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
All my code:
from azure.mgmt.monitor import MonitorClient
from azure.identity.aio import ClientSecretCredential
credentials = ClientSecretCredential(
tenant = tenant_id,
client_id= app_id,
secret = password
)
monitor_client = MonitorClient(credentials, subscription_id)
metrics_data = monitor_client.metrics.list(
resource_id,
timespan="{}/{}".format('2020-09-25T00:00:00', '2020-09-25T02:00:00'),
interval='PT1M',
metricnames='Percentage CPU',
aggregation='Average'
)
Package Name:
azure-mgmt-monitor
Package Version:
1.0.1
Operating System:
Ubuntu 18.04
Python Version:
3.7
Describe the bug
I want to get VM CPU usage,
So I run MonitorClient(credentials, subscription_id).metrics.list()
But get error message:
To Reproduce
Steps to reproduce the behavior:
Install package
azure-identity==1.4.0
azure-core==1.8.1
azure-mgmt-monitor==1.0.1
My credentials from ServicePrincipalCredentials
Reference by azure-mgmt-monitor/tests/test_cli_mgmt_monitor.py
Expected behavior
Get VM CPU usage
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
All my code: