Greetings all,
I am trying to collect metrics for vm instances that appear in the insights activity logs.
The instance ids for the vms are found by searching for Compute/virtualMachines write, deallocate/action delete and start/action events using
$"subscriptions/{subscriptionId}/providers/Microsoft.Insights/eventtypes/management/values?api-version=2015-04-01&$filter={filter}";
A list of metric definitions is then requested using
$"https://management.azure.com{vm.Value.ResourceId}/providers/microsoft.insights/metricDefinitions".
Finally, aggregated metric values are requested from the returned metric definitions using
$"https://management.azure.com{vm.Value.ResourceId}/providers/microsoft.insights/metrics?timespan={queryTimespan}&interval=PT5M&metricnames={metricDefinition.Name.Value}&aggregation=Average&api-version=2018-01-01&metricnamespace={metricDefinition.Namespace}"
Any vms that only appear in the insights activity logs return "NotFound".
Vms that are found by calling ComputeManagementClient.VirtualMachines.ListAllAsync() from the .net API return aggregated metrics when using this approach.
The Azure Monitor Metrics overview indicates that metrics are retained for 93 days, and I'm searching for virtual machines that are often created and deleted for an hour or so within the previous 24 hours.
Can anyone offer any suggestions?
Many thanks in advance.