将 ListDashboards 与 Amazon SDK 或 CLI 配合使用 - Amazon CloudWatch
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

ListDashboards 与 Amazon SDK 或 CLI 配合使用

以下代码示例演示如何使用 ListDashboards

.NET
适用于 .NET 的 Amazon SDK
注意

查看 GitHub,了解更多信息。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/// <summary> /// Get a list of dashboards. /// </summary> /// <returns>A list of DashboardEntry objects.</returns> public async Task<List<DashboardEntry>> ListDashboards() { var results = new List<DashboardEntry>(); var paginateDashboards = _amazonCloudWatch.Paginators.ListDashboards( new ListDashboardsRequest()); // Get the entire list using the paginator. await foreach (var data in paginateDashboards.DashboardEntries) { results.Add(data); } return results; }
  • 有关 API 详细信息,请参阅《适用于 .NET 的 Amazon SDK API 参考》中的 ListDashboards

CLI
Amazon CLI

检索控制面板的列表

以下 list-dashboards 示例列出了指定账户中的所有控制面板。

aws cloudwatch list-dashboards

输出:

{ "DashboardEntries": [ { "DashboardName": "Dashboard-A", "DashboardArn": "arn:aws:cloudwatch::123456789012:dashboard/Dashboard-A", "LastModified": "2024-10-11T18:40:11+00:00", "Size": 271 }, { "DashboardName": "Dashboard-B", "DashboardArn": "arn:aws:cloudwatch::123456789012:dashboard/Dashboard-B", "LastModified": "2024-10-11T18:44:41+00:00", "Size": 522 } ] }

有关更多信息,请参阅《Amazon CloudWatch 用户指南》中的使用 Amazon CloudWatch 控制面板

  • 有关 API 详细信息,请参阅《Amazon CLI Command Reference》中的 ListDashboards

Java
适用于 Java 的 SDK 2.x
注意

查看 GitHub,了解更多信息。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

/** * Lists the available dashboards. * * @return a {@link CompletableFuture} that completes when the operation is finished. * The future will complete exceptionally if an error occurs while listing the dashboards. */ public CompletableFuture<Void> listDashboardsAsync() { ListDashboardsRequest listDashboardsRequest = ListDashboardsRequest.builder().build(); ListDashboardsPublisher paginator = getAsyncClient().listDashboardsPaginator(listDashboardsRequest); return paginator.subscribe(response -> { response.dashboardEntries().forEach(entry -> { logger.info("Dashboard name is: {} ", entry.dashboardName()); logger.info("Dashboard ARN is: {} ", entry.dashboardArn()); }); }).exceptionally(ex -> { logger.info("Failed to list dashboards: {} ", ex.getMessage()); throw new RuntimeException("Error occurred while listing dashboards", ex); }); }
  • 有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API 参考》中的 ListDashboards

Kotlin
适用于 Kotlin 的 SDK
注意

查看 GitHub,了解更多信息。在 Amazon 代码示例存储库中查找完整示例,了解如何进行设置和运行。

suspend fun listDashboards() { CloudWatchClient { region = "us-east-1" }.use { cwClient -> cwClient .listDashboardsPaginated({}) .transform { it.dashboardEntries?.forEach { obj -> emit(obj) } } .collect { obj -> println("Name is ${obj.dashboardName}") println("Dashboard ARN is ${obj.dashboardArn}") } } }
  • 有关 API 详细信息,请参阅《Amazon SDK for Kotlin API 参考》中的 ListDashboards

PowerShell
适用于 PowerShell 的工具

示例 1:返回您账户的控制面板集合。

Get-CWDashboardList

输出

DashboardArn DashboardName LastModified Size ------------ ------------- ------------ ---- arn:... Dashboard1 7/6/2017 8:14:15 PM 252

示例 2:返回名称以前缀“dev”开头的账户的控制面板集合。

Get-CWDashboardList -DashboardNamePrefix dev
  • 有关 API 详细信息,请参阅《Amazon Tools for PowerShell Cmdlet 参考》中的 ListDashboards

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将 CloudWatch 与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。