Azure Monitor のメトリック アラート ルール用の Resource Manager テンプレート サンプル
この記事では、Azure Resource Manager テンプレートを使用した Azure Monitor のメトリック アラート ルールの作成例を紹介します。 各サンプルには、テンプレート ファイルと、テンプレートに指定するサンプル値を含むパラメーター ファイルが含まれています。
Note
利用可能なサンプルのリスト、および Azure サブスクリプションへの各サンプルのデプロイ方法については、Azure Monitor の Azure Resource Manager のサンプルに関するページを参照してください。
メトリック アラート ルールで使用可能なリソース一覧については、「Azure Monitor のメトリック アラートでサポートされるリソース」を参照してください。 アラート ルールのスキーマとプロパティについては、「メトリック アラート - 作成または更新」を参照してください。
Note
リソースの種類のメトリック アラートを作成するためのリソース テンプレート、つまり Azure Log Analytics ワークスペース Microsoft.OperationalInsights/workspaces
には、追加の手順が必要です。 詳細については、ログのメトリック アラート - リソース テンプレート編に関するページを参照してください。
テンプレート リファレンス
1 条件と静的しきい値
次のサンプルでは、条件 1 つと静的しきい値を使用するメトリック アラート ルールを作成します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Full Resource ID of the resource emitting the metric that will be used for the comparison. For example /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroups/ResourceGroupName/providers/Microsoft.compute/virtualMachines/VM_xyz')
@minLength(1)
param resourceId string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'Equals'
'GreaterThan'
'GreaterThanOrEqual'
'LessThan'
'LessThanOrEqual'
])
param operator string = 'GreaterThan'
@description('The threshold value at which the alert is activated.')
param threshold int = 0
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format.')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
'PT6H'
'PT12H'
'PT24H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT1M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
resourceId
]
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
allOf: [
{
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
threshold: threshold
timeAggregation: timeAggregation
criterionType: 'StaticThresholdCriterion'
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "New Metric Alert"
},
"alertDescription": {
"value": "New metric alert created via template"
},
"alertSeverity": {
"value":3
},
"isEnabled": {
"value": true
},
"resourceId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourceGroup-name/providers/Microsoft.Compute/virtualMachines/replace-with-resource-name"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterThan"
},
"threshold": {
"value": 80
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group"
}
}
}
1 条件と動的しきい値
次のサンプルでは、条件 1 つと動的しきい値を使用するメトリック アラート ルールを作成します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Full Resource ID of the resource emitting the metric that will be used for the comparison. For example /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroups/ResourceGroupName/providers/Microsoft.compute/virtualMachines/VM_xyz')
@minLength(1)
param resourceId string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'GreaterThan'
'LessThan'
'GreaterOrLessThan'
])
param operator string = 'GreaterOrLessThan'
@description('Tunes how \'noisy\' the Dynamic Thresholds alerts will be: \'High\' will result in more alerts while \'Low\' will result in fewer alerts.')
@allowed([
'High'
'Medium'
'Low'
])
param alertSensitivity string = 'Medium'
@description('The number of periods to check in the alert evaluation.')
param numberOfEvaluationPeriods int = 4
@description('The number of unhealthy periods to alert on (must be lower or equal to numberOfEvaluationPeriods).')
param minFailingPeriodsToAlert int = 3
@description('Use this option to set the date from which to start learning the metric historical data and calculate the dynamic thresholds (in ISO8601 format, e.g. \'2019-12-31T22:00:00Z\').')
param ignoreDataBefore string = ''
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one hour. ISO 8601 duration format.')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT5M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
resourceId
]
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
criterionType: 'DynamicThresholdCriterion'
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
alertSensitivity: alertSensitivity
failingPeriods: {
numberOfEvaluationPeriods: numberOfEvaluationPeriods
minFailingPeriodsToAlert: minFailingPeriodsToAlert
}
ignoreDataBefore: ignoreDataBefore
timeAggregation: timeAggregation
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "New Metric Alert with Dynamic Thresholds"
},
"alertDescription": {
"value": "New metric alert with Dynamic Thresholds created via template"
},
"alertSeverity": {
"value":3
},
"isEnabled": {
"value": true
},
"resourceId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourceGroup-name/providers/Microsoft.Compute/virtualMachines/replace-with-resource-name"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterOrLessThan"
},
"alertSensitivity": {
"value": "Medium"
},
"numberOfEvaluationPeriods": {
"value": "4"
},
"minFailingPeriodsToAlert": {
"value": "3"
},
"ignoreDataBefore": {
"value": ""
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group"
}
}
}
複数条件と静的しきい値
メトリック アラートでは、複数ディメンションのメトリックでのアラートがサポートされており、条件はアラート ルールあたり 5 つまでサポートされます。 次のサンプルでは、ディメンション メトリックに対してメトリック アラート ルールを作成し、複数の条件を指定します。
複数の条件を含むアラート ルールでディメンションを使用する場合は、次の制約が適用されます。
各条件内では、ディメンションごとに 1 つの値のみを選択できます。
"*" をディメンション値として使用することはできません。
異なる条件内で構成されているメトリックが同じディメンションをサポートしている場合、構成するディメンションの値は、関連する条件内にあるこれらすべてのメトリックに対して同じ方法で明示的に設定する必要があります。
- 次の例では、Transactions と SuccessE2ELatency メトリックの両方に ApiName ディメンションがあり、criterion1 で ApiName ディメンションの "GetBlob" 値が指定されているためcriterion2 は ApiName ディメンションに "GetBlob" 値も設定する必要があります。
テンプレート ファイル
@description('Name of the alert')
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Resource ID of the resource emitting the metric that will be used for the comparison.')
param resourceId string = ''
@description('Criterion includes metric name, dimension values, threshold and an operator. The alert rule fires when ALL criteria are met')
param criterion1 object
@description('Criterion includes metric name, dimension values, threshold and an operator. The alert rule fires when ALL criteria are met')
param criterion2 object
@description('Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format.')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
'PT6H'
'PT12H'
'PT24H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT1M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
var criterion1_var = array(criterion1)
var criterion2_var = array(criterion2)
var criteria = concat(criterion1_var, criterion2_var)
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
resourceId
]
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
allOf: criteria
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "New Multi-dimensional Metric Alert (Replace with your alert name)"
},
"alertDescription": {
"value": "New multi-dimensional metric alert created via template (Replace with your alert description)"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"resourceId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourcegroup-name/providers/Microsoft.Storage/storageAccounts/replace-with-storage-account"
},
"criterion1": {
"value": {
"name": "1st criterion",
"metricName": "Transactions",
"dimensions": [
{
"name": "ResponseType",
"operator": "Include",
"values": [ "Success" ]
},
{
"name": "ApiName",
"operator": "Include",
"values": [ "GetBlob" ]
}
],
"operator": "GreaterThan",
"threshold": 5,
"timeAggregation": "Total"
}
},
"criterion2": {
"value": {
"name": "2nd criterion",
"metricName": "SuccessE2ELatency",
"dimensions": [
{
"name": "ApiName",
"operator": "Include",
"values": [ "GetBlob" ]
}
],
"operator": "GreaterThan",
"threshold": 250,
"timeAggregation": "Average"
}
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-actiongroup-name"
}
}
}
複数ディメンションと静的しきい値
1 つのアラート ルールで、複数のメトリック時系列を一度に監視できます。これにより、管理するアラート ルールが少なくなります。 次のサンプルでは、ディメンション メトリックに対して静的なメトリック アラート ルールを作成します。
この例では、アラート ルールによって、Transactions メトリックの ResponseType と ApiName ディメンションのディメンション値の組み合わせが監視されます。
- ResponseType - "*" ワイルド カードを使用することは、ResponseType ディメンションの各値 (将来の値を含む) について、異なる時系列が個別に監視されることを意味します。
- ApiName - GetBlob および PutBlob ディメンション値に対してのみ異なる時系列が監視されます。
たとえば、このアラート ルールによって監視される可能性のある時系列のいくつかを次に示します。
- Metric = Transactions, ResponseType = Success, ApiName = GetBlob
- Metric = Transactions, ResponseType = Success, ApiName = PutBlob
- Metric = Transactions, ResponseType = Server Timeout, ApiName = GetBlob
- Metric = Transactions, ResponseType = Server Timeout, ApiName = PutBlob
テンプレート ファイル
@description('Name of the alert')
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Resource ID of the resource emitting the metric that will be used for the comparison.')
param resourceId string = ''
@description('Criterion includes metric name, dimension values, threshold and an operator. The alert rule fires when ALL criteria are met')
param criterion object
@description('Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format.')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
'PT6H'
'PT12H'
'PT24H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT1M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
var criteria = array(criterion)
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
resourceId
]
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
allOf: criteria
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "New multi-dimensional metric alert rule (replace with your alert name)"
},
"alertDescription": {
"value": "New multi-dimensional metric alert rule created via template (replace with your alert description)"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"resourceId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourcegroup-name/providers/Microsoft.Storage/storageAccounts/replace-with-storage-account"
},
"criterion": {
"value": {
"name": "Criterion",
"metricName": "Transactions",
"dimensions": [
{
"name": "ResponseType",
"operator": "Include",
"values": [ "*" ]
},
{
"name": "ApiName",
"operator": "Include",
"values": [ "GetBlob", "PutBlob" ]
}
],
"operator": "GreaterThan",
"threshold": 5,
"timeAggregation": "Total"
}
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-actiongroup-name"
}
}
}
Note
ディメンション値として "すべて" を使用することは、"*" (現在および将来のすべての値) を選択することと同じです。
複数ディメンションと動的しきい値
1 つの動的しきい値アラート ルールによって、一度に数百のメトリック時系列 (異なる種類も可) のカスタマイズされたしきい値を作成できます。これにより、管理するアラートの数を抑えられます。 次のサンプルでは、ディメンション メトリックに対して動的しきい値のメトリック アラート ルールを作成します。
この例では、アラート ルールによって、Transactions メトリックの ResponseType と ApiName ディメンションのディメンション値の組み合わせが監視されます。
- ResponseType - ResponseType ディメンションの各値 (将来の値を含む) について、異なる時系列が個別に監視されます。
- ApiName - GetBlob および PutBlob ディメンション値に対してのみ異なる時系列が監視されます。
たとえば、このアラート ルールによって監視される可能性のある時系列のいくつかを次に示します。
- Metric = Transactions, ResponseType = Success, ApiName = GetBlob
- Metric = Transactions, ResponseType = Success, ApiName = PutBlob
- Metric = Transactions, ResponseType = Server Timeout, ApiName = GetBlob
- Metric = Transactions, ResponseType = Server Timeout, ApiName = PutBlob
Note
現在、動的しきい値を使用するメトリック アラート ルールでは複数の条件はサポートされていません。
テンプレート ファイル
@description('Name of the alert')
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Resource ID of the resource emitting the metric that will be used for the comparison.')
param resourceId string = ''
@description('Criterion includes metric name, dimension values, threshold and an operator.')
param criterion object
@description('Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one hour. ISO 8601 duration format.')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT5M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
var criteria = array(criterion)
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
resourceId
]
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: criteria
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "New Multi-dimensional Metric Alert with Dynamic Thresholds (Replace with your alert name)"
},
"alertDescription": {
"value": "New multi-dimensional metric alert with Dynamic Thresholds created via template (Replace with your alert description)"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"resourceId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourcegroup-name/providers/Microsoft.Storage/storageAccounts/replace-with-storage-account"
},
"criterion": {
"value": {
"criterionType": "DynamicThresholdCriterion",
"name": "1st criterion",
"metricName": "Transactions",
"dimensions": [
{
"name": "ResponseType",
"operator": "Include",
"values": [ "*" ]
},
{
"name": "ApiName",
"operator": "Include",
"values": [ "GetBlob", "PutBlob" ]
}
],
"operator": "GreaterOrLessThan",
"alertSensitivity": "Medium",
"failingPeriods": {
"numberOfEvaluationPeriods": "4",
"minFailingPeriodsToAlert": "3"
},
"timeAggregation": "Total"
}
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-actiongroup-name"
}
}
}
カスタム メトリックと静的しきい値
次のテンプレートを使用すると、カスタム メトリックに関するより高度な静的しきい値メトリック アラート ルールを作成できます。
Azure Monitor のカスタム メトリックの詳細については、「Azure Monitor のカスタム メトリック」を参照してください。
カスタム メトリックに関するアラート ルールを作成する場合は、メトリック名とメトリック名前空間の両方を指定する必要があります。 まだ存在しないカスタム メトリックに対してアラート ルールを作成することはできないため、カスタム メトリックが既に報告されていることを確認する必要もあります。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Full Resource ID of the resource emitting the metric that will be used for the comparison. For example /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroups/ResourceGroupName/providers/Microsoft.compute/virtualMachines/VM_xyz')
@minLength(1)
param resourceId string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Namespace of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricNamespace string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'Equals'
'GreaterThan'
'GreaterThanOrEqual'
'LessThan'
'LessThanOrEqual'
])
param operator string = 'GreaterThan'
@description('The threshold value at which the alert is activated.')
param threshold int = 0
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format.')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
'PT6H'
'PT12H'
'PT24H'
])
param windowSize string = 'PT5M'
@description('How often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT1M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
resourceId
]
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria'
allOf: [
{
name: '1st criterion'
metricName: metricName
metricNamespace: metricNamespace
dimensions: []
operator: operator
threshold: threshold
timeAggregation: timeAggregation
criterionType: 'StaticThresholdCriterion'
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "New alert rule on a custom metric"
},
"alertDescription": {
"value": "New alert rule on a custom metric created via template"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"resourceId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourceGroup-name/providers/microsoft.insights/components/replace-with-application-insights-resource-name"
},
"metricName": {
"value": "The custom metric name"
},
"metricNamespace": {
"value": "Azure.ApplicationInsights"
},
"operator": {
"value": "GreaterThan"
},
"threshold": {
"value": 80
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group"
}
}
}
Note
特定のカスタム メトリックのメトリック名前空間を確認するには、Azure portal でカスタム メトリックを参照します。
複数のリソース
Azure Monitor では、同じ Azure リージョンに存在するリソースに対して、メトリック アラート ルールが 1 つ設定されている、同種の複数リソースの監視がサポートされます。 現在、この機能は Azure パブリック クラウド内でのみサポートされており、仮想マシン、SQL Server データベース、SQL Server エラスティック プール、および Azure Stack Edge デバイス専用です。 また、この機能はプラットフォーム メトリックでのみ使用でき、カスタム メトリックではサポートされていません。
動的しきい値アラート ルールは、一度に数百のメトリック シリーズ (異なる種類でも) のカスタマイズされたしきい値を作成するためにも役立つことがあります。これにより、管理するアラートが少なくなります。
このセクションでは、1 つのルールで複数のリソースを監視する 3 つのシナリオの Azure Resource Manager テンプレートについて説明します。
- 1 つまたは複数のリソース グループ内の (1 つの Azure リージョン内の) すべての仮想マシンの監視。
- 1 つのサブスクリプション内の (1 つの Azure リージョン内の) すべての仮想マシンの監視。
- 1 つのサブスクリプション内の (1 つの Azure リージョン内の)、一覧に含まれる仮想マシンの監視。
Note
- 複数のリソースを監視するメトリック アラート ルールの場合、許可される条件は 1 つだけです。
- 1 つのリソースに対するメトリック アラートを作成している場合、テンプレートではターゲット リソースの
ResourceId
が使われます。 複数のリソースに対するメトリック アラートを作成している場合、テンプレートではターゲット リソースのscope
、TargetResourceType
、TargetResourceRegion
が使われます。
1 つまたは複数のリソース グループ内のすべての仮想マシンの静的しきい値アラート
このテンプレートによって、1 つまたは複数のリソース グループ内 (1 つの Azure リージョン内) のすべての仮想マシンの CPU 使用率を監視する静的しきい値メトリック アラート ルールが作成されます。
このチュートリアルでは、以下の JSON を all-vms-in-resource-group-static.json として保存します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Full path of the resource group(s) where target resources to be monitored are in. For example - /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroups/ResourceGroupName')
@minLength(1)
param targetResourceGroup array
@description('Azure region in which target resources to be monitored are in (without spaces). For example: EastUS')
@allowed([
'EastUS'
'EastUS2'
'CentralUS'
'NorthCentralUS'
'SouthCentralUS'
'WestCentralUS'
'WestUS'
'WestUS2'
'CanadaEast'
'CanadaCentral'
'BrazilSouth'
'NorthEurope'
'WestEurope'
'FranceCentral'
'FranceSouth'
'UKWest'
'UKSouth'
'GermanyCentral'
'GermanyNortheast'
'GermanyNorth'
'GermanyWestCentral'
'SwitzerlandNorth'
'SwitzerlandWest'
'NorwayEast'
'NorwayWest'
'SoutheastAsia'
'EastAsia'
'AustraliaEast'
'AustraliaSoutheast'
'AustraliaCentral'
'AustraliaCentral2'
'ChinaEast'
'ChinaNorth'
'ChinaEast2'
'ChinaNorth2'
'CentralIndia'
'WestIndia'
'SouthIndia'
'JapanEast'
'JapanWest'
'KoreaCentral'
'KoreaSouth'
'SouthAfricaWest'
'SouthAfricaNorth'
'UAECentral'
'UAENorth'
])
param targetResourceRegion string
@description('Resource type of target resources to be monitored.')
@minLength(1)
param targetResourceType string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'Equals'
'GreaterThan'
'GreaterThanOrEqual'
'LessThan'
'LessThanOrEqual'
])
param operator string = 'GreaterThan'
@description('The threshold value at which the alert is activated.')
param threshold string = '0'
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format.')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
'PT6H'
'PT12H'
'PT24H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
])
param evaluationFrequency string = 'PT1M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: targetResourceGroup
targetResourceType: targetResourceType
targetResourceRegion: targetResourceRegion
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
threshold: threshold
timeAggregation: timeAggregation
criterionType: 'StaticThresholdCriterion'
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "Multi-resource metric alert via Azure Resource Manager template"
},
"alertDescription": {
"value": "New Multi-resource metric alert created via template"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"targetResourceGroup": {
"value": [
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name1",
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name2"
]
},
"targetResourceRegion": {
"value": "SouthCentralUS"
},
"targetResourceType": {
"value": "Microsoft.Compute/virtualMachines"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterThan"
},
"threshold": {
"value": 0
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group-name"
}
}
}
1 つまたは複数のリソース グループ内のすべての仮想マシンの動的しきい値アラート
次のサンプルでは、1 つまたは複数のリソース グループの 1 つの Azure リージョンに含まれるすべての仮想マシンについて、CPU 使用率を監視する動的しきい値メトリック アラート ルールを作成します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Full path of the resource group(s) where target resources to be monitored are in. For example - /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroups/ResourceGroupName')
@minLength(1)
param targetResourceGroup array
@description('Azure region in which target resources to be monitored are in (without spaces). For example: EastUS')
@allowed([
'EastUS'
'EastUS2'
'CentralUS'
'NorthCentralUS'
'SouthCentralUS'
'WestCentralUS'
'WestUS'
'WestUS2'
'CanadaEast'
'CanadaCentral'
'BrazilSouth'
'NorthEurope'
'WestEurope'
'FranceCentral'
'FranceSouth'
'UKWest'
'UKSouth'
'GermanyCentral'
'GermanyNortheast'
'GermanyNorth'
'GermanyWestCentral'
'SwitzerlandNorth'
'SwitzerlandWest'
'NorwayEast'
'NorwayWest'
'SoutheastAsia'
'EastAsia'
'AustraliaEast'
'AustraliaSoutheast'
'AustraliaCentral'
'AustraliaCentral2'
'ChinaEast'
'ChinaNorth'
'ChinaEast2'
'ChinaNorth2'
'CentralIndia'
'WestIndia'
'SouthIndia'
'JapanEast'
'JapanWest'
'KoreaCentral'
'KoreaSouth'
'SouthAfricaWest'
'SouthAfricaNorth'
'UAECentral'
'UAENorth'
])
param targetResourceRegion string
@description('Resource type of target resources to be monitored.')
@minLength(1)
param targetResourceType string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'GreaterThan'
'LessThan'
'GreaterOrLessThan'
])
param operator string = 'GreaterOrLessThan'
@description('Tunes how \'noisy\' the Dynamic Thresholds alerts will be: \'High\' will result in more alerts while \'Low\' will result in fewer alerts.')
@allowed([
'High'
'Medium'
'Low'
])
param alertSensitivity string = 'Medium'
@description('The number of periods to check in the alert evaluation.')
param numberOfEvaluationPeriods int = 4
@description('The number of unhealthy periods to alert on (must be lower or equal to numberOfEvaluationPeriods).')
param minFailingPeriodsToAlert int = 3
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one hour. ISO 8601 duration format.')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT5M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: targetResourceGroup
targetResourceType: targetResourceType
targetResourceRegion: targetResourceRegion
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
criterionType: 'DynamicThresholdCriterion'
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
alertSensitivity: alertSensitivity
failingPeriods: {
numberOfEvaluationPeriods: numberOfEvaluationPeriods
minFailingPeriodsToAlert: minFailingPeriodsToAlert
}
timeAggregation: timeAggregation
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "Multi-resource metric alert with Dynamic Thresholds via Azure Resource Manager template"
},
"alertDescription": {
"value": "New Multi-resource metric alert with Dynamic Thresholds created via template"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"targetResourceGroup": {
"value": [
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name1",
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name2"
]
},
"targetResourceRegion": {
"value": "SouthCentralUS"
},
"targetResourceType": {
"value": "Microsoft.Compute/virtualMachines"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterOrLessThan"
},
"alertSensitivity": {
"value": "Medium"
},
"numberOfEvaluationPeriods": {
"value": "4"
},
"minFailingPeriodsToAlert": {
"value": "3"
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group-name"
}
}
}
サブスクリプション内のすべての仮想マシンの静的しきい値アラート
次のサンプルでは、1 サブスクリプションの 1 つの Azure リージョンに含まれるすべての仮想マシンの CPU 使用率を監視する静的しきい値メトリック アラート ルールを作成します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Azure Resource Manager path up to subscription ID. For example - /subscriptions/00000000-0000-0000-0000-0000-00000000')
@minLength(1)
param targetSubscription string
@description('Azure region in which target resources to be monitored are in (without spaces). For example: EastUS')
@allowed([
'EastUS'
'EastUS2'
'CentralUS'
'NorthCentralUS'
'SouthCentralUS'
'WestCentralUS'
'WestUS'
'WestUS2'
'CanadaEast'
'CanadaCentral'
'BrazilSouth'
'NorthEurope'
'WestEurope'
'FranceCentral'
'FranceSouth'
'UKWest'
'UKSouth'
'GermanyCentral'
'GermanyNortheast'
'GermanyNorth'
'GermanyWestCentral'
'SwitzerlandNorth'
'SwitzerlandWest'
'NorwayEast'
'NorwayWest'
'SoutheastAsia'
'EastAsia'
'AustraliaEast'
'AustraliaSoutheast'
'AustraliaCentral'
'AustraliaCentral2'
'ChinaEast'
'ChinaNorth'
'ChinaEast2'
'ChinaNorth2'
'CentralIndia'
'WestIndia'
'SouthIndia'
'JapanEast'
'JapanWest'
'KoreaCentral'
'KoreaSouth'
'SouthAfricaWest'
'SouthAfricaNorth'
'UAECentral'
'UAENorth'
])
param targetResourceRegion string
@description('Resource type of target resources to be monitored.')
@minLength(1)
param targetResourceType string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'Equals'
'GreaterThan'
'GreaterThanOrEqual'
'LessThan'
'LessThanOrEqual'
])
param operator string = 'GreaterThan'
@description('The threshold value at which the alert is activated.')
param threshold string = '0'
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format.')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
'PT6H'
'PT12H'
'PT24H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT1M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
targetSubscription
]
targetResourceType: targetResourceType
targetResourceRegion: targetResourceRegion
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
threshold: threshold
timeAggregation: timeAggregation
criterionType: 'StaticThresholdCriterion'
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "Multi-resource sub level metric alert via Azure Resource Manager template"
},
"alertDescription": {
"value": "New Multi-resource sub level metric alert created via template"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"targetSubscription": {
"value": "/subscriptions/replace-with-subscription-id"
},
"targetResourceRegion": {
"value": "SouthCentralUS"
},
"targetResourceType": {
"value": "Microsoft.Compute/virtualMachines"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterThan"
},
"threshold": {
"value": 0
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group-name"
}
}
}
サブスクリプション内のすべての仮想マシンの動的しきい値アラート
次のサンプルでは、1 つのサブスクリプション内 (1 つの Azure リージョン内) に含まれるすべての仮想マシンの CPU 使用率を監視する動的しきい値メトリック アラート ルールを作成します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('Azure Resource Manager path up to subscription ID. For example - /subscriptions/00000000-0000-0000-0000-0000-00000000')
@minLength(1)
param targetSubscription string
@description('Azure region in which target resources to be monitored are in (without spaces). For example: EastUS')
@allowed([
'EastUS'
'EastUS2'
'CentralUS'
'NorthCentralUS'
'SouthCentralUS'
'WestCentralUS'
'WestUS'
'WestUS2'
'CanadaEast'
'CanadaCentral'
'BrazilSouth'
'NorthEurope'
'WestEurope'
'FranceCentral'
'FranceSouth'
'UKWest'
'UKSouth'
'GermanyCentral'
'GermanyNortheast'
'GermanyNorth'
'GermanyWestCentral'
'SwitzerlandNorth'
'SwitzerlandWest'
'NorwayEast'
'NorwayWest'
'SoutheastAsia'
'EastAsia'
'AustraliaEast'
'AustraliaSoutheast'
'AustraliaCentral'
'AustraliaCentral2'
'ChinaEast'
'ChinaNorth'
'ChinaEast2'
'ChinaNorth2'
'CentralIndia'
'WestIndia'
'SouthIndia'
'JapanEast'
'JapanWest'
'KoreaCentral'
'KoreaSouth'
'SouthAfricaWest'
'SouthAfricaNorth'
'UAECentral'
'UAENorth'
])
param targetResourceRegion string
@description('Resource type of target resources to be monitored.')
@minLength(1)
param targetResourceType string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'GreaterThan'
'LessThan'
'GreaterOrLessThan'
])
param operator string = 'GreaterOrLessThan'
@description('Tunes how \'noisy\' the Dynamic Thresholds alerts will be: \'High\' will result in more alerts while \'Low\' will result in fewer alerts.')
@allowed([
'High'
'Medium'
'Low'
])
param alertSensitivity string = 'Medium'
@description('The number of periods to check in the alert evaluation.')
param numberOfEvaluationPeriods int = 4
@description('The number of unhealthy periods to alert on (must be lower or equal to numberOfEvaluationPeriods).')
param minFailingPeriodsToAlert int = 3
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one hour. ISO 8601 duration format.')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT5M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: [
targetSubscription
]
targetResourceType: targetResourceType
targetResourceRegion: targetResourceRegion
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
criterionType: 'DynamicThresholdCriterion'
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
alertSensitivity: alertSensitivity
failingPeriods: {
numberOfEvaluationPeriods: numberOfEvaluationPeriods
minFailingPeriodsToAlert: minFailingPeriodsToAlert
}
timeAggregation: timeAggregation
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "Multi-resource sub level metric alert with Dynamic Thresholds via Azure Resource Manager template"
},
"alertDescription": {
"value": "New Multi-resource sub level metric alert with Dynamic Thresholds created via template"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"targetSubscription": {
"value": "/subscriptions/replace-with-subscription-id"
},
"targetResourceRegion": {
"value": "SouthCentralUS"
},
"targetResourceType": {
"value": "Microsoft.Compute/virtualMachines"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterOrLessThan"
},
"alertSensitivity": {
"value": "Medium"
},
"numberOfEvaluationPeriods": {
"value": "4"
},
"minFailingPeriodsToAlert": {
"value": "3"
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group-name"
}
}
}
仮想マシンの一覧の静的しきい値アラート
次のサンプルでは、1 サブスクリプションの 1 つの Azure リージョンに含まれる仮想マシンの一覧の CPU 使用率を監視する静的しきい値メトリック アラート ルールを作成します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('array of Azure resource Ids. For example - /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroup/resource-group-name/Microsoft.compute/virtualMachines/vm-name')
@minLength(1)
param targetResourceId array
@description('Azure region in which target resources to be monitored are in (without spaces). For example: EastUS')
@allowed([
'EastUS'
'EastUS2'
'CentralUS'
'NorthCentralUS'
'SouthCentralUS'
'WestCentralUS'
'WestUS'
'WestUS2'
'CanadaEast'
'CanadaCentral'
'BrazilSouth'
'NorthEurope'
'WestEurope'
'FranceCentral'
'FranceSouth'
'UKWest'
'UKSouth'
'GermanyCentral'
'GermanyNortheast'
'GermanyNorth'
'GermanyWestCentral'
'SwitzerlandNorth'
'SwitzerlandWest'
'NorwayEast'
'NorwayWest'
'SoutheastAsia'
'EastAsia'
'AustraliaEast'
'AustraliaSoutheast'
'AustraliaCentral'
'AustraliaCentral2'
'ChinaEast'
'ChinaNorth'
'ChinaEast2'
'ChinaNorth2'
'CentralIndia'
'WestIndia'
'SouthIndia'
'JapanEast'
'JapanWest'
'KoreaCentral'
'KoreaSouth'
'SouthAfricaWest'
'SouthAfricaNorth'
'UAECentral'
'UAENorth'
])
param targetResourceRegion string
@description('Resource type of target resources to be monitored.')
@minLength(1)
param targetResourceType string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'Equals'
'GreaterThan'
'GreaterThanOrEqual'
'LessThan'
'LessThanOrEqual'
])
param operator string = 'GreaterThan'
@description('The threshold value at which the alert is activated.')
param threshold string = '0'
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between one minute and one day. ISO 8601 duration format.')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
'PT6H'
'PT12H'
'PT24H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT1M'
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT1M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: targetResourceId
targetResourceType: targetResourceType
targetResourceRegion: targetResourceRegion
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
threshold: threshold
timeAggregation: timeAggregation
criterionType: 'StaticThresholdCriterion'
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "Multi-resource metric alert by list via Azure Resource Manager template"
},
"alertDescription": {
"value": "New Multi-resource metric alert by list created via template"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"targetResourceId": {
"value": [
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name1/Microsoft.Compute/virtualMachines/replace-with-vm-name1",
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name2/Microsoft.Compute/virtualMachines/replace-with-vm-name2"
]
},
"targetResourceRegion": {
"value": "SouthCentralUS"
},
"targetResourceType": {
"value": "Microsoft.Compute/virtualMachines"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterThan"
},
"threshold": {
"value": 0
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group-name"
}
}
}
仮想マシンの一覧の動的しきい値アラート
次のサンプルでは、1 つのサブスクリプション内の 1 つの Azure リージョン内に含まれる仮想マシンの一覧の CPU 使用率を監視する動的しきい値メトリック アラート ルールを作成します。
テンプレート ファイル
@description('Name of the alert')
@minLength(1)
param alertName string
@description('Description of alert')
param alertDescription string = 'This is a metric alert'
@description('Severity of alert {0,1,2,3,4}')
@allowed([
0
1
2
3
4
])
param alertSeverity int = 3
@description('Specifies whether the alert is enabled')
param isEnabled bool = true
@description('array of Azure resource Ids. For example - /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroup/resource-group-name/Microsoft.compute/virtualMachines/vm-name')
@minLength(1)
param targetResourceId array
@description('Azure region in which target resources to be monitored are in (without spaces). For example: EastUS')
@allowed([
'EastUS'
'EastUS2'
'CentralUS'
'NorthCentralUS'
'SouthCentralUS'
'WestCentralUS'
'WestUS'
'WestUS2'
'CanadaEast'
'CanadaCentral'
'BrazilSouth'
'NorthEurope'
'WestEurope'
'FranceCentral'
'FranceSouth'
'UKWest'
'UKSouth'
'GermanyCentral'
'GermanyNortheast'
'GermanyNorth'
'GermanyWestCentral'
'SwitzerlandNorth'
'SwitzerlandWest'
'NorwayEast'
'NorwayWest'
'SoutheastAsia'
'EastAsia'
'AustraliaEast'
'AustraliaSoutheast'
'AustraliaCentral'
'AustraliaCentral2'
'ChinaEast'
'ChinaNorth'
'ChinaEast2'
'ChinaNorth2'
'CentralIndia'
'WestIndia'
'SouthIndia'
'JapanEast'
'JapanWest'
'KoreaCentral'
'KoreaSouth'
'SouthAfricaWest'
'SouthAfricaNorth'
'UAECentral'
'UAENorth'
])
param targetResourceRegion string
@description('Resource type of target resources to be monitored.')
@minLength(1)
param targetResourceType string
@description('Name of the metric used in the comparison to activate the alert.')
@minLength(1)
param metricName string
@description('Operator comparing the current value with the threshold value.')
@allowed([
'GreaterThan'
'LessThan'
'GreaterOrLessThan'
])
param operator string = 'GreaterOrLessThan'
@description('Tunes how \'noisy\' the Dynamic Thresholds alerts will be: \'High\' will result in more alerts while \'Low\' will result in fewer alerts.')
@allowed([
'High'
'Medium'
'Low'
])
param alertSensitivity string = 'Medium'
@description('The number of periods to check in the alert evaluation.')
param numberOfEvaluationPeriods int = 4
@description('The number of unhealthy periods to alert on (must be lower or equal to numberOfEvaluationPeriods).')
param minFailingPeriodsToAlert int = 3
@description('How the data that is collected should be combined over time.')
@allowed([
'Average'
'Minimum'
'Maximum'
'Total'
'Count'
])
param timeAggregation string = 'Average'
@description('Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one hour. ISO 8601 duration format.')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param windowSize string = 'PT5M'
@description('how often the metric alert is evaluated represented in ISO 8601 duration format')
@allowed([
'PT5M'
'PT15M'
'PT30M'
'PT1H'
])
param evaluationFrequency string = 'PT5M'
@description('The ID of the action group that is triggered when the alert is activated or deactivated')
param actionGroupId string = ''
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: alertName
location: 'global'
properties: {
description: alertDescription
severity: alertSeverity
enabled: isEnabled
scopes: targetResourceId
targetResourceType: targetResourceType
targetResourceRegion: targetResourceRegion
evaluationFrequency: evaluationFrequency
windowSize: windowSize
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
allOf: [
{
criterionType: 'DynamicThresholdCriterion'
name: '1st criterion'
metricName: metricName
dimensions: []
operator: operator
alertSensitivity: alertSensitivity
failingPeriods: {
numberOfEvaluationPeriods: numberOfEvaluationPeriods
minFailingPeriodsToAlert: minFailingPeriodsToAlert
}
timeAggregation: timeAggregation
}
]
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "Multi-resource metric alert with Dynamic Thresholds by list via Azure Resource Manager template"
},
"alertDescription": {
"value": "New Multi-resource metric alert with Dynamic Thresholds by list created via template"
},
"alertSeverity": {
"value": 3
},
"isEnabled": {
"value": true
},
"targetResourceId": {
"value": [
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name1/Microsoft.Compute/virtualMachines/replace-with-vm-name1",
"/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name2/Microsoft.Compute/virtualMachines/replace-with-vm-name2"
]
},
"targetResourceRegion": {
"value": "SouthCentralUS"
},
"targetResourceType": {
"value": "Microsoft.Compute/virtualMachines"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterOrLessThan"
},
"alertSensitivity": {
"value": "Medium"
},
"numberOfEvaluationPeriods": {
"value": "4"
},
"minFailingPeriodsToAlert": {
"value": "3"
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group-name"
}
}
}
メトリック アラートを使用した可用性テスト
Application Insights 可用性テストを使用すると、世界中のさまざまな場所から Web サイトやアプリケーションの可用性を監視することができます。 可用性テストに失敗した場所が所定の数に達すると、可用性テスト アラートから通知が届きます。 可用性テスト アラートの対象となるリソースの種類は、メトリック アラートと同じです (Microsoft.Insights/metricAlerts)。 次のサンプルでは、単純な可用性テストおよび関連するアラートを作成します。
Note
&
; は、& の HTML エンティティ参照です。 URL パラメーターは、1 つの & で分離されていますが、HTML で URL を記述した場合は、エンコードする必要があります。 そのため、pingURL パラメーターの値に "&" が含まれている場合は、"&
;" を使用してエスケープする必要があります。
テンプレート ファイル
param appName string
param pingURL string
param pingText string = ''
param actionGroupId string
param location string
var pingTestName = 'PingTest-${toLower(appName)}'
var pingAlertRuleName = 'PingAlert-${toLower(appName)}-${subscription().subscriptionId}'
resource pingTest 'Microsoft.Insights/webtests@2020-10-05-preview' = {
name: pingTestName
location: location
tags: {
'hidden-link:${resourceId('Microsoft.Insights/components', appName)}': 'Resource'
}
properties: {
Name: pingTestName
Description: 'Basic ping test'
Enabled: true
Frequency: 300
Timeout: 120
Kind: 'ping'
RetryEnabled: true
Locations: [
{
Id: 'us-va-ash-azr'
}
{
Id: 'emea-nl-ams-azr'
}
{
Id: 'apac-jp-kaw-edge'
}
]
Configuration: {
WebTest: '<WebTest Name="${pingTestName}" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="120" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale=""> <Items> <Request Method="GET" Version="1.1" Url="${pingURL}" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="200" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" /> </Items> <ValidationRules> <ValidationRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleFindText, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" DisplayName="Find Text" Description="Verifies the existence of the specified text in the response." Level="High" ExecutionOrder="BeforeDependents"> <RuleParameters> <RuleParameter Name="FindText" Value="${pingText}" /> <RuleParameter Name="IgnoreCase" Value="False" /> <RuleParameter Name="UseRegularExpression" Value="False" /> <RuleParameter Name="PassIfTextFound" Value="True" /> </RuleParameters> </ValidationRule> </ValidationRules> </WebTest>'
}
SyntheticMonitorId: pingTestName
}
}
resource metricAlert 'Microsoft.Insights/metricAlerts@2018-03-01' = {
name: pingAlertRuleName
location: 'global'
tags: {
'hidden-link:${resourceId('Microsoft.Insights/components', appName)}': 'Resource'
'hidden-link:${pingTest.id}': 'Resource'
}
properties: {
description: 'Alert for web test'
severity: 1
enabled: true
scopes: [
pingTest.id
resourceId('Microsoft.Insights/components', appName)
]
evaluationFrequency: 'PT1M'
windowSize: 'PT5M'
criteria: {
'odata.type': 'Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria'
webTestId: pingTest.id
componentId: resourceId('Microsoft.Insights/components', appName)
failedLocationCount: 2
}
actions: [
{
actionGroupId: actionGroupId
}
]
}
}
パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"value": "Replace with your Application Insights resource name"
},
"pingURL": {
"value": "https://www.yoursite.com"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourceGroup-name/providers/microsoft.insights/actiongroups/replace-with-action-group-name"
},
"location": {
"value": "Replace with the location of your Application Insights resource"
},
"pingText": {
"defaultValue": "Optional parameter that allows you to perform a content-match for the presence of a specific string within the content returned from a pingURL response",
"type": "String"
},
}
}
コンテンツ一致 pingText
パラメーターの追加構成は、テンプレート ファイルの Configuration/Webtest
部分で制御されます。 具体的には、以下のセクションを参照してください。
<RuleParameter Name=\"FindText\" Value=\"',parameters('pingText'), '\" />
<RuleParameter Name=\"IgnoreCase\" Value=\"False\" />
<RuleParameter Name=\"UseRegularExpression\" Value=\"False\" />
<RuleParameter Name=\"PassIfTextFound\" Value=\"True\" />
テストの場所
Id | リージョン |
---|---|
emea-nl-ams-azr |
西ヨーロッパ |
us-ca-sjc-azr |
米国西部 |
emea-ru-msa-edge |
英国南部 |
emea-se-sto-edge |
英国西部 |
apac-sg-sin-azr |
東南アジア |
us-tx-sn1-azr |
米国中南部 |
us-il-ch1-azr |
米国中北部 |
emea-gb-db3-azr |
北ヨーロッパ |
apac-jp-kaw-edge |
東日本 |
emea-fr-pra-edge |
フランス中部 |
emea-ch-zrh-edge |
フランス南部 |
us-va-ash-azr |
米国東部 |
apac-hk-hkn-azr |
東アジア |
us-fl-mia-edge |
米国中部 |
latam-br-gru-edge |
ブラジル南部 |
emea-au-syd-edge |
オーストラリア東部 |
米国政府のテストの場所
Id | リージョン |
---|---|
usgov-va-azr |
USGov Virginia |
usgov-phx-azr |
USGov Arizona |
usgov-tx-azr |
USGov Texas |
usgov-ddeast-azr |
USDoD East |
usgov-ddcentral-azr |
USDoD Central |