自动缩放的诊断设置

自动缩放有两个日志类别和一组指标,可通过“自动缩放设置”页上的“诊断设置”选项卡启用。

这两个类别是:

有关自动缩放指标的详细信息,请参阅支持的指标文档。

可以将日志和指标发送到各个目标:

  • Log Analytics 工作区
  • 存储帐户
  • 事件中心
  • 合作伙伴解决方案

有关诊断的详细信息,请参阅 Azure Monitor 中的诊断设置

运行历史记录

在“运行历史记录”选项卡中查看自动缩放活动的历史记录。“运行历史记录”选项卡包括一段时间内的资源实例计数图表以及自动缩放的资源活动日志条目。

屏幕截图显示了“自动缩放设置”页上的“运行历史记录”选项卡。

资源日志架构

以下示例是包含示例数据的自动缩放资源日志的一般格式。 并非所有示例都是格式正确的 JSON,因为它们可能包含给定字段的有效列表。

使用这些日志来排查自动缩放中的问题。 有关详细信息,请参阅排查自动缩放问题

备注

虽然日志描述的是“纵向扩展”和“纵向缩减”操作,但实际采取的操作是横向缩减或横向扩展。

自动缩放评估日志

以下架构显示在自动缩放评估日志中。

配置文件评估

在自动缩放首次查看自动缩放配置文件时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": ["FixedDateProfileEvaluation", "RecurrentProfileEvaluation", "DefaultProfileEvaluation"],
  "category": "AutoscaleEvaluations",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "profile": "defaultProfile",
    "profileSelected": [true, false]
  }
}

配置文件冷却评估

在自动缩放评估是否因冷却期而不应缩放时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "ScaleRuleCooldownEvaluation",
  "category": "AutoscaleEvaluations",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "selectedProfile": "defaultProfile",
    "scaleDirection": ["Increase", "Decrease"]
    "lastScaleActionTime": "2018-09-10 18:08:00.6132593",
    "cooldown": "00:30:00",
    "evaluationTime": "2018-09-10 18:11:00.6132593",
    "skipRuleEvaluationForCooldown": true
  }
}

规则评估

在自动缩放首次开始评估特定缩放规则时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "ScaleRuleEvaluation",
  "category": "AutoscaleEvaluations",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "metricName": "Percentage CPU",
    "metricNamespace": "",
    "timeGrain": "00:01:00",
    "timeGrainStatistic": "Average",
    "timeWindow": "00:10:00",
    "timeAggregationType": "Average",
    "operator": "GreaterThan",
    "threshold": 70,
    "observedValue": 25,
    "estimateScaleResult": ["Triggered", "NotTriggered", "Unknown"]
  }
}

指标评估

在自动缩放评估用于触发缩放操作的指标时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "MetricEvaluation",
  "category": "AutoscaleEvaluations",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "metricName": "Percentage CPU",
    "metricNamespace": "",
    "timeGrain": "00:01:00",
    "timeGrainStatistic": "Average",
    "startTime": "2018-09-10 18:00:00.43833793",
    "endTime": "2018-09-10 18:10:00.43833793",
    "data": [0.33333333333333331,0.16666666666666666,1.0,0.33333333333333331,2.0,0.16666666666666666,9.5]
  }
}

实例计数评估

在自动缩放评估已在运行的实例数以便决定是否应启动更多实例、关闭某些实例或不执行任何操作时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "InstanceCountEvaluation",
  "category": "AutoscaleEvaluations",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "currentInstanceCount": 20,
    "minimumInstanceCount": 15,
    "maximumInstanceCount": 30,
    "defaultInstanceCount": 20
  }
}

缩放操作评估

在自动缩放开始评估是否应执行某个缩放操作时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "ScaleActionOperationEvaluation",
  "category": "AutoscaleEvaluations",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "lastScaleActionOperationId": "378ejr-7yye-892d-17dd-92ndijfe1738",
    "lastScaleActionOperationStatus": ["InProgress", "Timeout"]
	"skipCurrentAutoscaleEvaluation": [true, false]
  }
}

