Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.55k stars 2.77k forks source link

List instances from resource #6368

Closed bulkware closed 5 years ago

bulkware commented 5 years ago

Hello,

I am unable to use "cloud_roleName" as a parameter while retrieving metrics from resource: https://github.com/Azure/azure-sdk-for-python/issues/6103

And the "Application Insights SDK for Python" seems to be only for sending telemetry and not for retrieving metrics. So I tried the same thing using the Azure CLI client and did not succeed in that either: https://github.com/Azure/azure-cli/issues/9934

But I found out that I could use the "role_instanceName" as a filter option for both the Azure CLI and the "Azure SDK for Python":

az monitor metrics list --resource "/subscriptions/***/resourceGroups/***/providers/microsoft.insights/components/***" --metric "performanceCounters/processCpuPercentage" --aggregation "Total" --start-time "2019-07-16 05:00:00" --end-time "2019-07-16 05:01:00" --filter "cloud/roleInstance eq '*'"

Some time ago I got the answer that the filter option seems to be deprecated: https://github.com/Azure/azure-sdk-for-python/issues/5243

So now I don't know if I should use the filter option or not. It does seem to work in this case, but not as I intended in the first place. Should I use it or not?

Second question is, how can I get a list of these "cloud_roleInstances" because the only way I can do this is by making a query for metrics with the filter option as "cloud/roleInstance eq '*'"?

lmazuel commented 5 years ago

Hi @bulkware I'm sorry if I induced you in error, this is the complete signature of metrics.list:

list(resource_uri, timespan=None, interval=None, metricnames=None, aggregation=None, top=None, orderby=None, filter=None, result_type=None, metricnamespace=None, custom_headers=None, raw=False, **operation_config)

filter is NOT deprecated, my point was that the sample you talked about was made before aggregation or interval where parameters, and then at this point you needed to create a complete string manually with join to get any results. I didn't mean that filter itself was deprecated, but mostly the usage of filter in the sample you mentioned was. Sorry again for the miscommunication.

I do not know how to get a list of cloud/roleInstance. @tjprescott would you happen to know?

tjprescott commented 5 years ago

I don't. You would need to reach out the Monitor team.

bulkware commented 5 years ago

How can I reach the Monitor team?

lmazuel commented 5 years ago

Hi @bulkware, I asked @anirudhcavale from the monitor team and he told me you must pass result_type="Metadata" to get what you want.

bulkware commented 5 years ago

Ok. This is handy for limiting data =)

I still don't know what is the correct way to get a list of cloud_roleInstances. I assume it's perfectly valid to list cloud_roleInstances using the metrics list method, filter using "cloud/roleInstance eq '*' and result_type="Metadata"? I cannot get a list of these instances by any other way.

And I still don't know how can I get a list of cloud_roleNames or filter using them. I don't know if this is even possible right now.

anirudhcavale commented 5 years ago

@bulkware that's correct. The intended way to get a list of cloud_roleinstances values (or any dimension's values) is to call the list metrics API with result_type = Metadata. Is cloud_roleNames a dimension on the particular App Insights metric? If it is, then you can run the same API call with the dimension = * as well. If its not then its not data the metric allows to be split or filtered on.

bulkware commented 5 years ago

Ok, so now I have a list of instances using the metric-queries.

I also checked the output of "az monitor metrics list-definitions --resource ***" and found out that the "cloud_roleName" is in fact a dimension in some of the metrics. It was not set as a dimension for all the metrics, so that was the first thing that lead me astray. Now that I found out the metrics that support it and how to filter using them I have what I need.

Thank all for your support, you've been very helpful =)

CrashLaker commented 4 years ago

Hi all. I know there's an API limit to the amount of datapoints I request when calling metrics.list. Does anyone know the exact number or where's it documented?