

 **帮助改进此页面** 

要帮助改进本用户指南，请选择位于每个页面右侧窗格中的**在 GitHub 上编辑此页面**链接。

# 使用 Prometheus 监控集群指标
<a name="prometheus"></a>

 [Prometheus](https://prometheus.io/) 是一个用于抓取端点的监控和时间序列数据库。提供查询、聚合和存储收集的数据的功能。您还可以将其用于警报和警报聚合。本主题介绍如何将 Prometheus 设置为托管或开源选项。一个常见用例为监控 Amazon EKS 控制面板指标。

Amazon Managed Service for Prometheus 是一项与 Prometheus 兼容的监控和警报服务，可以轻松实现对容器化应用程序和基础设施的大规模监控。这是一项完全托管的服务，可自动扩展指标的提取、存储、查询和警报。这项服务还集成了 Amazon 安全服务，可以快速安全地访问您的数据。您可以使用开源 PromQL 查询语言来查询指标并发出警报。此外，您还可以使用 Amazon Managed Service for Prometheus 中的警报管理器来设置关键警报的提醒规则。然后，您可以将这些关键警报作为通知发送到某个 Amazon SNS 主题。

可以通过多种方式将 Prometheus 与 Amazon EKS 结合使用：
+ 您可以在首次创建 Amazon EKS 集群时开启 Prometheus 指标，也可以为现有集群创建自己的 Prometheus 抓取程序。本主题涵盖了这两个选项。
+ 您可以使用 Helm 部署 Prometheus。有关更多信息，请参阅 [使用 Helm 部署 Prometheus](deploy-prometheus.md)。
+ 您可以查看 Prometheus 格式的控制面板原始指标。有关更多信息，请参阅 [获取 Prometheus 格式的控制面板原始指标](view-raw-metrics.md)。

## 第 1 步：开启 Prometheus 指标
<a name="turn-on-prometheus-metrics"></a>

**重要**  
适用于 Prometheus 的 Amazon 托管服务资源不在集群生命周期内，需要独立于集群进行维护。删除集群时，请务必同时删除所有适用的抓取器以停止适用的费用。有关更多信息，请参阅*《Amazon Managed Service for Prometheus 用户指南》*中的[查找和删除抓取程序](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-collector-how-to.html#AMP-collector-list-delete)。

Prometheus 通过一个名为抓取的拉取模型从集群中发现和收集指标。设置抓取程序以从您的集群基础设施和容器化应用程序中收集数据。当您开启发送 Prometheus 指标的选项时，Amazon Managed Service for Prometheus 会提供一个完全托管的无代理抓取程序。

如果尚未创建集群，您可以在首次创建集群时开启向 Prometheus 发送指标的选项。在 Amazon EKS 控制台中，此选项位于创建新集群的**配置可观测性**步骤中。有关更多信息，请参阅 [创建一个 Amazon EKS 集群。](create-cluster.md)。

如果您已经有现有的集群，则可以创建自己的 Prometheus 抓取程序。要在 Amazon EKS 控制台中执行此操作，请导航到集群的**可观测性**选项卡，然后选择**添加抓取器**按钮。如果您更愿意使用 Amazon API 或 Amazon CLI 执行此操作，请参阅《Amazon Managed Service for Prometheus User Guide》**中的 [Create a scraper](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-collector-how-to.html#AMP-collector-create)。

使用 Amazon EKS 控制台创建抓取程序时，可以使用以下选项。

 **抓取程序别名**   
（可选）输入抓取程序的唯一别名。

 **目标位置**   
选择 Amazon Managed Service for Prometheus 工作区。工作区是专用于存储和查询 Prometheus 指标的逻辑空间。借助此工作区，您将能够查看有权访问该工作区账户的 Prometheus 指标。**创建新工作区**选项指示 Amazon EKS 使用您提供的**工作区别名**，来代表您创建工作区。您可以使用**选择现有工作区**选项，从下拉列表中选择一个现有工作区。有关工作区的更多信息，请参阅《Amazon Managed Service for Prometheus 用户指南》**中的[管理工作区](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-manage-ingest-query.html)。

 **服务访问**   
本节总结了您在发送 Prometheus 指标时授予的权限：  
+ 允许 Amazon Managed Service for Prometheus 描述抓取的 Amazon EKS 集群
+ 允许远程写入 Amazon Managed Prometheus 工作区
如果 `AmazonManagedScraperRole` 已存在，抓取程序会进行使用。选择 `AmazonManagedScraperRole` 链接以查看**权限详细信息**。如果 `AmazonManagedScraperRole` 尚不存在，请选择**查看权限详细信息**链接，查看您通过发送 Prometheus 指标授予的特定权限。

 **子网**   
根据需要修改抓取程序将继承的子网。如果需要添加灰显的子网选项，请返回创建集群**指定网络**步骤。

 **抓取程序配置**   
根据需要修改 YAML 格式的抓取程序进行配置。为此，请使用表单或上传替换的 YAML 文件。有关更多信息，请参阅《Amazon Managed Service for Prometheus 用户指南》**中的[抓取程序配置](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-collector-how-to.html#AMP-collector-configuration)。

Amazon Managed Service for Prometheus 指的是与集群一起创建的无代理抓取程序，作为 Amazon 托管的收集器。有关 Amazon 托管的收集器的更多信息，请参阅《Amazon Managed Service for Prometheus 用户指南》**中的 [使用 Amazon 托管收集器摄取指标](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-collector.html)。

**重要**  
如果您使用 Amazon CLI 或 Amazon API 创建 Prometheus 抓取程序，则需要调整其配置，向抓取程序授予集群内的权限。有关更多信息，请参阅《Amazon Managed Service for Prometheus 用户指南》**中的[配置您的 Amazon EKS 集群](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-collector-how-to.html#AMP-collector-eks-setup)。
如果您在 2024 年 11 月 11 日之前创建了使用 `aws-auth` `ConfigMap` 而非访问条目的 Prometheus 抓取程序，则需要对其进行更新才能从 Amazon EKS 集群控制面板访问其他指标。有关更新的配置，请参阅《Amazon Managed Service for Prometheus 用户指南》**中的[手动配置 Amazon EKS 以获取抓取工具访问权限](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-collector-how-to.html#AMP-collector-eks-manual-setup)。

## 第 2 步：使用 Prometheus 指标
<a name="use-prometheus-metrics"></a>

有关为集群开启 Prometheus 指标后如何使用这些指标的详细信息，请参阅《[Amazon Managed Service for Prometheus User Guide](https://docs.amazonaws.cn/prometheus/latest/userguide/what-is-Amazon-Managed-Service-Prometheus.html)》。

## 第 3 步：管理 Prometheus 抓取程序
<a name="viewing-prometheus-scraper-details"></a>

要管理抓取程序，请在 Amazon EKS 控制台中选择**可观测性**选项卡。一个显示集群抓取程序列表的表格，包括抓取程序 ID、别名、状态和创建日期等信息。您可以添加更多抓取程序、编辑抓取程序、删除抓取程序或查看有关当前抓取程序的更多信息。

要查看有关抓取程序的更多详细信息，请选择抓取程序 ID 链接。例如，您可以查看 ARN、环境、工作空间 ID、IAM 角色、配置和网络信息。您可以使用抓取程序 ID 作为 Amazon Managed Service for Prometheus API 操作的输入，例如 [https://docs.amazonaws.cn/prometheus/latest/APIReference/API_DescribeScraper.html](https://docs.amazonaws.cn/prometheus/latest/APIReference/API_DescribeScraper.html)、[https://docs.amazonaws.cn/prometheus/latest/APIReference/API_UpdateScraper.html](https://docs.amazonaws.cn/prometheus/latest/APIReference/API_UpdateScraper.html) 和 [https://docs.amazonaws.cn/prometheus/latest/APIReference/API_DeleteScraper.html](https://docs.amazonaws.cn/prometheus/latest/APIReference/API_DeleteScraper.html)。有关使用 Prometheus API 的更多信息，请参阅 [Amazon Managed Service for Prometheus API Reference](https://docs.amazonaws.cn/prometheus/latest/userguide/AMP-APIReference.html)。