New-AzPrometheusRuleGroup

Create or update a Prometheus rule group definition.

Syntax

New-AzPrometheusRuleGroup
   -ResourceGroupName <String>
   -RuleGroupName <String>
   [-SubscriptionId <String>]
   -Location <String>
   -Rule <IPrometheusRule[]>
   -Scope <String[]>
   [-ClusterName <String>]
   [-Description <String>]
   [-Enabled]
   [-Interval <TimeSpan>]
   [-Tag <Hashtable>]
   [-DefaultProfile <PSObject>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

Create or update a Prometheus rule group definition.

Examples

Example 1: Create Prometheus rule group definition with one rule.

$rule1 = New-AzPrometheusRuleObject -Record "job_type:billing_jobs_duration_seconds:99p5m"
$scope = "/subscriptions/fffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/MyresourceGroup/providers/microsoft.monitor/accounts/MyAccounts"
New-AzPrometheusRuleGroup -ResourceGroupName MyresourceGroup -RuleGroupName MyRuleGroup -Location eastus -Rule $rule1 -Scope $scope -Enabled

Name        Location ClusterName Enabled
----        -------- ----------- -------
MyRuleGroup eastus               True

Create Prometheus rule group definition with one rule.

Example 2: Create Prometheus rule group definition with rules.

$rule1 = New-AzPrometheusRuleObject -Record "job_type:billing_jobs_duration_seconds:99p5m"
$action =  New-AzPrometheusRuleGroupActionObject -ActionGroupId /subscriptions/fffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/MyresourceGroup/providers/microsoft.insights/actiongroups/MyActionGroup -ActionProperty @{"key1" = "value1"}
$Timespan = New-TimeSpan -Minutes 15
$rule2 = New-AzPrometheusRuleObject -Alert Billing_Processing_Very_Slow -Expression "job_type:billing_jobs_duration_seconds:99p5m > 30" -Enabled $false -Severity 3 -For $Timespan -Label @{"team"="prod"} -Annotation @{"annotation" = "value"} -ResolveConfigurationAutoResolved $true -ResolveConfigurationTimeToResolve $Timespan -Action $action
$rules = @($rule1, $rule2)
$scope = "/subscriptions/fffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/MyresourceGroup/providers/microsoft.monitor/accounts/MyAccounts"
New-AzPrometheusRuleGroup -ResourceGroupName MyresourceGroup -RuleGroupName MyRuleGroup -Location eastus -Rule $rule1 -Scope $scope -Enabled

Name        Location ClusterName Enabled
----        -------- ----------- -------
MyRuleGroup eastus               True

Create Prometheus rule group definition with rules.

Parameters

-ClusterName

Apply rule to data from a specific cluster.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.

Type:PSObject
Aliases:AzureRMContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Description

Rule group description.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Enabled

Enable/disable rule group.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Interval

The interval in which to run the Prometheus rule group represented in ISO 8601 duration format. Should be between 1 and 15 minutes

Type:TimeSpan
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Location

The geo-location where the resource lives

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ResourceGroupName

The name of the resource group. The name is case insensitive.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Rule

Defines the rules in the Prometheus rule group. To construct, see NOTES section for RULE properties and create a hash table.

Type:IPrometheusRule[]
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-RuleGroupName

The name of the rule group.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Scope

Target Azure Monitor workspaces resource ids. This api-version is currently limited to creating with one scope. This may change in future.

Type:String[]
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-SubscriptionId

The ID of the target subscription.

Type:String
Position:Named
Default value:(Get-AzContext).Subscription.Id
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Tag

Resource tags.

Type:Hashtable
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Outputs

IPrometheusRuleGroupResource

Notes

ALIASES

COMPLEX PARAMETER PROPERTIES

To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.

RULE <IPrometheusRule[]>: Defines the rules in the Prometheus rule group.

  • Expression <String>: The PromQL expression to evaluate. https://prometheus.io/docs/prometheus/latest/querying/basics/. Evaluated periodically as given by 'interval', and the result recorded as a new set of time series with the metric name as given by 'record'.
  • [Action <IPrometheusRuleGroupAction[]>]: Actions that are performed when the alert rule becomes active, and when an alert condition is resolved.
    • [ActionGroupId <String>]: The resource id of the action group to use.
    • [ActionProperty <IPrometheusRuleGroupActionProperties>]: The properties of an action group object.
      • [(Any) <String>]: This indicates any property can be added to this object.
  • [Alert <String>]: Alert rule name.
  • [Annotation <IPrometheusRuleAnnotations>]: The annotations clause specifies a set of informational labels that can be used to store longer additional information such as alert descriptions or runbook links. The annotation values can be templated.
    • [(Any) <String>]: This indicates any property can be added to this object.
  • [Enabled <Boolean?>]: Enable/disable rule.
  • [For <TimeSpan?>]: The amount of time alert must be active before firing.
  • [Label <IPrometheusRuleLabels>]: Labels to add or overwrite before storing the result.
    • [(Any) <String>]: This indicates any property can be added to this object.
  • [Record <String>]: Recorded metrics name.
  • [ResolveConfigurationAutoResolved <Boolean?>]: Enable alert auto-resolution.
  • [ResolveConfigurationTimeToResolve <TimeSpan?>]: Alert auto-resolution timeout.
  • [Severity <Int32?>]: The severity of the alerts fired by the rule. Must be between 0 and 4.