1

La documentation de cette méthode peut être trouvé hereAzure API Courant - AppServicePlanOperations.ListMetricsWithHttpMessagesAsync retour InternalServerError

Voici mon code:

 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;  

Ceci est la seule exception détaillée que je reçois:

Une ou plusieurs erreurs se sont produites. (Opération renvoyé un code d'état non valide 'InternalServerError') ---> Microsoft.Rest.Azure.CloudException: Opération renvoyé un code d'état non valide 'InternalServerError'

La documentation indique que filter est facultative, ce qui n'est pas (Je reçois un BadRequest si je passe en null). Je fournis maintenant un et maintenant il jette une erreur de serveur interne.

J'ai ouvert un problème sur le repo azure-sdk-for-net mais j'espère que quelqu'un d'autre peut voir si je fais des erreurs dans ma chaîne filter.

Répondre

1

Je peux également reproduire ce problème de mon côté lorsque j'utilise le code que vous avez mentionné. Je trouve un autre Microsoft.Azure.Management.Monitor.Fluent SDK pourrait être utilisé pour la liste des mesures de la ressource, c'est une version beta. Je fais une démo de mon côté, ça fonctionne correctement de mon côté.

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; 
     } 
    } 
} 

enter image description here

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> 
+0

Merci Tom pour prendre le temps de répondre. Je vais jouer avec vos découvertes et si cela répond à mes besoins, j'accepterai votre réponse – AMoghrabi