Udostępnij za pośrednictwem


LoadTestRunClient.GetMetricsAsync Method

Definition

List the metric values for a load test run.

public virtual Azure.AsyncPageable<BinaryData> GetMetricsAsync (string testRunId, string metricName, string metricNamespace, string timespan, Azure.Core.RequestContent content = default, string aggregation = default, string interval = default, Azure.RequestContext context = default);
abstract member GetMetricsAsync : string * string * string * string * Azure.Core.RequestContent * string * string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
override this.GetMetricsAsync : string * string * string * string * Azure.Core.RequestContent * string * string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
Public Overridable Function GetMetricsAsync (testRunId As String, metricName As String, metricNamespace As String, timespan As String, Optional content As RequestContent = Nothing, Optional aggregation As String = Nothing, Optional interval As String = Nothing, Optional context As RequestContext = Nothing) As AsyncPageable(Of BinaryData)

Parameters

testRunId
String

Unique name for the load test run, must contain only lower-case alphabetic, numeric, underscore or hyphen characters.

metricName
String

Metric name.

metricNamespace
String

Metric namespace to query metric definitions for.

timespan
String

The timespan of the query. It is a string with the following format 'startDateTime_ISO/endDateTime_ISO'.

content
RequestContent

The content to send as the body of the request. Details of the request body schema are in the Remarks section below.

aggregation
String

The aggregation.

interval
String

The interval (i.e. timegrain) of the query. Allowed values: "PT5S" | "PT10S" | "PT1M" | "PT5M" | "PT1H".

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The AsyncPageable<T> from the service containing a list of BinaryData objects. Details of the body schema for each item in the collection are in the Remarks section below.

Exceptions

testRunId, metricName, metricNamespace or timespan is null.

testRunId is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call GetMetricsAsync with required parameters and parse the result.

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new LoadTestRunClient(endpoint, credential);

var data = new {};

await foreach (var data in client.GetMetricsAsync("<testRunId>", "<metricname>", "<metricNamespace>", "<timespan>", RequestContent.Create(data)))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.ToString());
}

This sample shows how to call GetMetricsAsync with all parameters and request content, and how to parse the result.

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new LoadTestRunClient(endpoint, credential);

var data = new {
    filters = new[] {
        new {
            name = "<name>",
            values = new[] {
                "<String>"
            },
        }
    },
};

await foreach (var data in client.GetMetricsAsync("<testRunId>", "<metricname>", "<metricNamespace>", "<timespan>", RequestContent.Create(data), "<aggregation>", "<interval>"))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("data")[0].GetProperty("timestamp").ToString());
    Console.WriteLine(result.GetProperty("data")[0].GetProperty("value").ToString());
    Console.WriteLine(result.GetProperty("dimensionValues")[0].GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("dimensionValues")[0].GetProperty("value").ToString());
}

Remarks

Below is the JSON schema for the request payload and one item in the pageable response.

Request Body:

Schema for MetricRequestPayload:

{
  filters: [
    {
      name: string, # Optional. The dimension name
      values: [string], # Optional. The dimension values. Maximum values can be 20.
    }
  ], # Optional. Get metrics for specific dimension values. Example: Metric contains dimension like SamplerName, Error. To retrieve all the time series data where SamplerName is equals to HTTPRequest1 or HTTPRequest2, the DimensionFilter value will be {"SamplerName", ["HTTPRequest1", "HTTPRequest2"}
}

Response Body:

Schema for MetricsValue:

{
  data: [
    {
      timestamp: string, # Optional. The timestamp for the metric value in ISO 8601 format.
      value: number, # Optional. The metric value.
    }
  ], # Optional. An array of data points representing the metric values.
  dimensionValues: [
    {
      name: string, # Optional. The name of the dimension.
      value: string, # Optional. The value of the dimension.
    }
  ], # Optional. The dimension values 
}

Applies to