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?
CodePudding user response:
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 :