简体   繁体   中英

How to get metrics of Azure apim using an api

I have to make a program on C# that get information about a few apis of Azure APIM, can I achieve this through an api?

One of the workarounds you can try is to get the viewed diagnostic data from Azure Monitor which stores the metrics of API Management

For listing metrics for a resource

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

or with a filter

// 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

REFERENCES:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM