【问题标题】:Azure powershell command to get web app cpu & memory percentageAzure powershell 命令获取 Web 应用程序 cpu 和内存百分比
【发布时间】:2018-12-19 04:31:12
【问题描述】:

我的要求是获取托管在 azure 中的 Web 应用程序的平均 CPU 和内存百分比消耗。我想使用 powershell 命令获取数据 所以我尝试了以下命令并收到以下错误,请帮助。

命令 1:

Get-AzureRmAppServicePlanMetrics -ResourceGroupName 'RGname' -Name 'appserviceplan name' -StartTime ((get-date).AddHours(-1)) -Granularity PT1M -Metrics ["CPU Percentage"]  

错误:

Get-AzureRmAppServicePlanMetrics : $filter. Details: Microsoft.Data.OData.ODataException: Syntax error at position 82 in 'name/value eq 
'CPU Percentage'and startTime eq '2018-12-19T13:52:33Zand' timeGrain eq 'duration''PT1M''''.
   at Microsoft.Data.OData.Query.ExpressionLexer.ValidateToken(ExpressionTokenKind t)
   at Microsoft.Data.OData.Query.UriQueryExpressionParser.ParseFilter(String filter)
   at Microsoft.Data.OData.Query.ODataUriParser.ParseFilterImplementation(String filter, IEdmType elementType, IEdmEntitySet entitySet)
   at Microsoft.Web.Hosting.Administration.Csm.Common.ODataFilterParser.ParseMetricsFilterQuery(IEnumerable`1 queryNameValuePairs, String& 
   names, String& startTime, String& endTime, String& timeGrain). 
   name/value eq 'CPU Percentage'and startTime eq '2018-12-19T13:52:33Zand' timeGrain eq 'duration''PT1M''' is invalid.
   At line:1 char:1
   + Get-AzureRmAppServicePlanMetrics -ResourceGroupName 'resource group name ...
   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Get-AzureRmAppServicePlanMetrics], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.GetAzureAppServicePlanMetricsCmdlet

命令 2:

Get-AzureRmAppServicePlanMetrics -ResourceGroupName 'RGname' -Name 'web app name' -StartTime ((get-date).AddHours(-1)) -Granularity PT1M -Metrics ["CPU Percentage"]

错误:

Get-AzureRmAppServicePlanMetrics : Can not perform requested operation on nested resource. Parent resource 'web app name' not found.
At line:1 char:1
+ Get-AzureRmAppServicePlanMetrics -ResourceGroupName 'resource group name...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Get-AzureRmAppServicePlanMetrics], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.GetAzureAppServicePlanMetricsCmdle

请在下面找到我的 Powershell 和 AzureRM 版本详细信息

PS C:\Users\xxxx> Get-Module -Name AzureRM -ListAvailable
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version    Name                                ExportedCommands                                                     

---------- -------    ----                                ----------------                                                                 

Script     6.13.1     AzureRM                                                                                                          

Script     5.4.1      AzureRM                                                                                                              

$PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14409  1005    

【问题讨论】:

    标签: azure-app-service-plans


    【解决方案1】:

    我刚刚遇到了同样的问题,Get-AzureRmAppServicePlanMetrics 和 Get-AzureRmWebAppMetrics 命令目前似乎不起作用,无论选择什么选项。

    相反,我已经能够使用以下命令获得相同的数据:

    Get-AzureRmMetric
    

    例如,要获取过去 30 分钟的 CPU 使用情况和内存使用情况,对于资源组“rgname”中的“webappname”,订阅 ID 为“d6ae8085-3bbc-410e-8c95-7be4aa2adbeb”,您可以使用以下:

    Get-AzureRmMetric -ResourceId "/subscriptions/d6ae8085-3bbc-410e-8c95-7be4aa2adbeb/resourceGroups/rgname/providers/Microsoft.Web/sites/webappname" -TimeGrain 00:01:00 -StartTime ((get-date).AddMinutes(-30)) -EndTime (get-date) -MetricNames "AverageMemoryWorkingSet","CpuTime"
    

    这将返回一个包含所有指标的数组,数据点位于“数据”属性中。

    此命令似乎只采用 -ResourceId 参数,因此我建议使用 Get-AzureRmWebApp 结果中的“Id”属性,因为它的格式正确。

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      • 2012-05-22
      相关资源
      最近更新 更多