实例更新评估

在自动缩放更新正在运行的计算实例数(扩展或缩减)时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "InstanceUpdateEvaluation",
  "category": "AutoscaleEvaluations",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "currentInstanceCount": 20,
    "newInstanceCount": 21,
    "shouldUpdateInstance": [true, false],
    "reason": ["Scale down action triggered", "Scale up to default instance count", ...]
  }
}

自动缩放缩放操作日志

以下架构显示在自动缩放评估日志中。

缩放操作

在自动缩放启动某个缩放操作(扩展或缩减)时记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "InstanceScaleAction",
  "category": "AutoscaleScaleActions",
  "resultType": ["Succeeded", "InProgress", "Failed"],
  "resultDescription": ["Create async operation job failed", ...]
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "currentInstanceCount": 20,
    "newInstanceCount": 21,
    "scaleDirection": ["Increase", "Decrease"],
    ["createdAsyncScaleActionJob": [true, false],]
    ["createdAsyncScaleActionJobId": "378ejr-7yye-892d-17dd-92ndijfe1738",]
  }
}

缩放操作跟踪

按实例缩放操作的不同时间间隔进行记录:

{
  "time": "2018-09-10 18:12:00.6132593",
  "resourceId": "/SUBSCRIPTIONS/BA13C41D-C957-4774-8A37-092D62ACFC85/RESOURCEGROUPS/AUTOSCALETRACKING12042017/PROVIDERS/MICROSOFT.INSIGHTS/AUTOSCALESETTINGS/DEFAULTSETTING",
  "operationName": "InstanceScaleAction",
  "category": "AutoscaleScaleActions",
  "correlationId": "e8f67045-f381-445d-bc2d-eeff81ec0d77",
  "property": {
    "targetResourceId": "/subscriptions/d45c994a-809b-4cb3-a952-e75f8c488d23/resourceGroups/RingAhoy/providers/Microsoft.Web/serverfarms/ringahoy",
    "scaleActionOperationId": "378ejr-7yye-892d-17dd-92ndijfe1738",
    "scaleActionOperationStatus": ["InProgress", "Timeout", "Canceled", ...],
    "scaleActionMessage": ["Scale action is inprogress", ...]
  }
}

活动日志

将以下事件记录到活动日志中,其中 CategoryValueAutoscale

  • 自动缩放纵向扩展已启动
  • 自动缩放纵向扩展已完成
  • 自动缩放纵向缩减已启动
  • 自动缩放纵向缩减已完成
  • 预测性自动缩放纵向扩展已启动
  • 预测性自动缩放纵向扩展已完成
  • 指标故障
  • 指标恢复
  • 预测性指标故障
  • 不稳定

每个日志事件名称的摘录,其中显示了 Properties 元素的相关部分,如下所示。

自动缩放操作

在自动缩放尝试横向缩减或横向扩展时记录:

