列出 CloudWatch 控制面板 - Amazon CloudWatch
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

列出 CloudWatch 控制面板

以下代码示例展示如何列出 Amazon CloudWatch 控制面板。

.NET
Amazon SDK for .NET

using System; using System.Collections.Generic; using System.Threading.Tasks; using Amazon.CloudWatch; using Amazon.CloudWatch.Model; /// <summary> /// Shows how to retrieve a list of Amazon CloudWatch dashboards. This /// example was written using AWSSDK for .NET version 3.7 and .NET Core 5.0. /// </summary> public class ListDashboards { public static async Task Main() { IAmazonCloudWatch cwClient = new AmazonCloudWatchClient(); var dashboards = await ListDashboardsAsync(cwClient); DisplayDashboardList(dashboards); } /// <summary> /// Get the list of available dashboards. /// </summary> /// <param name="client">The initialized CloudWatch client used to /// retrieve a list of defined dashboards.</param> /// <returns>A list of DashboardEntry objects.</returns> public static async Task<List<DashboardEntry>> ListDashboardsAsync(IAmazonCloudWatch client) { var response = await client.ListDashboardsAsync(new ListDashboardsRequest()); return response.DashboardEntries; } /// <summary> /// Displays the name of each CloudWatch Dashboard in the list passed /// to the method. /// </summary> /// <param name="dashboards">A list of DashboardEntry objects.</param> public static void DisplayDashboardList(List<DashboardEntry> dashboards) { if (dashboards.Count > 0) { Console.WriteLine("The following dashboards are defined:"); foreach (var dashboard in dashboards) { Console.WriteLine($"Name: {dashboard.DashboardName} Last modified: {dashboard.LastModified}"); } } else { Console.WriteLine("No dashboards found."); } } }

有关 Amazon 开发工具包开发人员指南和代码示例的完整列表,包括帮助入门和有关早期版本的信息,请参阅 将 CloudWatch 与 Amazon 开发工具包结合使用