Ci sono altri AWS SDK esempi disponibili nel repository AWS Doc SDK Examples GitHub .
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzare DeleteAnomalyDetector
con un AWS SDK o CLI
I seguenti esempi di codice mostrano come utilizzareDeleteAnomalyDetector
.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- .NET
-
- AWS SDK for .NET
-
/// <summary>
/// Delete a single metric anomaly detector.
/// </summary>
/// <param name="anomalyDetector">The anomaly detector to delete.</param>
/// <returns>True if successful.</returns>
public async Task<bool> DeleteAnomalyDetector(SingleMetricAnomalyDetector anomalyDetector)
{
var deleteAnomalyDetectorResponse = await _amazonCloudWatch.DeleteAnomalyDetectorAsync(
new DeleteAnomalyDetectorRequest()
{
SingleMetricAnomalyDetector = anomalyDetector
});
return deleteAnomalyDetectorResponse.HttpStatusCode == HttpStatusCode.OK;
}
- Java
-
- SDKper Java 2.x
-
public static void deleteAnomalyDetector(CloudWatchClient cw, String fileName) {
try {
// Read values from the JSON file.
JsonParser parser = new JsonFactory().createParser(new File(fileName));
com.fasterxml.jackson.databind.JsonNode rootNode = new ObjectMapper().readTree(parser);
String customMetricNamespace = rootNode.findValue("customMetricNamespace").asText();
String customMetricName = rootNode.findValue("customMetricName").asText();
SingleMetricAnomalyDetector singleMetricAnomalyDetector = SingleMetricAnomalyDetector.builder()
.metricName(customMetricName)
.namespace(customMetricNamespace)
.stat("Maximum")
.build();
DeleteAnomalyDetectorRequest request = DeleteAnomalyDetectorRequest.builder()
.singleMetricAnomalyDetector(singleMetricAnomalyDetector)
.build();
cw.deleteAnomalyDetector(request);
System.out.println("Successfully deleted the Anomaly Detector.");
} catch (CloudWatchException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
}
}
- Kotlin
-
- SDKper Kotlin
-
suspend fun deleteAnomalyDetector(fileName: String) {
// Read values from the JSON file.
val parser = JsonFactory().createParser(File(fileName))
val rootNode = ObjectMapper().readTree<JsonNode>(parser)
val customMetricNamespace = rootNode.findValue("customMetricNamespace").asText()
val customMetricName = rootNode.findValue("customMetricName").asText()
val singleMetricAnomalyDetectorVal =
SingleMetricAnomalyDetector {
metricName = customMetricName
namespace = customMetricNamespace
stat = "Maximum"
}
val request =
DeleteAnomalyDetectorRequest {
singleMetricAnomalyDetector = singleMetricAnomalyDetectorVal
}
CloudWatchClient { region = "us-east-1" }.use { cwClient ->
cwClient.deleteAnomalyDetector(request)
println("Successfully deleted the Anomaly Detector.")
}
}