{
   "eventCategory": "Autoscale",
    "eventName": "AutoscaleAction",
    ...
    "eventProperties": "{
        "Description": "The autoscale engine attempting to scale resource '/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourcegroups/ed-rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan' from 2 instances count to 1 instancescount.",
        "ResourceName": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourcegroups/ed-rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan",
        "OldInstancesCount": 2,
        "NewInstancesCount": 1,
        "ActiveAutoscaleProfile": {
            "Name": "Default scale condition",
            "Capacity": {
                "Minimum": "1",
                "Maximum": "5",
                "Default": "1"
            },
            "Rules": [
                {
                    "MetricTrigger": {
                        "Name": "CpuPercentage",
                        "Namespace": "microsoft.web/serverfarms",
                        "Resource": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/ed-rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan",
                        "ResourceLocation": "China North",
                        "TimeGrain": "PT1M",
                        "Statistic": "Average",
                        "TimeWindow": "PT2M",
                        "TimeAggregation": "Average",
                        "Operator": "GreaterThan",
                        "Threshold": 40.0,
                        "Source": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/ed-rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan",
                        "MetricType": "MDM",
                        "Dimensions": [],
                        "DividePerInstance": false
                    },
                    "ScaleAction": {
                        "Direction": "Increase",
                        "Type": "ChangeCount",
                        "Value": "1",
                        "Cooldown": "PT3M"
                    }
                },
                {
                    "MetricTrigger": {
                        "Name": "CpuPercentage",
                        "Namespace": "microsoft.web/serverfarms",
                        "Resource": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/ed-rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan",
                        "ResourceLocation": "China North",
                        "TimeGrain": "PT1M",
                        "Statistic": "Average",
                        "TimeWindow": "PT5M",
                        "TimeAggregation": "Average",
                        "Operator": "LessThanOrEqual",
                        "Threshold": 30.0,
                        "Source": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/ed-rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan",
                        "MetricType": "MDM",
                        "Dimensions": [],
                        "DividePerInstance": false
                    },
                    "ScaleAction": {
                        "Direction": "Decrease",
                        "Type": "ExactCount",
                        "Value": "1",
                        "Cooldown": "PT5M"
                    }
                }
            ]
                },
    "LastScaleActionTime": "Thu, 26 Jan 2023 12:57:14 GMT"
    }",
    ...
   "activityStatusValue": "Succeeded"
}

获取操作状态结果

在缩放事件之后记录:


"Properties":{
    "eventCategory": "Autoscale",
    "eventName": "GetOperationStatusResult",
    ...
    "eventProperties": "{"OldInstancesCount":3,"NewInstancesCount":2}",
    ...
    "activityStatusValue": "Succeeded"
}

指标故障

在自动缩放无法确定缩放规则中使用的指标值时记录:

"Properties":{
    "eventCategory": "Autoscale",
    "eventName": "MetricFailure",
    ...
    "eventProperties": "{
        "Notes":"To ensure service availability, Autoscale will scale out the resource to the default capacity if it is greater than the current capacity}",
    ...
    "activityStatusValue": "Failed"
}

指标恢复

当自动缩放在 MetricFailure 事件后能够再次确定缩放规则中使用的指标值时记录:

"Properties":{
    "eventCategory": "Autoscale",
    "eventName": "MetricRecovery",
    ...
    "eventProperties": "{}",
    ...
    "activityStatusValue": "Succeeded"
}

预测性指标故障

在自动缩放由于指标不可用而无法计算预测的缩放事件时记录:

"Properties": {
    "eventCategory": "Autoscale",
    "eventName": "PredictiveMetricFailure",
    ...
    "eventProperties": "{
        "Notes": "To ensure service availability, Autoscale will scale out the resource to the default capacity if it is greater than the current capacity"
    }",
   ...
    "activityStatusValue": "Failed"
}

发生回摆

在自动缩放检测到可能会发生回摆并以不同的方式缩放来避免此情况时记录:

