Исключение автомасштабирования Azure при попытке чтения счетчика производительности

Я работаю над примером от Microsoft, который показывает, как использовать автоматическое масштабирование ( http://www.windowsazure.com/en-us/develop/net/how-to-guides/autoscaling/). Установленная в облаке рабочая роль генерирует счетчик производительности, и локально консольное приложение считывает этот счетчик и применяет автомасштабирование.

Все выглядит хорошо, счетчик производительности доступен из WADPerformanceCountersTable, и консольное приложение правильно обращается к хранилищу, но не может найти рабочую роль внутри WADPerformanceCountersTable. Это сгенерированное исключение:

Autoscaling General Error: 2001 : 
Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling.DataPointsCollection.DataPointsCollectionException:
Could not retrieve performance counter with name '\Processor(_Total)\% Processor Time'
for target 'WorkerRoleExample' from the WADPerformanceCountersTable table. ---> 
System.ArgumentOutOfRangeException: Could not retrieve the role with alias 'WorkerRoleExample' from the service information store.
Please review the service information store to fix this.

Конфигурационные файлы Autoscaling Application Block (оба файла являются частью консольного приложения):

rules.xml:

<?xml version="1.0" encoding="utf-8" ?>
<rules xmlns="http://schemas.microsoft.com/practices/2011/entlib/autoscaling/rules">
  <constraintRules>
    <rule name="default" enabled="true" rank="1" description="The default constraint rule">
      <actions>
        <range min="1" max="2" target="WorkerRoleExample"/>
      </actions>
    </rule>
  </constraintRules>
  <reactiveRules>
    <rule name="ScaleUpOnHighUtilization" rank="10" description="Scale up the web role" enabled="true" >
      <when>
        <any>
          <greaterOrEqual operand="WebRoleA_CPU_Avg_5m" than="60"/>
        </any>
      </when>
      <actions>
        <scale target="WorkerRoleExample" by="1"/>
      </actions>
    </rule>
    <rule name="ScaleDownOnLowUtilization" rank="10" description="Scale up the web role" enabled="true" >
      <when>
        <all>
          <less operand="WebRoleA_CPU_Avg_5m" than="60"/>
        </all>
      </when>
      <actions>
        <scale target="WorkerRoleExample" by="-1"/>
      </actions>
    </rule>
  </reactiveRules>
  <operands>
    <performanceCounter alias="WebRoleA_CPU_Avg_5m"
                        performanceCounterName="\Processor(_Total)\% Processor Time"
                        source ="WorkerRoleExample"
                        timespan="00:05:00" aggregate="Average"/>
  </operands>
</rules>

services.xml:

<?xml version="1.0" encoding="utf-8" ?>
<serviceModel xmlns="http://schemas.microsoft.com/practices/2011/entlib/autoscaling/serviceModel">
  <subscriptions>
    <subscription name="TestingWorkerRole"
                  certificateThumbprint="**************"
                  subscriptionId="**************"
                  certificateStoreLocation="CurrentUser"
                  certificateStoreName="My">
      <services>
        <service dnsPrefix="**************" slot="Staging">
          <roles>
            <role alias="AutoscalingApplicationRole"
                  roleName="WorkerRoleExample"
                  wadStorageAccountName="targetstorage"/>
          </roles>
        </service>
      </services>
      <storageAccounts>
        <storageAccount alias="targetstorage"
          connectionString="DefaultEndpointsProtocol=https;AccountName=*****;AccountKey=*******">
        </storageAccount>
      </storageAccounts>
    </subscription>
  </subscriptions>
</serviceModel>

Рабочая роль, работающая в облаке, генерирует счетчик производительности:

public override bool OnStart()
{
    // Set the maximum number of concurrent connections 
    ServicePointManager.DefaultConnectionLimit = 12;

    CreatePerformanceCounters();

    return base.OnStart();
}

private static void CreatePerformanceCounters()
{
    DiagnosticMonitorConfiguration diagConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();

    var procTimeConfig = new PerformanceCounterConfiguration();
    procTimeConfig.CounterSpecifier = @"\Processor(_Total)\% Processor Time";
    procTimeConfig.SampleRate = TimeSpan.FromSeconds(10);

    diagConfig.PerformanceCounters.DataSources.Add(procTimeConfig);
    diagConfig.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

    DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagConfig);
}

1 ответ

Решение

В services.xml попробуйте изменить это:

<role alias="AutoscalingApplicationRole"
              roleName="WorkerRoleExample"
              wadStorageAccountName="targetstorage"/>

К этому:

<role alias="WorkerRoleExample"
              roleName="WorkerRoleExample"
              wadStorageAccountName="targetstorage"/>

В rules.xml target атрибут scale элемент ищет соответствие aliasattribute на role элемент в services.xml - это искал WorkerRoleExample и не смог его найти.

Это также будет работать, если вместо вышеуказанного в rules.xml вы изменили:

<scale target="WorkerRoleExample" by="1"/>

К этому:

<scale target="AutoscalingApplicationRole" by="1"/>
Другие вопросы по тегам