0
// get metric definitions for storage account.
  for (MetricDefinition  metricDefinition : azure.metricDefinitions().listByResource(storageAccount.id())) {

Azure github has this example to get metrics for a storage account. I am struggling to find any reference on what should be passed as parameter to listByResource() to get VM Metric (for example Network In metric)? Appreciate any input.

kosa
  • 65,990
  • 13
  • 130
  • 167

1 Answers1

1

Firstly, if you want to get metrics supported by Azure Monitor, you could use this to query records. You could also find it in the sample code.

MetricCollection metricCollection = metricDefinition.defineQuery()
                        .startingFrom(recordDateTime.minusDays(7))
                        .endsBefore(recordDateTime)
                        .withAggregation("Average")
                        .withInterval(Period.minutes(5))
                        .withOdataFilter("apiName eq 'PutBlob' and responseType eq 'Success' and geoType eq 'Primary'")
                        .execute();

And about the method description, you could refer to this site.

As for the VM NetWork metric, I suppose it's not supported, in the official doc :Supported metrics with Azure Monitor on Azure Stack, it lists metrics supported by Azure Monitor. With Microsoft.Compute/virtualMachines, it only supports the Percentage CPU metric.

George Chen
  • 13,703
  • 2
  • 11
  • 26
  • Thank you, but one thing I am clear with above example is, where are we referencing the fact that we want "Percentage CPU metric"? – kosa Apr 29 '19 at 16:37
  • @kosa , in the example firstly get the get metric definitions for storage account with resource id, then find metric definition for Transactions(metric name Percentage CPU) after this define your query condition. The condition methods meanings are in the site, and the filter is using withOdataFilter. You need write a query to filter metric data. – George Chen Apr 30 '19 at 01:37
  • Thanks for taking time to help with information. What is this "storage account"? this is the thing confused me. When I am asking for "CPU", why do I need to provide "Storage account"? – kosa Apr 30 '19 at 15:44
  • @kosa, no you don't need a storage account, it's an example. What listByResource() need is resource id. This is the method description.https://azure.github.io/azure-sdk-for-java/com/microsoft/azure/management/monitor/MetricDefinitions.html#listByResource-java.lang.String- – George Chen May 01 '19 at 01:39