

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

# 湊集器組態
<a name="managed-prometheus-collectors-scraper-configuration"></a>

Amazon CloudWatch 受管 Prometheus 收集器使用Prometheus與 相容的 YAML 組態來定義收集器如何抓取指標。您可以在建立或更新抓取器時，將此組態提供為 base64 編碼的 Blob。組態使用標準湊Prometheus集組態格式，具有受管收集器的特定限制。

您可以使用 [GetDefaultScraperConfiguration](https://docs.aws.amazon.com/prometheus/latest/APIReference/API_GetDefaultScraperConfiguration.html)來擷取一般用途的抓取器組態，或提供您自己的組態。

## 支援的組態區段
<a name="managed-prometheus-collectors-scraper-configuration-supported"></a>

支援Prometheus抓取組態的下列最上層區段：
+ `global` — 全域設定`scrape_timeout`，包括 `scrape_interval`、 和 `external_labels`。
+ `scrape_configs` — 抓取任務清單，每個任務都定義了目標，以及如何抓取它們。

在每個`scrape_configs`項目中，支援下列欄位：
+ `job_name` — 湊集任務的唯一名稱。
+ `metrics_path` — 抓取的 HTTP 路徑 （預設為 `/metrics`)。
+ `scheme` — 通訊協定結構描述 (`http` 或 `https`)。
+ `scrape_interval` — 全域湊集間隔的每個任務覆寫。
+ `scrape_timeout` — 全域湊集逾時的每個任務覆寫。
+ `static_configs` — 目標的靜態清單。
+ `dns_sd_configs` — 以 DNS 為基礎的服務探索。
+ `relabel_configs` — 重新標記在抓取之前套用的規則。
+ `metric_relabel_configs` — 重新標記抓取後套用的規則。
+ `tls_config` — HTTPS 目標的 TLS 組態。

## 範例組態
<a name="managed-prometheus-collectors-scraper-configuration-example"></a>

下列範例示範基本的湊集組態：

```
global:
  scrape_interval: 60s
  scrape_timeout: 10s
  external_labels:
    environment: production

scrape_configs:
  - job_name: 'my-service'
    metrics_path: /metrics
    scheme: http
    static_configs:
      - targets:
          - '{{10.0.1.10}}:9090'
          - '{{10.0.1.11}}:9090'
        labels:
          team: platform
    relabel_configs:
      - source_labels: [__address__]
        target_label: instance
    metric_relabel_configs:
      - source_labels: [__name__]
        regex: 'go_.*'
        action: drop
```

## 限制
<a name="managed-prometheus-collectors-scraper-configuration-limits"></a>
+ 最短`scrape_interval`為 30 秒。
+ 受管收集器不支援檔案型服務探索 (`file_sd_configs`)。
+ 受管收集器不支援 Consul、Eureka 或其他外部服務探索機制。
+ 遠端寫入和遠端讀取組態不適用，因為收集器會處理 CloudWatch 的交付。
+ 組態大小上限為 256 KB。

## 疑難排解
<a name="managed-prometheus-collectors-scraper-configuration-troubleshooting"></a>

如果您的抓取器未如預期收集指標，請檢查下列項目：
+ 確認連接到抓取器的安全群組允許傳出流量到您的目標連接埠。
+ 確認您的目標可從您在抓取器組態中指定的子網路存取。
+ 檢查 VPC 內用於 的 DNS 名稱是否正確`dns_sd_configs`解析。
+ 請確定您的目標以`metrics_path`有效的Prometheus表達格式回應所設定的 。

如需其他故障診斷指引，請參閱《*Amazon Managed Service for Prometheus 使用者指南*》中的[故障診斷受管收集器](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-troubleshooting.html)。