简体   繁体   English

如何查询Azure App Service中的性能指标?

[英]How do I query an indicator of performance capability in an Azure App Service?

I have some slow-running services doing some fairly heavy processing. 我有一些运行缓慢的服务,需要进行大量的处理。 These processes run in several different places, including on-prem servers and in Azure, and all write their results to a common database. 这些过程在几个不同的位置(包括本地服务器和Azure)中运行,并且都将其结果写入通用数据库。 I'd like to have a note stored in the database tied to the processing results indicating something useful about the performance capabilities of where the processing was ran. 我想在数据库中存储一条注释,该注释与处理结果相关联,以指示关于运行处理的位置的性能的一些有用信息。

My on-prem servers run the following code successfully, which allows me to log the CPU name (ex: my workstation logs "AMD Ryzen 9 3900X 12-Core Processor" with the following code, which is good enough for our needs): 我的本地服务器成功运行以下代码,这使我可以记录CPU名称(例如:我的工作站使用以下代码记录“ AMD Ryzen 9 3900X 12核处理器”,足以满足我们的需求):

    public string GetCpu()
    {
        var searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_Processor");

        string results = "Unknown CPU";
        foreach (var item in searcher.Get())
        {
            results = item["Name"].ToString();
        }

        return results;
    }

As you probably suspect, this code fails to run in Azure with a permissions error. 您可能会怀疑,此代码无法在Azure中运行,并出现权限错误。 What is something else that I can run in Azure to get useful information, even if not identical? 我可以在Azure中运行什么以获取有用的信息,即使它们不完全相同? I don't necessary need a CPU name, just a useful indicator of processing capabilities. 我不需要CPU名称,只是处理能力的有用指示。 If something like "P1V1 App Hosting Plan" was logged, that would be quite good enough for our needs. 如果记录了诸如“ P1V1 App Hosting Plan”之类的内容,则足以满足我们的需求。 I'm not sure if there's something more indicative of processing power than that but I'm open to other suggestions as well. 我不确定是否还有其他指标可以说明处理能力,但是我也愿意接受其他建议。 I suspect getting a CPU model might even be deceptive in Azure given the multi-tenant setups going on. 我怀疑由于正在进行多租户设置,因此在Azure中获取CPU模型甚至可能具有欺骗性。

There is a easy way to get it, the Azure has a environment called WEBSITE_SKU store the host plan level. 有一种简单的方法可以得到它,Azure有一个称为WEBSITE_SKU的环境来存储主机计划级别。 You could go to your Kudu page to check the env. 您可以转到Kudu页面检查环境。

You could use Environment.GetEnvironmentVariable("WEBSITE_SKU") to get it. 您可以使用Environment.GetEnvironmentVariable("WEBSITE_SKU")来获取它。

在此处输入图片说明

在此处输入图片说明


The above example will output "PremiumV2" for all levels of the Premium V2 configurations. 上面的示例将为Premium V2配置的所有级别输出“ PremiumV2”。 That means it has the same output for P1V2, P2V2, and P3V2 even though each one has twice as many ACUs as the prior. 这意味着即使P1V2,P2V2和P3V2的ACU数量是前一个的两倍,它的输出也相同。 Fortunately, there are a number of other environment variables with useful information in them that can get us more info. 幸运的是, 还有许多其他环境变量中包含有用的信息 ,它们可以为我们提供更多信息。 With this extra information, an example of a function to gather information in a way that works both on-prem and in an Azure App Service might look like this: 有了这些额外的信息,可以以一种既可以在本地部署又可以在Azure App Service中运行的方式收集信息的函数示例如下所示:

public string GetComputationalResources()
{
    string results = null;

    try
    {
        var azureSku = Environment.GetEnvironmentVariable("WEBSITE_SKU");
        if (!string.IsNullOrWhiteSpace(azureSku))
        {
            // We're in Azure. Get more information!

            var cpuCount = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")?.Trim();
            var cpuId = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")?.Trim();
            var computeMode = Environment.GetEnvironmentVariable("WEBSITE_COMPUTE_MODE")?.Trim();
            var websiteMode = Environment.GetEnvironmentVariable("WEBSITE_SITE_MODE")?.Trim();
            results = $"{azureSku} {computeMode} {websiteMode} | {cpuCount}x {cpuId}";
        }

    }
    catch
    {
        results = null;
    }

    if (results == null)
    {
        try
        {
            using (var searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_Processor"))
            {
                foreach (var item in searcher.Get())
                {
                    results = item["Name"].ToString().Trim();
                }
            }
        }
        catch
        {
            results = "Unknown CPU";
        }
    }

    return results;
}

Example outputs (it's possible to get AMD and not just Intel in Azure, from what I understand): 示例输出(据我了解,有可能在Azure中获得AMD而不只是Intel):

  • On-Prem: AMD Ryzen 9 3900X 12-Core Processor 本地: AMD Ryzen 9 3900X 12-Core Processor
  • P1V2: PremiumV2 Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel P1V2: PremiumV2 Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel PremiumV2 Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • P2V2: PremiumV2 Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel P2V2: PremiumV2 Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel PremiumV2 Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • P3V2: PremiumV2 Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel P3V2: PremiumV2 Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel PremiumV2 Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • P1: Premium Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel P1: Premium Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel Premium Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • P2: Premium Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel P2: Premium Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel Premium Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • P3: Premium Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel P3: Premium Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel Premium Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • S1: Standard Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel S1: Standard Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel Standard Dedicated | 1x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • S2: Standard Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel S2: Standard Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel Standard Dedicated | 2x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
  • S3: Standard Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel S3: Standard Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel Standard Dedicated | 4x Intel64 Family 6 Model 79 Stepping 1, GenuineIntel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从应用程序以管理员身份访问Azure移动服务? - How do I access an Azure Mobile Service as an admin from an app? 如何在Azure App Service中插入具有1:n关系的实体 - How do I insert entities with a 1:n relationship in Azure App Service 如何从我的 SQL Azure 应用服务 Web 应用写入日志文件? - How do I write a log file from my SQL Azure App Service Web App? 如何配置 NLog 以写入 Azure 应用服务的日志 stream? - How do I configure NLog to write to Azure App Service's log stream? 如何使用 websockets 在我的 Azure 应用服务 Web 应用和本地控制台应用之间建立连接? - How do I establish a connection between my Azure App Service Web App and local console app using websockets? 如何从托管在 Azure 应用服务中的 .Net Framework Asp.Net 应用程序访问 Azure KeyValut? - How do I access an Azure KeyValut from an .Net Framework Asp.Net application hosted in an Azure App Service? 如何将XML绑定到WPF,并具有CRUD功能? - How do I bind XML to WPF, and have CRUD capability? 您如何看待Azure应用服务的特定“数据输入”负载? - How do you see the specific “data in” load for an Azure App Service? 如何在VPC上部署Azure应用服务 - How can I deploy an Azure App Service on VPC 如何在Web App Service中使用“Azure文件存储”? - How can I use “Azure File Storage” with Web App Service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM