gpt4 book ai didi

c# - 尝试读取性能计数器时出现 Azure 自动缩放异常

转载 作者:行者123 更新时间:2023-12-03 03:19:00 31 4
gpt4 key购买 nike

我正在研究 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.

自动缩放应用程序 block 的配置文件(这两个文件都是控制台应用程序的一部分):

规则.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>

服务.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);
}

最佳答案

在 services.xml 中尝试更改此内容:

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

对此:

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

rules.xml 中,scale 元素的 target 属性查找匹配的 alias services.xmlrole 元素上的属性 - 它正在寻找 WorkerRoleExample 但找不到它。

如果您在 Rules.xml 中更改了以下内容而不是上述内容,它也会起作用:

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

对此:

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

关于c# - 尝试读取性能计数器时出现 Azure 自动缩放异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16122016/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com