C# Azure Fluent API-AppServicePlanOperations.ListMetricswithHttpMessageAsync返回InternalServerError

C# Azure Fluent API-AppServicePlanOperations.ListMetricswithHttpMessageAsync返回InternalServerError,c#,azure,azure-sdk-.net,azure-app-service-plans,azure-sdk,C#,Azure,Azure Sdk .net,Azure App Service Plans,Azure Sdk,可以找到此方法的文档 这是我的密码: var appServiceManager = AppServiceManager.Authenticate(credentials, subscriptionId); var filter = "(name.value eq 'CpuPercentage') and startTime eq '2017-10-06T08:00:00Z' and endTime eq '2017-10-06T09:00:00Z' and ti

可以找到此方法的文档

这是我的密码:

        var appServiceManager = AppServiceManager.Authenticate(credentials, subscriptionId);
        var filter = "(name.value eq 'CpuPercentage') and startTime eq '2017-10-06T08:00:00Z' and endTime eq '2017-10-06T09:00:00Z' and timeGrain eq duration'PT1H'";
        var metrics = appServiceManager.AppServicePlans.Inner.ListMetricsWithHttpMessagesAsync("myResourceGroupName", "myAppServicePlanName", false, filter).Result;    
这是我得到的唯一一个详细的例外:

发生了一个或多个错误。(操作返回无效的状态代码“InternalServerError”)-->Microsoft.Rest.Azure.CloudException:操作返回无效的状态代码“InternalServerError”

文档中说,
filter
是可选的,而不是(如果传入
null
,我会收到一个坏请求)。我现在提供一个,现在它抛出一个内部服务器错误


我在
azure sdk for net
repo上打开了一个问题,但我希望其他人能看到我的
过滤器
字符串中是否有任何错误。

我也可以在使用您提到的代码时重现这个问题。我发现另一个可以用于列出资源的指标,它是beta版。我在我这边做了一个演示,它在我这边正常工作

using Microsoft.Azure.Management.Fluent.ServiceBus;
using Microsoft.Azure.Management.Fluent.ServiceBus.Models;
using Microsoft.Rest.Azure.Authentication;
using Microsoft.Rest.Azure.OData;

namespace MonitorDemo
{
    class Program
    {
        static void Main(string[] args)
        {

            var azureTenantId = "tenant Id";
            var azureSecretKey = "secret key";
            var azureAppId = "azure AD application Id";
            var subscriptionId = "subscription Id";
            var resourceGroup = "resource group name";
            var servicePlanName = "service plan name";
            var serviceCreds = ApplicationTokenProvider.LoginSilentAsync(azureTenantId, azureAppId, azureSecretKey).Result;
            MonitorClient monitorClient = new MonitorClient(serviceCreds) { SubscriptionId = subscriptionId };
            var resourceUri = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/serverfarms/{servicePlanName}"; // resource id
            var metricNames = "name.value eq 'CpuPercentage'"; // could be concatenated with " or name.value eq '<another name>'" ... inside parentheses for more than one name.

            // The $filter can include time grain, which is optional when metricNames is present. The is forms a conjunction with the list of metric names described above.
            string timeGrain = " and timeGrain eq duration'PT5M'";

            // The $filter can also include a time range for the query; also a conjunction with the list of metrics and/or the time grain. Defaulting to 3 hours before the time of execution for these datetimes
            string startDate = " and startTime eq 2017-10-06T08:00:00Z";
            string endDate = " and endTime eq 2017-10-06T09:00:00Z";

            var odataFilterMetrics = new ODataQuery<MetricInner>(
                $"{metricNames}{timeGrain}{startDate}{endDate}");

            var metrics = monitorClient.Metrics.ListWithHttpMessagesAsync(resourceUri, odataFilterMetrics).Result;
        }
    }
}
使用Microsoft.Azure.Management.Fluent.ServiceBus;
使用Microsoft.Azure.Management.Fluent.ServiceBus.Models;
使用Microsoft.Rest.Azure.Authentication;
使用Microsoft.Rest.Azure.OData;
名称空间监视器演示
{
班级计划
{
静态void Main(字符串[]参数)
{
var azureTenantId=“租户Id”;
var azureSecretKey=“秘钥”;
var azureAppId=“azure AD应用程序Id”;
var subscriptionId=“订阅Id”;
var resourceGroup=“资源组名称”;
var servicePlanName=“服务计划名称”;
var serviceCreds=ApplicationTokenProvider.LoginSilentAsync(azureTenantId、azureAppId、azureSecretKey);
MonitorClient MonitorClient=新的MonitorClient(serviceCreds){SubscriptionId=SubscriptionId};
var resourceUri=$“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/serverfarms/{servicePlanName}”;//资源id
var metricNames=“name.value eq'CpuPercentage'”;//可以与“or name.value eq”连接

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Azure.Management.Monitor.Fluent" version="1.3.0-beta" targetFramework="net47" />
  <package id="Microsoft.Azure.Management.ResourceManager.Fluent" version="1.3.0" targetFramework="net47" />
  <package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net47" />
  <package id="Microsoft.Rest.ClientRuntime" version="2.3.9" targetFramework="net47" />
  <package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.10" targetFramework="net47" />
  <package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.3.1" targetFramework="net47" />
  <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net47" />
</packages>


感谢Tom抽出时间回复。我将仔细研究您的发现,如果它满足我的需要,我将接受您的回答可能是我遗漏了一些愚蠢的东西,但我无法解决您的问题MonitorClient@RahulPatel我也有同样的问题,你解决了吗?