Azure自动缩放度量标准值

时间:2014-09-09 11:59:08

标签: azure autoscaling

我需要为我的虚拟机定义缩放规则我已阅读以下内容

  

MetricName和MetricNamespace不是我刚刚编写的值。   这些必须准确。你可以从中获取这些值   MetricsClient API和此链接中有一些示例代码可供显示   如何获得价值。

     

http://rickrainey.com/2013/12/15/auto-scaling-cloud-services-on-cpu-percentage-with-the-windows-azure-monitoring-services-management-library/

但它仍然不清楚我是否得到可能值的MetricName列表,因为我没有找到任何示例代码

1 个答案:

答案 0 :(得分:2)

以下是我用于获取云服务的可用MetricNames的代码。它是单元测试项目的一部分,因此是[TestMethod]属性。

    [TestMethod]
    public async Task GetMetricDefinitions()
    {
        // Build the resource ID string.
        string resourceId = ResourceIdBuilder.BuildCloudServiceResourceId(
            cloudServiceName, deploymentName, roleName );

        Console.WriteLine("Resource Id: {0}", resourceId);

        //Get the metric definitions.
        var retrieveMetricsTask =
            metricsClient.MetricDefinitions.ListAsync(resourceId, null, null, CancellationToken.None);
        var metricListResponse = await retrieveMetricsTask;

        MetricDefinitionCollection metricDefinitions = metricListResponse.MetricDefinitionCollection;

        // Make sure something was returned.
        Assert.IsTrue(metricDefinitions.Value.Count > 0);

        // Display the metric definitions.
        int count = 0;
        foreach (MetricDefinition metricDefinition in metricDefinitions.Value)
        {
            Console.WriteLine("MetricDefinitio: " + count++);
            Console.WriteLine("Display Name: " + metricDefinition.DisplayName);
            Console.WriteLine("Metric Name: " + metricDefinition.Name);
            Console.WriteLine("Metric Namespace: " + metricDefinition.Namespace);
            Console.WriteLine("Is Altertable: " + metricDefinition.IsAlertable);
            Console.WriteLine("Min. Altertable Time Window: " + metricDefinition.MinimumAlertableTimeWindow);
            Console.WriteLine();
        }
    }

以下是我的云服务测试的输出:

enter image description here