【问题标题】:How to get metrics of Azure apim using an api如何使用 api 获取 Azure apim 的指标
【发布时间】:2022-01-12 02:13:06
【问题描述】:

我必须在 C# 上编写一个程序来获取有关 Azure APIM 的一些 api 的信息,我可以通过 api 来实现吗?

【问题讨论】:

    标签: c# azure api azure-api-management


    【解决方案1】:

    您可以尝试的一种解决方法是从存储 API 管理指标的 Azure Monitor 获取查看的诊断数据

    用于列出资源的指标

    IEnumerable<Metric> metrics = await readOnlyClient.Metrics.ListAsync(resourceUri: resourceUri, cancellationToken: CancellationToken.None);
    

    或使用过滤器

    // The comma-separated list of metric names must be present if a filter is used
    var metricNames = "name.value eq 'CpuPercentage'"; // could be concatenated with " or name.value eq '<another name>'" ...
    
    // Time grain is optional when metricNames is present
    string timeGrain = " and timeGrain eq duration'PT5M'";
    
    // Defaulting to 3 hours before the time of execution for these datetimes
    string startDate = string.Format(" and startTime eq {0}", DateTime.Now.AddHours(-3).ToString("o"));
    string endDate = string.Format(" and endTime eq {0}", DateTime.Now.ToString("o"));
    
    var odataFilterMetrics = new ODataQuery<Metric>(
        string.Format(
            "{0}{1}{2}{3}",
            metricNames,
            timeGrain,
            startDate,
            endDate));
    
    Write("Call with filter parameter (i.e. $filter = {0})", odataFilterMetrics);
    metrics = await readOnlyClient.Metrics.ListAsync(resourceUr
    

    参考:

    【讨论】:

      猜你喜欢
      • 2020-03-08
      • 2019-03-03
      • 2017-12-17
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      • 2021-11-03
      相关资源
      最近更新 更多