Compartilhar via


LoadTestRunClient.CreateOrUpdateServerMetricsConfigAsync Método

Definição

Configure as métricas do servidor para uma execução de teste.

public virtual System.Threading.Tasks.Task<Azure.Response> CreateOrUpdateServerMetricsConfigAsync (string testRunId, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateOrUpdateServerMetricsConfigAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateOrUpdateServerMetricsConfigAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateOrUpdateServerMetricsConfigAsync (testRunId As String, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parâmetros

testRunId
String

O nome exclusivo para a execução do teste de carga deve conter apenas caracteres alfabéticos, numéricos, sublinhados ou hifens de minúsculas.

content
RequestContent

O conteúdo a ser enviado como o corpo da solicitação. Os detalhes do esquema do corpo da solicitação estão na seção Comentários abaixo.

context
RequestContext

O contexto de solicitação, que pode substituir os comportamentos padrão do pipeline do cliente por chamada.

Retornos

A resposta retornada do serviço. Os detalhes do esquema do corpo da resposta estão na seção Comentários abaixo.

Exceções

testRunId ou content é nulo.

testRunId é uma cadeia de caracteres vazia e esperava-se que não estivesse vazia.

O serviço retornou um código de status sem êxito.

Exemplos

Este exemplo mostra como chamar CreateOrUpdateServerMetricsConfigAsync com os parâmetros necessários e analisar o resultado.

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

var data = new {};

Response response = await client.CreateOrUpdateServerMetricsConfigAsync("<testRunId>", RequestContent.Create(data));

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.ToString());

Este exemplo mostra como chamar CreateOrUpdateServerMetricsConfigAsync com todos os parâmetros e conteúdo da solicitação e como analisar o resultado.

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

var data = new {
    metrics = new {
        key = new {
            resourceId = "<resourceId>",
            metricNamespace = "<metricNamespace>",
            displayDescription = "<displayDescription>",
            name = "<name>",
            aggregation = "<aggregation>",
            unit = "<unit>",
            resourceType = "<resourceType>",
        },
    },
};

Response response = await client.CreateOrUpdateServerMetricsConfigAsync("<testRunId>", RequestContent.Create(data));

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("testRunId").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("resourceId").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("metricNamespace").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("displayDescription").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("aggregation").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("unit").ToString());
Console.WriteLine(result.GetProperty("metrics").GetProperty("<test>").GetProperty("resourceType").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("createdBy").ToString());
Console.WriteLine(result.GetProperty("lastModifiedDateTime").ToString());
Console.WriteLine(result.GetProperty("lastModifiedBy").ToString());

Comentários

Abaixo está o esquema JSON para as cargas de solicitação e resposta.

Corpo da solicitação:

Esquema para TestRunServerMetricConfig:

{
  testRunId: string, # Optional. Test run identifier
  metrics: Dictionary<string, ResourceMetric>, # Optional. Azure resource metrics collection {metric id : metrics object} (Refer : https://docs.microsoft.com/en-us/rest/api/monitor/metric-definitions/list#metricdefinition for metric id).
  createdDateTime: string (ISO 8601 Format), # Optional. The creation datetime(ISO 8601 literal format).
  createdBy: string, # Optional. The user that created.
  lastModifiedDateTime: string (ISO 8601 Format), # Optional. The last Modified datetime(ISO 8601 literal format).
  lastModifiedBy: string, # Optional. The user that last modified.
}

Corpo da resposta:

Esquema para TestRunServerMetricConfig:

{
  testRunId: string, # Optional. Test run identifier
  metrics: Dictionary<string, ResourceMetric>, # Optional. Azure resource metrics collection {metric id : metrics object} (Refer : https://docs.microsoft.com/en-us/rest/api/monitor/metric-definitions/list#metricdefinition for metric id).
  createdDateTime: string (ISO 8601 Format), # Optional. The creation datetime(ISO 8601 literal format).
  createdBy: string, # Optional. The user that created.
  lastModifiedDateTime: string (ISO 8601 Format), # Optional. The last Modified datetime(ISO 8601 literal format).
  lastModifiedBy: string, # Optional. The user that last modified.
}

Aplica-se a