【问题标题】:Unable to create custom performance counters in Azure Web Role无法在 Azure Web 角色中创建自定义性能计数器
【发布时间】:2012-02-06 17:08:11
【问题描述】:

按照in this MSDN article 的说明尝试创建自定义性能计数器时,我仍然遇到安全异常。

我使用的代码与那篇文章中的相同,只是我创建了不同的计数器。

我知道我可以尝试在启动任务中创建它,但现在我想在角色内部进行。它应该可以工作:/

例外:

[SecurityException: Requested registry access is not allowed.]
   Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +12746267
   System.Diagnostics.PerformanceCounterLib.CreateRegistryEntry(String categoryName, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection creationData, Boolean& iniRegistered) +170
   System.Diagnostics.PerformanceCounterLib.RegisterCategory(String categoryName, PerformanceCounterCategoryType categoryType, String categoryHelp, CounterCreationDataCollection creationData) +49
   System.Diagnostics.PerformanceCounterCategory.Create(String categoryName, String categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) +558

我的 ServiceDefinition.csdef 的开头:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="Jonathan.Cloud" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebDriver" vmsize="Small" enableNativeCodeExecution="true">
    <Runtime executionContext="elevated" />

当我 RDP 进入角色时,我可以看到应用程序池仍在以 NetworkService 身份运行,当我将角色更改为“提升”时,我期望它在不同的主体下运行 - 手动设置自定义具有权限的主体解决了这个问题,但是一旦角色重新配置自身或我部署升级,它将被覆盖 - 无论如何,这不是真正的解决方案,而是一个黑客:/ [沮丧]

【问题讨论】:

  • 您是否尝试过使用 Windows Azure Powershell Cmdlet 而不是自己封装管理 API?这是 David Aiken 关于如何使用 PowerShell 远程配置诊断信息的文章。 davidaiken.com/2011/10/18/…

标签: azure performancecounter azure-web-roles


【解决方案1】:

在完整 IIS 的 Web 角色的情况下,您在 Runtime 元素中指定的特殊权限将应用于 RoleEntoryPoint。我认为有必要通过内部RoleEntryPoint(通常是WebRole.cs)的OnStart方法注册一个自定义的性能计数器。

【讨论】:

  • 你是对的,这行得通! :) 我将初始化计数器的代码移至 RoleEntryPoint 的 OnStart(),删除了现有部署以确保我开始干净,并发布它 - 工作并注册计数器。
  • 记得在你的 .csdef 文件中包含 配置(如你的例子)
猜你喜欢
  • 2011-04-20
  • 1970-01-01
  • 1970-01-01
  • 2010-09-08
  • 2016-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-29
相关资源
最近更新 更多