question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot create custom metric alert via azure cli.

See original GitHub issue

Note: this pertains to https://docs.microsoft.com/en-us/cli/azure/monitor/metrics?view=azure-cli-latest#az-monitor-metrics-list-definitions and https://docs.microsoft.com/en-us/cli/azure/monitor/metrics/alert?view=azure-cli-latest#az-monitor-metrics-alert-create

Describe the bug I ran

$aiid = "/subscriptions/CENSORED/resourceGroups/CENSORED/providers/microsoft.insights/components/CENSORED"
az monitor metrics list-definitions --resource $aiid

and expected to see my custom metric definitions (in custom namespaces), but didn’t found any custom metrics.

To Reproduce Log a custom metric from the source code using ApplicationIsnights. Observe you can create an alert using it it via azure portal, or view it in metrics view in AI. However, it is not listed via list-definitions, nor you can create an alert via Azure CLI using it, as it is not found.

Expected behavior The custom metric (and its namespace) to be listed, and accepted when creating an alert with az monitor metrics alert create.

Environment summary

az --version
azure-cli                         2.0.66

Additional context Confirmed the custom metrics also cannot be found via

Get-AzMetricDefinition -ResourceId $aiid

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
K31Dcommented, Aug 22, 2019

If you pass an empty string to -DynamicThreshold it lets you create the criteria unfortunatelly when you create the alert rule it comes with static “default” threshold.

protected override void ProcessRecordInternal() |  
-- | --
  | {
  | if(String.IsNullOrWhiteSpace(this.DynamicThreshold))
  | {
  | List<MetricDimension> metricDimensions = new List<MetricDimension>();
  |  
  | if (this.DimensionSelection!= null && this.DimensionSelection.Length > 0)
  | {
  | foreach (var dimension in this.DimensionSelection)
  | {
  | if (dimension.IncludeValues != null && dimension.IncludeValues.Count() > 0)
  | {
  | metricDimensions.Add(new MetricDimension(dimension.Dimension, "Include", dimension.IncludeValues));
  | }
  | if (dimension.ExcludeValues != null && dimension.ExcludeValues.Count() > 0)
  | {
  | metricDimensions.Add(new MetricDimension(dimension.Dimension, "Exclude", dimension.ExcludeValues));
  | }
  | }
  | }
  | else
  | {
  | metricDimensions = null;
  | }
  | MetricCriteria metricCriteria = new MetricCriteria(name: "metric1", metricName: this.MetricName, operatorProperty: this.Operator, timeAggregation: this.TimeAggregation, threshold: this.Threshold, metricNamespace: this.MetricNamespace, dimensions: metricDimensions);
  | PSMetricCriteria result = new PSMetricCriteria(metricCriteria);
  | WriteObject(sendToPipeline: result);
  | }
  | else
  | {
  | WriteExceptionError(new Exception("Creating   criteria for Dynamic Threshold is not yet supported"));
  | }

1reaction
snehithmcommented, Jul 5, 2019

Hi @konrad-jamrozik , @pajzo, thanks for reporting this. We are looking into this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frequently asked questions about Azure Monitor metric alerts
For a custom metric: Make sure that the metric is already being emitted because you can't create an alert rule on a custom...
Read more >
Create a metric alert with a Resource Manager template
You can create the metric alert using the template and parameters file by using PowerShell or the Azure CLI from your current working...
Read more >
Create a new alert rule - Azure Monitor - Microsoft Learn
Create a new alert rule in the Azure portal · On the Configure signal logic pane, you can preview the results of the...
Read more >
Manage your alert rules - Azure Monitor | Microsoft Learn
This section describes how to manage metric alert rules using the cross-platform Azure CLI. The following examples use Azure Cloud Shell.
Read more >
Create metric alert monitors in Azure CLI - Microsoft Learn
These samples create metric alert monitors in Azure Monitor by using Azure CLI commands. The first sample creates an alert for a virtual ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found