"Properties":{
    "eventCategory": "Autoscale",
    "eventName": "FlappingOccurred",
    ...
    "eventProperties": 
        "{"Description":"Scale down will occur with updated instance count to avoid flapping. 
         Resource: '/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourcegroups/rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan'.
         Current instance count: '6', 
         Intended new instance count: '1'.
         Actual new instance count: '4'",
        "ResourceName":"/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourcegroups/rg-001/providers/Microsoft.Web/serverFarms/ScaleableAppServicePlan",
        "OldInstancesCount":6,
        "NewInstancesCount":4,
        "ActiveAutoscaleProfile":{"Name":"Auto created scale condition",
        "Capacity":{"Minimum":"1","Maximum":"30","Default":"1"},
        "Rules":[{"MetricTrigger":{"Name":"Requests","Namespace":"microsoft.web/sites","Resource":"/subscriptions/    d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/providers/Microsoft.Web/sites/ScaleableWebApp1",    "ResourceLocation":"China North","TimeGrain":"PT1M","Statistic":"Average","TimeWindow":"PT1M","TimeAggregation":"Maximum",    "Operator":"GreaterThanOrEqual","Threshold":3.0,"Source":"/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/    rg-001/providers/Microsoft.Web/sites/ScaleableWebApp1","MetricType":"MDM","Dimensions":[],"DividePerInstance":true},    "ScaleAction":{"Direction":"Increase","Type":"ChangeCount","Value":"10","Cooldown":"PT1M"}},{"MetricTrigger":{"Name":"Requests",    "Namespace":"microsoft.web/sites","Resource":"/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/    providers/Microsoft.Web/sites/ScaleableWebApp1","ResourceLocation":"China North","TimeGrain":"PT1M","Statistic":"Max",    "TimeWindow":"PT1M","TimeAggregation":"Maximum","Operator":"LessThan","Threshold":3.0,"Source":"/subscriptions/    d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/providers/Microsoft.Web/sites/ScaleableWebApp1","MetricType":"MDM",    "Dimensions":[],"DividePerInstance":true},"ScaleAction":{"Direction":"Decrease","Type":"ChangeCount","Value":"5",    "Cooldown":"PT1M"}}]}}",
    ...
    "activityStatusValue": "Succeeded"
}

不稳定

在自动缩放检测到可能发生回摆并延迟横向缩减来避免此情况时记录:

"Properties": {
    "eventCategory": "Autoscale",
    "eventName": "Flapping",
    "Description": "{"Cannot scale down due to flapping observed. Resource: '/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourcegroups/rg-001/providers/Microsoft.Compute/virtualMachineScaleSets/mac2'. Current instance count: '2', Intended new instance count '1'",
    "ResourceName": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourcegroups/rg-001/providers/Microsoft.Compute/virtualMachineScaleSets/mac2",
    "OldInstancesCount": "2",
    "NewInstancesCount": "2",
    "ActiveAutoscaleProfile": "ActiveAutoscaleProfile": {
        "Name": "Auto created default scale condition",
        "Capacity": {
            "Minimum": "1",
            "Maximum": "2",
            "Default": "1"
        },
        "Rules": [
            {
                "MetricTrigger": {
                    "Name": "StorageSuccesses",
                    "Namespace": "monitoringbackgroundjob",
                    "Resource": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/providers/microsoft.monitor/accounts/MACAzureInsightsPROD",
                    "ResourceLocation": "ChinaNorth2",
                    "TimeGrain": "PT1M",
                    "Statistic": "Average",
                    "TimeWindow": "PT10M",
                    "TimeAggregation": "Average",
                    "Operator": "LessThan",
                    "Threshold": 600.0,
                    "Source": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/providers/microsoft.monitor/accounts/MACAzureInsightsPROD",
                    "MetricType": "MDM",
                    "Dimensions": [],
                    "DividePerInstance": false
                },
                "ScaleAction": {
                    "Direction": "Decrease",
                    "Type": "ChangeCount",
                    "Value": "1",
                    "Cooldown": "PT5M"
                }
            },
            {
                "MetricTrigger": {
                    "Name": "TimeToStartupInMs",
                    "Namespace": "armrpclient",
                    "Resource": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-123/providers/microsoft.monitor/accounts/MACMetricsRP",
                    "ResourceLocation": "chinanorth2",
                    "TimeGrain": "PT1M",
                    "Statistic": "Percentile99th",
                    "TimeWindow": "PT10M",
                    "TimeAggregation": "Average",
                    "Operator": "GreaterThan",
                    "Threshold": 70.0,
                    "Source": "/subscriptions/d1234567-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-123/providers/microsoft.monitor/accounts/MACMetricsRP",
                    "MetricType": "MDM",
                    "Dimensions": [],
                    "DividePerInstance": false
                },
                "ScaleAction": {
                    "Direction": "Increase",
                    "Type": "ChangeCount",
                    "Value": "1",
                    "Cooldown": "PT5M"
                }
            }
        ]
    }"
}...

后续步骤