

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 設定 Amazon EKS 的受管收集器
<a name="AMP-collector-how-to"></a>

若要使用 Amazon Managed Service for Prometheus 收集器，您可以建立抓取器來探索和提取 Amazon EKS 叢集中的指標。您也可以建立與 Amazon Managed Streaming for Apache Kafka 整合的抓取器。如需詳細資訊，請參閱[整合 Amazon MSK](https://docs.aws.amazon.com/prometheus/latest/userguide/prom-msk-integration.html)。
+ 您可以建立湊集器作為 Amazon EKS 叢集建立作業的一部份。如需建立 Amazon EKS 叢集的詳細資訊，包括建立抓取器，請參閱《[Amazon EKS 使用者指南》中的建立 Amazon EKS 叢集](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html)。 **
+ 您可以使用 AWS API 或使用 ，以程式設計方式建立自己的抓取器 AWS CLI。

Amazon Managed Service for Prometheus 收集器會抓取與 Prometheus 相容的指標。如需 Prometheus 相容指標的詳細資訊，請參閱 [什麼是與 Prometheus 相容的指標？](prom-compatible-metrics.md)。Amazon EKS 叢集會公開 API 伺服器的指標。Kubernetes 版本`1.28`或更高版本的 Amazon EKS 叢集也會公開 `kube-scheduler`和 的指標`kube-controller-manager`。如需詳細資訊，請參閱《*Amazon EKS 使用者指南*》中的[擷取 Prometheus 格式的控制平面原始指標](https://docs.aws.amazon.com/eks/latest/userguide/view-raw-metrics.html#scheduler-controller-metrics)。

**注意**  
從叢集擴展指標可能會產生網路用量的費用。最佳化這些成本的一種方法是設定您的`/metrics`端點來壓縮提供的指標 （例如，使用 gzip)，以減少必須跨網路移動的資料。如何執行此操作取決於提供指標的應用程式或程式庫。根據預設，某些程式庫 gzip。

下列主題說明如何建立、管理和設定湊集器。

**Topics**
+ [建立湊集器](#AMP-collector-create)
+ [設定 Amazon EKS 叢集](#AMP-collector-eks-setup)
+ [尋找並刪除湊集器](#AMP-collector-list-delete)
+ [湊集器組態](#AMP-collector-configuration)
+ [對湊集器組態進行移難排解](#AMP-collector-troubleshoot)
+ [湊集器限制](#AMP-collector-limits)

## 建立湊集器
<a name="AMP-collector-create"></a>

Amazon Managed Service for Prometheus 收集器包含一個湊集器，可從 Amazon EKS 叢集中探索和收集指標。Amazon Managed Service for Prometheus 可為您管理湊集器，提供所需的可擴展性、安全性和可靠性，而無需自行管理任何執行個體、代理程式或湊集器。

建立抓取器的方法有三種：
+ 當您[透過 Amazon EKS 主控台建立 Amazon EKS 叢集](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html)並選擇開啟 Prometheus 指標時，系統會自動為您建立抓取器。
+ 您可以從 Amazon EKS 主控台為現有叢集建立抓取器。在 [Amazon EKS 主控台](https://console.aws.amazon.com/eks/home#/clusters)中開啟叢集，然後在**可觀測性**索引標籤上，選擇**新增抓取器**。

  如需可用設定的詳細資訊，請參閱《*Amazon EKS 使用者指南*》中的[開啟 Prometheus 指標](https://docs.aws.amazon.com/eks/latest/userguide/prometheus.html#turn-on-prometheus-metrics)。
+ 您可以使用 AWS API 或 建立抓取器 AWS CLI。

  這些選項會在下列程序中說明。

您需先滿足幾項先決條件，才能建立自己的湊集器：
+ 您必須已建立 Amazon EKS 叢集。
+ 您的 Amazon EKS 叢集必須設定[叢集端點存取控制](https://docs.aws.amazon.com/eks/latest/userguide/cluster-endpoint.html)以包含私有存取。它可以包括私有和公有，但必須包含私有。
+ Amazon EKS 叢集所在的 Amazon VPC 必須[啟用 DNS](https://docs.aws.amazon.com/vpc/latest/userguide/AmazonDNS-concepts.html)。

**注意**  
叢集將依其 Amazon 資源名稱 (ARN) 與抓取器建立關聯。如果您刪除叢集，然後使用相同名稱建立新的叢集，則 ARN 將重複使用於新叢集。因此，抓取器會嘗試收集新叢集的指標。[您可以將抓取器](#AMP-collector-list-delete)與刪除叢集分開刪除。

------
#### [ AWS API ]

**使用 AWS API 建立 **

使用 `CreateScraper` API 操作來建立具有 AWS API 的抓取器。以下範例會在 `us-west-2` 地區中建立湊集器。您需要使用自己的 ID 取代 AWS 帳戶、工作區、安全性和 Amazon EKS 叢集資訊，並提供用於湊集器的組態。

**注意**  
安全群組和子網路應設定為您要連線之叢集的安全群組和子網路。  
您必須包含至少兩個子網路，至少位於兩個可用區域。

`scrapeConfiguration` 是一個 base64 編碼的 Prometheus 組態 YAML 檔案。您可以透過 `GetDefaultScraperConfiguration` API 作業下載一般用途設定。如需 的格式詳細資訊`scrapeConfiguration`，請參閱 [湊集器組態](#AMP-collector-configuration)。

```
POST /scrapers HTTP/1.1
Content-Length: 415 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: aws-cli/1.18.147 Python/2.7.18 Linux/5.4.58-37.125.amzn2int.x86_64 botocore/1.18.6

{
    "alias": "myScraper",
    "destination":  {
        "ampConfiguration": {
            "workspaceArn": "arn:aws:aps:us-west-2:{{account-id}}:workspace/ws-{{workspace-id}}"
        }
    },
    "source": {
        "eksConfiguration": {
            "clusterArn": "arn:aws:eks:us-west-2:{{account-id}}:cluster/{{cluster-name}}",
            "securityGroupIds": ["sg-{{security-group-id}}"],
            "subnetIds": ["subnet-{{subnet-id-1}}", "subnet-{{subnet-id-2}}"]
        }
    },
    "scrapeConfiguration": {
        "configurationBlob": {{<base64-encoded-blob>}}
    }
}
```

------
#### [ AWS CLI ]

**使用 AWS CLI建立湊集器**

使用 `create-scraper`命令來建立具有 的抓取器 AWS CLI。以下範例會在 `us-west-2` 地區中建立湊集器。您需要使用自己的 ID 取代 AWS 帳戶、工作區、安全性和 Amazon EKS 叢集資訊，並提供用於湊集器的組態。

**注意**  
安全群組和子網路應設定為您要連線之叢集的安全群組和子網路。  
您必須包含至少兩個子網路，至少位於兩個可用區域。

`scrape-configuration` 是一個 base64 編碼的 Prometheus 組態 YAML 檔案。您可以使用 `get-default-scraper-configuration`命令下載一般用途組態。如需 的格式詳細資訊`scrape-configuration`，請參閱 [湊集器組態](#AMP-collector-configuration)。

```
aws amp create-scraper \
  --source eksConfiguration="{clusterArn='arn:aws:eks:us-west-2:{{account-id}}:cluster/{{cluster-name}}', securityGroupIds=['sg-{{security-group-id}}'],subnetIds=['subnet-{{subnet-id-1}}', 'subnet-{{subnet-id-2}}']}" \
  --scrape-configuration configurationBlob={{<base64-encoded-blob>}} \
  --destination ampConfiguration="{workspaceArn='arn:aws:aps:us-west-2:{{account-id}}:workspace/ws-{{workspace-id}}'}"
```

------

下列是您可以與 AWS API 一併使用的完整湊集器作業清單：
+ 使用 [CreateScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_CreateScraper.html) API 操作建立抓取器。
+ 使用 [ListScrapers](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_ListScrapers.html) API 操作列出現有的抓取器。
+ 使用 [UpdateScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_UpdateScraper.html) API 操作更新抓取器的別名、組態或目的地。
+ 使用 [DeleteScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_DeleteScraper.html) API 操作刪除抓取器。
+ 使用 [DescribeScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_DescribeScraper.html) API 操作取得有關抓取器的詳細資訊。
+ 使用 [GetDefaultScraperConfiguration](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_GetDefaultScraperConfiguration.html) API 操作取得抓取器的一般用途組態。

**注意**  
必須設定您要湊集的 Amazon EKS 叢集以讓 Amazon Managed Service for Prometheus 存取指標。下一個主題說明如何設定叢集。

### 跨帳戶設定
<a name="cross-account-remote-write"></a>

若要在 Amazon EKS 叢集和 Amazon Managed Service for Prometheus 工作區位於不同帳戶時建立跨帳戶抓取器，請使用下列程序。例如，您有`account_id_source`包含 Amazon EKS 叢集的來源帳戶，以及`account_id_target`包含 Amazon Managed Service for Prometheus 工作區的目標帳戶。

**在跨帳戶設定中建立抓取器**

1. 在來源帳戶中，建立角色`arn:aws:iam::{{account_id}}_source:role/Source`並新增下列信任政策。

   ```
   {
       "Effect": "Allow",
       "Principal": {
       "Service": [
           "scraper.aps.amazonaws.com"
        ]
       },
       "Action": "sts:AssumeRole",
       "Condition": {
           "ArnEquals": {
               "aws:SourceArn": "scraper_ARN"
           },
           "StringEquals": {
               "AWS:SourceAccount": "account_id"
           }
       }
   }
   ```

1. 在來源 (Amazon EKS 叢集） 和目標 (Amazon Managed Service for Prometheus 工作區） 的每個組合上，您需要建立角色，`arn:aws:iam::{{account_id}}_target:role/Target`並新增具有 [AmazonPrometheusRemoteWriteAccess](https://docs.aws.amazon.com/prometheus/latest/userguide/security-iam-awsmanpol.html) 許可的下列信任政策。

   ```
   {
     "Effect": "Allow",
     "Principal": {
        "AWS": "arn:aws:iam::account_id_source:role/Source"
     },
     "Action": "sts:AssumeRole",
     "Condition": {
        "StringEquals": {
           "sts:ExternalId": "scraper_ARN"
         }
     }
   }
   ```

1. 使用 `--role-configuration`選項建立抓取器。

   ```
   aws amp create-scraper \
     --source eksConfiguration="{clusterArn='arn:aws:eks:us-west-2:{{account-id}}_source:cluster/xarw,subnetIds=[subnet-{{subnet-id}}]}" \
     --scrape-configuration configurationBlob={{<base64-encoded-blob>}} \
     --destination ampConfiguration="{workspaceArn='arn:aws:aps:us-west-2:{{account-id}}_target:workspace/ws-{{workspace-id}}'}"\
     --role-configuration '{"sourceRoleArn":"arn:aws:iam::{{account-id}}_source:role/Source", "targetRoleArn":"arn:aws:iam::{{account-id}}_target:role/Target"}'
   ```

1. 驗證抓取器建立。

   ```
   aws amp list-scrapers
   {
       "scrapers": [
           {
               "scraperId": "{{scraper-id}}",
               "arn": "arn:aws:aps:us-west-2:{{account_id}}_source:scraper/{{scraper-id}}",
               "roleArn": "arn:aws:iam::{{account_id}}_source:role/aws-service-role/scraper.aps.amazonaws.com/AWSServiceRoleForAmazonPrometheusScraperInternal_cc319052-41a3-4",
               "status": {
                   "statusCode": "ACTIVE"
               },
               "createdAt": "2024-10-29T16:37:58.789000+00:00",
               "lastModifiedAt": "2024-10-29T16:55:17.085000+00:00",
               "tags": {},
               "source": {
                   "eksConfiguration": {
                       "clusterArn": "arn:aws:eks:us-west-2:{{account_id}}_source:cluster/xarw",
                       "securityGroupIds": [
                           "sg-{{security-group-id}}",
                           "sg-{{security-group-id}}"
                       ],
                       "subnetIds": [
                           "subnet-{{subnet_id}}"
                       ]
                   }
               },
               "destination": {
                   "ampConfiguration": {
                       "workspaceArn": "arn:aws:aps:us-west-2:{{account_id}}_target:workspace/ws-{{workspace-id}}"
                   }
               }
           }
       ]
   }
   ```

### 在 RoleConfiguration 和服務連結角色之間變更
<a name="changing-roles"></a>

當您想要切換回服務連結角色，而不是 `RoleConfiguration` 以寫入 Amazon Managed Service for Prometheus 工作區時，您必須更新 ，`UpdateScraper`並在與抓取器相同的帳戶中提供工作區，而不使用 `RoleConfiguration`。`RoleConfiguration` 將從抓取器中移除，並使用服務連結角色。

當您變更與抓取器相同帳戶中的工作區，並且想要繼續使用 時`RoleConfiguration`，您必須再次`RoleConfiguration`在 上提供 `UpdateScraper`。

### 為使用客戶受管金鑰啟用的工作區建立抓取器
<a name="setup-customer-managed-keys"></a>

若要建立抓取器，以使用[客戶受管金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk)將指標擷取至 Amazon Managed Service for Prometheus 工作區，請使用同時將來源和目標設定為相同帳戶`--role-configuration`的 。

```
aws amp create-scraper \
  --source eksConfiguration="{clusterArn='arn:aws:eks:us-west-2:{{account-id}}:cluster/xarw,subnetIds=[subnet-{{subnet_id}}]}" \
  --scrape-configuration configurationBlob={{<base64-encoded-blob>}} \
  --destination ampConfiguration="{workspaceArn='arn:aws:aps:us-west-2:{{account-id}}:workspace/ws-{{workspace-id}}'}"\
  --role-configuration '{"sourceRoleArn":"arn:aws:iam::{{account_id}}:role/Source", "targetRoleArn":"arn:aws:iam::{{account_id}}:role/Target"}'
```

### 建立抓取器時的常見錯誤
<a name="AMP-collector-create-errors"></a>

以下是嘗試建立新的抓取器時最常見的問題。
+ 所需的 AWS 資源不存在。指定的*安全群組*、*子網路*和 *Amazon EKS 叢集*必須存在。
+ IP 地址空間不足。您必須在每個傳入 `CreateScraper` API 的子網路中至少有一個可用的 IP 地址。

## 設定 Amazon EKS 叢集
<a name="AMP-collector-eks-setup"></a>

必須設定您的 Amazon EKS 叢集以讓湊集器存取指標。此組態有兩個選項：
+ 使用 Amazon EKS *存取項目*自動提供叢集的 Amazon Managed Service for Prometheus 收集器存取權。
+ 手動設定 Amazon EKS 叢集以進行受管指標抓取。

下列主題會更詳細地說明這些主題。

### 使用存取項目為抓取器存取設定 Amazon EKS
<a name="AMP-collector-eks-access-entry-setup"></a>

使用 Amazon EKS 的存取項目是讓 Amazon Managed Service for Prometheus 存取叢集的湊集指標最簡單的方式。

您抓取的 Amazon EKS 叢集必須設定為允許 API 身分驗證。叢集身分驗證模式必須設定為 `API`或 `API_AND_CONFIG_MAP`。這可在叢集詳細資訊的**存取組態**索引標籤上的 Amazon EKS 主控台中檢視。如需詳細資訊，請參閱《[Amazon EKS 使用者指南》中的允許 IAM 角色或使用者存取 Amazon EKS 叢集上的 Kubernetes 物件](https://docs.aws.amazon.com/eks/latest/userguide/access-entries.html)。 **

您可以在建立叢集時或在建立叢集之後建立抓取器：
+ **建立叢集時** – 當您[透過 Amazon EKS 主控台建立 Amazon EKS 叢集](https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html)時，您可以設定此存取 （遵循指示來建立叢集中的抓取器），系統會自動建立存取項目政策，讓 Amazon Managed Service for Prometheus 存取叢集指標。
+ **建立叢集後新增 **- 如果您的 Amazon EKS 叢集已存在，請將身分驗證模式設定為 `API`或 `API_AND_CONFIG_MAP`，而您[透過 Amazon Managed Service for Prometheus API 或 CLI](#AMP-collector-create) 或透過 Amazon EKS 主控台建立的任何抓取器，將自動擁有為您建立的正確存取項目政策，抓取器將可存取您的叢集。

**已建立存取項目政策**

當您建立抓取器並讓 Amazon Managed Service for Prometheus 為您產生存取項目政策時，會產生下列政策。如需存取項目的詳細資訊，請參閱[《Amazon EKS 使用者指南》中的允許 IAM 角色或使用者存取 Kubernetes](https://docs.aws.amazon.com/eks/latest/userguide/access-entries.html)。 **

```
{
    "rules": [
        {
            "effect": "allow",
            "apiGroups": [
                ""
            ],
            "resources": [
                "nodes",
                "nodes/proxy",
                "nodes/metrics",
                "services",
                "endpoints",
                "pods",
                "ingresses",
                "configmaps"
            ],
            "verbs": [
                "get",
                "list",
                "watch"
            ]
        },
        {
            "effect": "allow",
            "apiGroups": [
                "extensions",
                "networking.k8s.io"
            ],
            "resources": [
                "ingresses/status",
                "ingresses"
            ],
            "verbs": [
                "get",
                "list",
                "watch"
            ]
        },
        {
            "effect": "allow",
            "apiGroups": [
                "metrics.eks.amazonaws.com"
            ],
            "resources": [
                "kcm/metrics",
                "ksh/metrics"
            ],
            "verbs": [
                "get"
            ]
        },
        {
            "effect": "allow",
            "nonResourceURLs": [
                "/metrics"
            ],
            "verbs": [
                "get"
            ]
        }
    ]
}
```

### 手動設定 Amazon EKS 以進行抓取器存取
<a name="AMP-collector-eks-manual-setup"></a>

如果您偏好使用 `aws-auth ConfigMap`來控制對 kubernetes 叢集的存取，您仍然可以讓 Amazon Managed Service for Prometheus 湊集器存取您的指標。下列步驟將授予 Amazon Managed Service for Prometheus 從您的 Amazon EKS 叢集抓取指標的存取權。

**注意**  
如需 `ConfigMap`和 存取項目的詳細資訊，請參閱《*Amazon EKS 使用者指南*》中的[允許 IAM 角色或使用者存取 Kubernetes](https://docs.aws.amazon.com/eks/latest/userguide/access-entries.html)。

此程序使用 `kubectl`和 AWS CLI。如需有關安裝 `kubectl` 的資訊，請參閱《Amazon EKS 使用者指南》**中的[安裝 kubectl](https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html)。

**手動設定 Amazon EKS 叢集以進行受管指標抓取**

1. 使用下列內文建立名為 `clusterrole-binding.yml` 的檔案：

   ```
   apiVersion: rbac.authorization.k8s.io/v1
   kind: ClusterRole
   metadata:
     name: aps-collector-role
   rules:
     - apiGroups: [""]
       resources: ["nodes", "nodes/proxy", "nodes/metrics", "services", "endpoints", "pods", "ingresses", "configmaps"]
       verbs: ["describe", "get", "list", "watch"]
     - apiGroups: ["extensions", "networking.k8s.io"]
       resources: ["ingresses/status", "ingresses"]
       verbs: ["describe", "get", "list", "watch"]
     - nonResourceURLs: ["/metrics"]
       verbs: ["get"]
     - apiGroups: ["metrics.eks.amazonaws.com"]
       resources: ["kcm/metrics", "ksh/metrics"]
       verbs: ["get"]
   ---
   apiVersion: rbac.authorization.k8s.io/v1
   kind: ClusterRoleBinding
   metadata:
     name: aps-collector-user-role-binding
   subjects:
   - kind: User
     name: aps-collector-user
     apiGroup: rbac.authorization.k8s.io
   roleRef:
     kind: ClusterRole
     name: aps-collector-role
     apiGroup: rbac.authorization.k8s.io
   ```

1. 在叢集中執行下列命令：

   ```
   kubectl apply -f clusterrole-binding.yml
   ```

   這將建立叢集角色連結和規則。此範例使用 `aps-collector-role` 作為角色名稱和 `aps-collector-user` 作為使用者名稱。

1. 以下命令為您提供有關含有 ID 為 {{scraper-id}} 的資訊。這是您使用上一節命令建立的湊集器。

   ```
   aws amp describe-scraper --scraper-id {{scraper-id}}
   ```

1. 在 `describe-scraper` 的結果中尋找 `roleArn`，其格式如下：

   ```
   arn:aws:iam::{{account-id}}:role/aws-service-role/scraper.aps.amazonaws.com/AWSServiceRoleForAmazonPrometheusScraper_{{unique-id}}
   ```

   Amazon EKS 需要此 ARN 的不同格式。您必須調整傳回 ARN 的格式，以便在下一步中使用。編輯以比對此格式：

   ```
   arn:aws:iam::{{account-id}}:role/AWSServiceRoleForAmazonPrometheusScraper_{{unique-id}}
   ```

   例如，此 ARN：

   ```
   arn:aws:iam::111122223333:role/aws-service-role/scraper.aps.amazonaws.com/AWSServiceRoleForAmazonPrometheusScraper_1234abcd-56ef-7
   ```

   必須改寫為：

   ```
   arn:aws:iam::111122223333:role/AWSServiceRoleForAmazonPrometheusScraper_1234abcd-56ef-7
   ```

1. 使用上一個步驟中修改後的 `roleArn` 以及您的叢集名稱和區域，在叢集中執行下列命令：

   ```
   eksctl create iamidentitymapping --cluster {{cluster-name}} --region {{region-id}} --arn {{roleArn}} --username aps-collector-user
   ```

   這允許湊集器使用 `clusterrole-binding.yml` 檔案中建立的角色和使用者存取叢集。

## 尋找並刪除湊集器
<a name="AMP-collector-list-delete"></a>

您可以使用 AWS API 或 AWS CLI 列出您帳戶中的抓取器或刪除它們。

**注意**  
請確定您使用的是最新版本的 AWS CLI 或 SDK。最新版本為您提供最新的功能和功能，以及安全性更新。或者，使用 [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html)，它會自動提供up-to-date命令列體驗。

若要列出您帳戶中的所有抓取器，請使用 [ListScrapers](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_ListScrapers.html) API 操作。

或者，使用 AWS CLI呼叫：

```
aws amp list-scrapers --region {{{{aws-region}}}}
```

`ListScrapers` 會傳回您帳戶中的所有湊集器，例如：

```
{
    "scrapers": [
        {
            "scraperId": "s-1234abcd-56ef-7890-abcd-1234ef567890",
            "arn": "arn:aws:aps:us-west-2:123456789012:scraper/s-1234abcd-56ef-7890-abcd-1234ef567890",
            "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/AWSServiceRoleForAmazonPrometheusScraper_1234abcd-2931",
            "status": {
                "statusCode": "DELETING"
            },
            "createdAt": "2023-10-12T15:22:19.014000-07:00",
            "lastModifiedAt": "2023-10-12T15:55:43.487000-07:00",
            "tags": {},
            "source": {
                "eksConfiguration": {
                    "clusterArn": "arn:aws:eks:us-west-2:123456789012:cluster/my-cluster",
                    "securityGroupIds": [
                        "sg-1234abcd5678ef90"
                    ],
                    "subnetIds": [
                        "subnet-abcd1234ef567890", 
                        "subnet-1234abcd5678ab90"
                    ]
                }
            },
            "destination": {
                "ampConfiguration": {
                    "workspaceArn": "arn:aws:aps:us-west-2:123456789012:workspace/ws-1234abcd-5678-ef90-ab12-cdef3456a78"
                }
            }
        }
    ]
}
```

若要刪除抓取器，請使用 `ListScrapers`操作尋找您要刪除之抓取器`scraperId`的 ，然後使用 [DeleteScraper](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_DeleteScraper.html) 操作將其刪除。

或者，使用 AWS CLI呼叫：

```
aws amp delete-scraper --scraper-id {{scraperId}}
```

## 湊集器組態
<a name="AMP-collector-configuration"></a>

您可以使用與 Prometheus 相容的湊集器組態控制湊集器如何探索和收集指標。例如，您可以變更將指標傳送至工作區的間隔。您也可以使用重新標籤來動態重新寫入指標的標籤。湊集器組態是一個 YAML 檔案，屬於湊集器定義的一部份。

建立新的湊集器時，您可以透過在 API 呼叫中提供 base64 編碼的 YAML 檔案來指定組態。您可以透過 Amazon Managed Service for Prometheus API 中的 `GetDefaultScraperConfiguration` 作業下載一般用途組態檔案。

若要修改抓取器的組態，您可以使用 `UpdateScraper`操作。如果您需要更新指標的來源 （例如，其他 Amazon EKS 叢集），您必須刪除抓取器，並使用新來源重新建立該抓取器。

**支援的組態**

如需抓取器組態格式的相關資訊，包括可能值的詳細明細，請參閱 Prometheus 文件中的[組態](https://prometheus.io/docs/prometheus/latest/configuration/configuration/)。全域組態選項和 `<scrape_config>` 選項說明最常需要的選項。

由於 Amazon EKS 是唯一支援的服務，因此支援的唯一服務探索組態 (`<*_sd_config>`) 是 `<kubernetes_sd_config>`。

允許組態區段的完整清單：
+ `<global>`
+ `<scrape_config>`
+ `<static_config>`
+ `<relabel_config>`
+ `<metric_relabel_configs>`
+ `<kubernetes_sd_config>`

這些區段中的限制會列在範例組態檔案之後。

**範例組態檔案**

以下是具有 30 秒湊集間隔的範例 YAML 組態檔。此範例包含對 kube API 伺服器指標，以及 kube-controller-manager 和 kube-scheduler 指標的支援。如需詳細資訊，請參閱《*Amazon EKS 使用者指南*》中的[擷取 Prometheus 格式的控制平面原始指標](https://docs.aws.amazon.com/eks/latest/userguide/view-raw-metrics.html#scheduler-controller-metrics)。

```
global:
   scrape_interval: 30s
   external_labels:
     clusterArn: apiserver-test-2
scrape_configs:
  - job_name: pod_exporter
    kubernetes_sd_configs:
      - role: pod
  - job_name: cadvisor
    scheme: https
    authorization:
      type: Bearer
      credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    kubernetes_sd_configs:
      - role: node
    relabel_configs:
      - action: labelmap
        regex: __meta_kubernetes_node_label_(.+)
      - replacement: kubernetes.default.svc:443
        target_label: __address__
      - source_labels: [__meta_kubernetes_node_name]
        regex: (.+)
        target_label: __metrics_path__
        replacement: /api/v1/nodes/$1/proxy/metrics/cadvisor
  # apiserver metrics
  - scheme: https
    authorization:
      type: Bearer
      credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    job_name: kubernetes-apiservers
    kubernetes_sd_configs:
    - role: endpoints
    relabel_configs:
    - action: keep
      regex: default;kubernetes;https
      source_labels:
      - __meta_kubernetes_namespace
      - __meta_kubernetes_service_name
      - __meta_kubernetes_endpoint_port_name
  # kube proxy metrics
  - job_name: kube-proxy
    honor_labels: true
    kubernetes_sd_configs:
    - role: pod
    relabel_configs:
    - action: keep
      source_labels:
      - __meta_kubernetes_namespace
      - __meta_kubernetes_pod_name
      separator: '/'
      regex: 'kube-system/kube-proxy.+'
    - source_labels:
      - __address__
      action: replace
      target_label: __address__
      regex: (.+?)(\\:\\d+)?
      replacement: $1:10249
  # Scheduler metrics
  - job_name: 'ksh-metrics'
    kubernetes_sd_configs:
    - role: endpoints
    metrics_path: /apis/metrics.eks.amazonaws.com/v1/ksh/container/metrics
    scheme: https
    bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    relabel_configs:
    - source_labels:
      - __meta_kubernetes_namespace
      - __meta_kubernetes_service_name
      - __meta_kubernetes_endpoint_port_name
      action: keep
      regex: default;kubernetes;https
  # Controller Manager metrics
  - job_name: 'kcm-metrics'
    kubernetes_sd_configs:
    - role: endpoints
    metrics_path: /apis/metrics.eks.amazonaws.com/v1/kcm/container/metrics
    scheme: https
    bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    relabel_configs:
    - source_labels:
      - __meta_kubernetes_namespace
      - __meta_kubernetes_service_name
      - __meta_kubernetes_endpoint_port_name
      action: keep
      regex: default;kubernetes;https
```

以下是 AWS 受管收集器特有的限制：
+ **湊集間隔**：湊集器組態無法指定少於 30 秒的湊集間隔。
+ **目標**：`static_config` 中的目標必須指定為 IP 地址。
+ **DNS 解析** – 與目標名稱相關，此組態中辨識的唯一伺服器名稱是 Kubernetes api 伺服器 `kubernetes.default.svc`。所有其他機器名稱都必須由 IP 地址指定。
+ **授權** – 如果不需要授權，請省略 。如果需要，授權必須是 `Bearer`，而且必須指向檔案 `/var/run/secrets/kubernetes.io/serviceaccount/token`。換句話說，如果使用 ，授權區段必須如下所示：

  ```
      authorization:
        type: Bearer
        credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  ```
**注意**  
`type: Bearer` 是預設值，因此可以省略。

## 對湊集器組態進行移難排解
<a name="AMP-collector-troubleshoot"></a>

Amazon Managed Service for Prometheus 收集器會自動探索和湊集指標。但是，若未在 Amazon Managed Service for Prometheus 工作區中看到您希望看到的指標，該如何進行疑難排解？

**重要**  
確認已啟用 Amazon EKS 叢集的私有存取。如需詳細資訊，請參閱《*Amazon EKS 使用者指南*》中的[叢集私有端點](https://docs.aws.amazon.com/eks/latest/userguide/cluster-endpoint.html#cluster-endpoint-private)。

`up` 指標是一個有助益的工具。針對 Amazon Managed Service for Prometheus 收集器探索的每個端點，皆會自動分配此指標。此指標有三種狀態，可協助您疑難排解收集器內所發生的事情。
+ `up` 不存在 - 若端點沒有 `up` 指標，則這表示收集器找不到端點。

  如果您確定端點存在，收集器可能無法找到它有幾個原因。
  + 您可能需要調整湊集組態。探索`relabel_config`可能需要調整。
  + `role` 用於探索的 可能有問題。
  + Amazon EKS 叢集使用的 Amazon VPC 可能尚未[啟用 DNS](https://docs.aws.amazon.com/vpc/latest/userguide/AmazonDNS-concepts.html)，這會使收集器無法尋找端點。
+ `up` 已存在，但始終為 0 — 如果 `up` 已存在但為 0，則收集器能夠探索端點，但找不到任何與 Prometheus 相容的指標。

  在這種情況下，您可以嘗試直接對端點使用 `curl` 命令。您可以驗證詳細資訊是否正確，例如，您正在使用的通訊協定 (`http` 或 `https`)、端點或連接埠。您也可以檢查端點是否以有效的`200`回應回應，並遵循 Prometheus 格式。最後，回應的內文不能大於允許的大小上限。（如需 AWS 受管收集器的限制，請參閱下一節。)
+ `up` 已存在且大於 0 — 若 `up` 已存在且大於 0，則指標會傳送至 Amazon Managed Service for Prometheus。

  驗證您正在尋找 Amazon Managed Service for Prometheus (或您的替代儀表板，例如 Amazon Managed Grafana) 中的正確指標。您可以再次使用 curl 來檢查`/metrics`端點中的預期數據。同時檢查您是否未超過其他限制，例如每個湊集器的端點數量。您可以使用 檢查指標計數，以檢查要抓取的`up`指標端點數量`count(up)`。

## 湊集器限制
<a name="AMP-collector-limits"></a>

Amazon Managed Service for Prometheus 所提供全受管湊集器的限制較少。
+ **區域**：您的 EKS 叢集、受管理湊集器和 Amazon Managed Service for Prometheus workspace 必須位於相同 AWS 區域。
+ **收集器**：各帳戶最多可以為每個區域提供 10 個 Amazon Managed Service for Prometheus 湊集器。
**注意**  
您可以透過[請求增加配額](https://console.aws.amazon.com/support/home#/case/create?issueType=service-limit-increase)來請求增加此限制。
+ **指標回應**：來自任何一個 `/metrics` 端點請求的回應主體不能超過 50 MB。
+ **每個湊集器的端點**：湊集器最多可以湊集 30,000 `/metrics` 個端點。
+ **湊集間隔**：湊集器組態無法指定少於 30 秒的湊集間隔。