Prometheus Rule Groups - Create Or Update

Create or update a Prometheus rule group definition.

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/prometheusRuleGroups/{ruleGroupName}?api-version=2023-03-01

URI Parameters

Name In Required Type Description
resourceGroupName
path True

string

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

ruleGroupName
path True

string

The name of the rule group.

Regex pattern: ^[^:@/#{}%&+*<>?]+$

subscriptionId
path True

string

The ID of the target subscription.

api-version
query True

string

The API version to use for this operation.

Request Body

Name Required Type Description
location True

string

The geo-location where the resource lives

properties.rules True

PrometheusRule[]

Defines the rules in the Prometheus rule group.

properties.scopes True

string[]

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

properties.clusterName

string

Apply rule to data from a specific cluster.

properties.description

string

Rule group description.

properties.enabled

boolean

Enable/disable rule group.

properties.interval

string

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

tags

object

Resource tags.

Responses

Name Type Description
200 OK

PrometheusRuleGroupResource

OK (Updated).

201 Created

PrometheusRuleGroupResource

Created (New Alert rule was created).

Other Status Codes

ErrorResponse

Error response describing why the operation failed.

Examples

Create or Update a cluster centric PrometheusRuleGroup
Create or Update a PrometheusRuleGroup

Create or Update a cluster centric PrometheusRuleGroup

Sample request

PUT https://management.azure.com/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup?api-version=2023-03-01

{
  "location": "East US",
  "properties": {
    "description": "This is a rule group with culster centric configuration",
    "interval": "PT10M",
    "clusterName": "myClusterName",
    "scopes": [
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace",
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myClusterName"
    ],
    "rules": [
      {
        "alert": "Billing_Processing_Very_Slow",
        "expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
        "enabled": true,
        "severity": 2,
        "for": "PT5M",
        "labels": {
          "team": "prod"
        },
        "annotations": {
          "annotationName1": "annotationValue1"
        },
        "resolveConfiguration": {
          "autoResolved": true,
          "timeToResolve": "PT10M"
        },
        "actions": []
      }
    ]
  }
}

Sample response

{
  "id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup",
  "type": "Microsoft.AlertsManagement/prometheusRuleGroups",
  "location": "East US",
  "properties": {
    "description": "This is a rule group with culster centric configuration",
    "interval": "PT10M",
    "clusterName": "myClusterName",
    "scopes": [
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace",
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myClusterName"
    ],
    "rules": [
      {
        "alert": "Billing_Processing_Very_Slow",
        "expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
        "enabled": true,
        "severity": 2,
        "for": "PT5M",
        "labels": {
          "team": "prod"
        },
        "annotations": {
          "annotationName1": "annotationValue1"
        },
        "resolveConfiguration": {
          "autoResolved": true,
          "timeToResolve": "PT10M"
        },
        "actions": []
      }
    ]
  }
}
{
  "id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup",
  "type": "Microsoft.AlertsManagement/prometheusRuleGroups",
  "location": "East US",
  "properties": {
    "description": "This is a rule group with culster centric configuration",
    "interval": "PT10M",
    "clusterName": "myClusterName",
    "scopes": [
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace",
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myClusterName"
    ],
    "rules": [
      {
        "alert": "Billing_Processing_Very_Slow",
        "expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
        "enabled": true,
        "severity": 2,
        "for": "PT5M",
        "labels": {
          "team": "prod"
        },
        "annotations": {
          "annotationName1": "annotationValue1"
        },
        "resolveConfiguration": {
          "autoResolved": true,
          "timeToResolve": "PT10M"
        },
        "actions": []
      }
    ]
  }
}

Create or Update a PrometheusRuleGroup

Sample request

PUT https://management.azure.com/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup?api-version=2023-03-01

{
  "location": "East US",
  "properties": {
    "description": "This is the description of the following rule group",
    "enabled": true,
    "interval": "PT10M",
    "clusterName": "myClusterName",
    "scopes": [
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace"
    ],
    "rules": [
      {
        "record": "job_type:billing_jobs_duration_seconds:99p5m",
        "expression": "histogram_quantile(0.99, sum(rate(jobs_duration_seconds_bucket{service=\"billing-processing\"}[5m])) by (job_type))",
        "labels": {
          "team": "prod"
        }
      },
      {
        "alert": "Billing_Processing_Very_Slow",
        "expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
        "enabled": true,
        "severity": 2,
        "for": "PT5M",
        "labels": {
          "team": "prod"
        },
        "annotations": {
          "annotationName1": "annotationValue1"
        },
        "resolveConfiguration": {
          "autoResolved": true,
          "timeToResolve": "PT10M"
        },
        "actions": [
          {
            "actionGroupId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/myrg/providers/microsoft.insights/actiongroups/myactiongroup",
            "actionProperties": {
              "key11": "value11",
              "key12": "value12"
            }
          },
          {
            "actionGroupId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/myrg/providers/microsoft.insights/actiongroups/myotheractiongroup",
            "actionProperties": {
              "key21": "value21",
              "key22": "value22"
            }
          }
        ]
      }
    ]
  }
}

Sample response

{
  "id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup",
  "type": "Microsoft.AlertsManagement/prometheusRuleGroups",
  "location": "East US",
  "properties": {
    "description": "This is the description of the following rule group",
    "enabled": true,
    "interval": "PT10M",
    "clusterName": "myClusterName",
    "scopes": [
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace"
    ],
    "rules": [
      {
        "record": "job_type:billing_jobs_duration_seconds:99p5m",
        "expression": "histogram_quantile(0.99, sum(rate(jobs_duration_seconds_bucket{service=\"billing-processing\"}[5m])) by (job_type))",
        "labels": {
          "team": "prod"
        }
      },
      {
        "alert": "Billing_Processing_Very_Slow",
        "expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
        "enabled": true,
        "severity": 2,
        "for": "PT5M",
        "labels": {
          "team": "prod"
        },
        "annotations": {
          "annotationName1": "annotationValue1"
        },
        "resolveConfiguration": {
          "autoResolved": true,
          "timeToResolve": "PT10M"
        },
        "actions": [
          {
            "actionGroupId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/myrg/providers/microsoft.insights/actiongroups/myactiongroup",
            "actionProperties": {
              "key11": "value11",
              "key12": "value12"
            }
          },
          {
            "actionGroupId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/myrg/providers/microsoft.insights/actiongroups/myotheractiongroup",
            "actionProperties": {
              "key21": "value21",
              "key22": "value22"
            }
          }
        ]
      }
    ]
  }
}
{
  "id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/promResourceGroup/providers/Microsoft.AlertsManagement/prometheusRuleGroups/myPrometheusRuleGroup",
  "type": "Microsoft.AlertsManagement/prometheusRuleGroups",
  "location": "East US",
  "properties": {
    "description": "This is the description of the following rule group",
    "enabled": true,
    "interval": "PT10M",
    "clusterName": "myClusterName",
    "scopes": [
      "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/myResourceGroup/providers/microsoft.monitor/accounts/myAzureMonitorWorkspace"
    ],
    "rules": [
      {
        "record": "job_type:billing_jobs_duration_seconds:99p5m",
        "expression": "histogram_quantile(0.99, sum(rate(jobs_duration_seconds_bucket{service=\"billing-processing\"}[5m])) by (job_type))",
        "labels": {
          "team": "prod"
        }
      },
      {
        "alert": "Billing_Processing_Very_Slow",
        "expression": "job_type:billing_jobs_duration_seconds:99p5m > 30",
        "enabled": true,
        "severity": 2,
        "for": "PT5M",
        "labels": {
          "team": "prod"
        },
        "annotations": {
          "annotationName1": "annotationValue1"
        },
        "resolveConfiguration": {
          "autoResolved": true,
          "timeToResolve": "PT10M"
        },
        "actions": [
          {
            "actionGroupId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/myrg/providers/microsoft.insights/actiongroups/myactiongroup",
            "actionProperties": {
              "key11": "value11",
              "key12": "value12"
            }
          },
          {
            "actionGroupId": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourcegroups/myrg/providers/microsoft.insights/actiongroups/myotheractiongroup",
            "actionProperties": {
              "key21": "value21",
              "key22": "value22"
            }
          }
        ]
      }
    ]
  }
}

Definitions

Name Description
createdByType

The type of identity that created the resource.

ErrorAdditionalInfo

The resource management error additional info.

ErrorDetail

The error detail.

ErrorResponse

Error response

PrometheusRule

An Azure Prometheus alerting or recording rule.

PrometheusRuleGroupAction

An alert action. Only relevant for alerts.

PrometheusRuleGroupResource

The Prometheus rule group resource.

PrometheusRuleResolveConfiguration

Specifies the Prometheus alert rule configuration.

systemData

Metadata pertaining to creation and last modification of the resource.

createdByType

The type of identity that created the resource.

Name Type Description
Application

string

Key

string

ManagedIdentity

string

User

string

ErrorAdditionalInfo

The resource management error additional info.

Name Type Description
info

object

The additional info.

type

string

The additional info type.

ErrorDetail

The error detail.

Name Type Description
additionalInfo

ErrorAdditionalInfo[]

The error additional info.

code

string

The error code.

details

ErrorDetail[]

The error details.

message

string

The error message.

target

string

The error target.

ErrorResponse

Error response

Name Type Description
error

ErrorDetail

The error object.

PrometheusRule

An Azure Prometheus alerting or recording rule.

Name Type Description
actions

PrometheusRuleGroupAction[]

Actions that are performed when the alert rule becomes active, and when an alert condition is resolved.

alert

string

Alert rule name.

annotations

object

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.

enabled

boolean

Enable/disable rule.

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'.

for

string

The amount of time alert must be active before firing.

labels

object

Labels to add or overwrite before storing the result.

record

string

Recorded metrics name.

resolveConfiguration

PrometheusRuleResolveConfiguration

Defines the configuration for resolving fired alerts. Only relevant for alerts.

severity

integer

The severity of the alerts fired by the rule. Must be between 0 and 4.

PrometheusRuleGroupAction

An alert action. Only relevant for alerts.

Name Type Description
actionGroupId

string

The resource id of the action group to use.

actionProperties

object

The properties of an action group object.

PrometheusRuleGroupResource

The Prometheus rule group resource.

Name Type Description
id

string

Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}

location

string

The geo-location where the resource lives

name

string

The name of the resource

properties.clusterName

string

Apply rule to data from a specific cluster.

properties.description

string

Rule group description.

properties.enabled

boolean

Enable/disable rule group.

properties.interval

string

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

properties.rules

PrometheusRule[]

Defines the rules in the Prometheus rule group.

properties.scopes

string[]

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

systemData

systemData

Azure Resource Manager metadata containing createdBy and modifiedBy information.

tags

object

Resource tags.

type

string

The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts"

PrometheusRuleResolveConfiguration

Specifies the Prometheus alert rule configuration.

Name Type Description
autoResolved

boolean

Enable alert auto-resolution.

timeToResolve

string

Alert auto-resolution timeout.

systemData

Metadata pertaining to creation and last modification of the resource.

Name Type Description
createdAt

string

The timestamp of resource creation (UTC).

createdBy

string

The identity that created the resource.

createdByType

createdByType

The type of identity that created the resource.

lastModifiedAt

string

The timestamp of resource last modification (UTC)

lastModifiedBy

string

The identity that last modified the resource.

lastModifiedByType

createdByType

The type of identity that last modified the resource.