View a markdown version of this page

VPC 連線的受管收集器 - Amazon CloudWatch

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

VPC 連線的受管收集器

連接 VPC 的 Amazon CloudWatch 受管 Prometheus 收集器會從 VPC 內可存取的任何資源擷取 Prometheus相容的指標:Amazon EC2 執行個體和 Amazon ECS 任務。您提供子網路和安全群組;收集器會建立彈性網路介面 (ENIs),並根據您的組態抓取Prometheus/metrics端點。

如需特定工作負載的詳細演練,請參閱 Prometheus 指標集合的 CloudWatch 可觀測性解決方案: Amazon CloudWatch Prometheus 解決方案:Amazon EC2 上的指標集合Amazon CloudWatch Prometheus 解決方案:Amazon ECS 上的指標集合

先決條件

此程序假設熟悉 Amazon VPC 子網路、安全群組和Prometheus匯出工具端點。

  • 啟用 DNS 的 Amazon VPC

  • 不同可用區域中至少有兩個子網路

  • 安全群組允許收集器到達您的目標匯出器連接埠

  • 公開Prometheus相容 /metrics端點的目標

收集器會透過 AWS 網路將抓取指標交付至 CloudWatch,而不會周遊公有網際網路。您指定的子網路和安全群組可提供與湊集目標的連線;它們不提供 CloudWatch 交付路徑。您不需要在 VPC 中設定網際網路存取、NAT 閘道或 CloudWatch 介面 VPC 端點,即可交付指標。

建立湊集器

您可以使用 GetDefaultScraperConfiguration來擷取一般用途的抓取器組態,或提供您自己的組態。

AWS API

使用 CreateScraper API 操作建立具有 CloudWatch 目的地的抓取器。將子網路、安全群組和資料集資訊取代為您自己的值。

POST /scrapers HTTP/1.1 { "alias": "vpc-metrics-scraper", "source": { "vpcConfiguration": { "subnetIds": ["subnet-subnet-id-1", "subnet-subnet-id-2"], "securityGroupIds": ["sg-security-group-id"] } }, "destination": { "cloudWatchConfiguration": { "datasetArn": "arn:aws:cloudwatch:us-west-2:123456789012:dataset/default" } }, "scrapeConfiguration": { "configurationBlob": "base64-encoded-blob" } }
AWS CLI

使用 create-scraper命令建立具有 CloudWatch 目的地的抓取器。將子網路、安全群組和資料集資訊取代為您自己的值。

aws amp create-scraper \ --alias "vpc-metrics-scraper" \ --source '{ "vpcConfiguration": { "subnetIds": ["subnet-subnet-id-1", "subnet-subnet-id-2"], "securityGroupIds": ["sg-security-group-id"] } }' \ --scrape-configuration configurationBlob=$(cat scrape-config.yaml | base64 -w 0) \ --destination '{ "cloudWatchConfiguration": { "datasetArn": "arn:aws:cloudwatch:us-west-2:123456789012:dataset/default" } }'

從 Amazon EC2 收集指標

若要從執行 DCGM Exporter 或 Node Exporter 等Prometheus匯出工具的 Amazon EC2 執行個體抓取指標,請使用 static_configs搭配執行個體私有 IP 地址:

global: scrape_interval: 60s scrape_configs: - job_name: 'ec2-node-exporter' static_configs: - targets: - '10.0.1.10:9100' - '10.0.1.11:9100' relabel_configs: - source_labels: [__address__] target_label: instance - target_label: compute_platform replacement: 'ec2' - job_name: 'ec2-dcgm-exporter' static_configs: - targets: - '10.0.1.10:9400' - '10.0.1.11:9400' relabel_configs: - source_labels: [__address__] target_label: instance - target_label: compute_platform replacement: 'ec2'

從 Amazon ECS 收集指標

對於您向 AWS Cloud Map 註冊的 Amazon ECS 任務,請使用 DNS 服務探索來自動尋找和抓取容器:

global: scrape_interval: 60s scrape_configs: - job_name: 'ecs-services' dns_sd_configs: - names: - 'my-service.my-namespace.local' type: A port: 9090 relabel_configs: - source_labels: [__meta_dns_name] target_label: service_name - source_labels: [__address__] target_label: instance - target_label: compute_platform replacement: 'ecs'

跨帳戶可觀測性

對於跨帳戶 VPC 監控,我們建議您使用 Amazon CloudWatch 指標集中。如需詳細資訊,請參閱 CloudWatch 指標集中。

如需其他跨帳戶抓取器組態,請參閱《Amazon Managed Service for Prometheus 使用者指南》中的跨帳戶抓取器

安全最佳實務

  • 指定沒有收集器 ENIs 直接網際網路存取的私有子網路。

  • 將安全群組傳入限制為僅限特定匯出程式連接埠上的湊集器安全群組。

  • 盡可能為所有匯出工具端點啟用傳輸中的 TLS 加密。