Links#
1. YACE Config#
CloudFront CloudWatch metrics 通常从 us-east-1 查询。
apiVersion: v1alpha1
sts-region: us-east-1
discovery:
exportedTagsOnMetrics:
AWS/CloudFront:
- Environment
jobs:
- type: AWS/CloudFront
regions: [us-east-1]
period: 300
length: 600
nilToZero: true
metrics:
- name: Requests
statistics: [Sum]
- name: TotalErrorRate
statistics: [Average]
- name: 4xxErrorRate
statistics: [Average]
- name: 5xxErrorRate
statistics: [Average]
- name: CacheHitRate
statistics: [Average]
- name: OriginLatency
statistics: [Average, p95, p99]
- name: BytesDownloaded
statistics: [Sum]
- name: BytesUploaded
statistics: [Sum]Tag and environment note#
如果你想按 uat / prod 区分 CloudFront,不要把 us-east-1 当成环境。CloudFront 是 global service,环境通常来自 distribution 自己的 AWS tag。
如果你的 CloudFront distribution 上有 AWS tag:
Environment=uat并且你在 YACE 里配置了:
exportedTagsOnMetrics:
AWS/CloudFront:
- Environment那么 YACE 导出后通常会变成:
tag_Environment="uat"脱敏后的实际样本可以长这样:
aws_cloudfront_bytes_downloaded_sum{
account_id="123456789012",
dimension_DistributionId="E1ABCDEFG2HIJK",
dimension_Region="Global",
name="arn:aws:cloudfront::123456789012:distribution/E1ABCDEFG2HIJK",
region="us-east-1",
tag_Environment="uat"
} 0注意:
tag key 大小写敏感
如果 AWS tag key 实际写的是 Environment
导出的 label 很可能会是:
tag_Environment="uat"customTags 不是用来读取 CloudFront 资源 tag 的。它只是给整个 YACE job 打静态 label,例如:
customTags:
- key: environment
value: uat导出后通常会变成:
custom_tag_environment="uat"这表示:
这个 job 采到的所有指标都被静态标成 uat
不是从 CloudFront distribution 本身读取出来的 environment对于 CloudFront 这种 global service,如果你希望环境跟着 distribution 自己走,优先用:
AWS resource tag + exportedTagsOnMetrics当前这套 dashboard 用的是统一后的:
environment="uat"所以如果你的 YACE 原始 label 是 tag_Environment,建议在 vmagent / Prometheus scrape 阶段统一改成 environment。
示例:如果环境来自 AWS resource tag
scrape_configs:
- job_name: yace
static_configs:
- targets:
- yace:5000
metric_relabel_configs:
- source_labels: [tag_Environment]
regex: "(.+)"
target_label: environment
replacement: "$1"
action: replace
- regex: "tag_Environment"
action: labeldrop落地前先在 VMUI 里确认实际 label 名,不要猜:
aws_cloudfront_requests_sum看样本里到底出现的是:
tag_Environment
environment2. Dashboard Rows#
| Row | Panels |
|---|---|
| Overview | requests, total error rate, 4xx/5xx, cache hit rate |
| Drilldown | error split, origin latency, bytes downloaded/uploaded |
| Capacity | request trend, bandwidth trend, cache hit trend |
| Debug | origin latency p95/p99 and error spikes |
Trend note:
带 Trend 的 panel 不是原始单点值。
当前 CloudFront dashboard 里:
Request Trend
最近 1 小时 rolling sum
Bandwidth Trend
最近 1 小时 rolling sum
Cache Hit Trend
最近 1 小时 rolling average3. Verify#
{__name__=~"aws_cloudfront_.*"}重点确认这几个 metric 是否存在:
aws_cloudfront_cache_hit_rate_average
aws_cloudfront_origin_latency_average
aws_cloudfront_origin_latency_p95
aws_cloudfront_origin_latency_p99如果 aws_cloudfront_requests_sum、aws_cloudfront_4xx_error_rate_average、aws_cloudfront_5xx_error_rate_average 有值,但上面 4 个没有值,通常不是 dashboard 查询问题,而是下面两类原因:
1. 实际运行中的 YACE config 没有收集:
CacheHitRate Average
OriginLatency Average / p95 / p99
2. CloudFront distribution 没有启用 additional metrics:
CacheHitRate
OriginLatencyYACE 侧应包含:
- name: CacheHitRate
statistics: [Average]
- name: OriginLatency
statistics: [Average, p95, p99]CloudWatch 侧用 us-east-1 和 Region=Global 验证源数据是否存在:
aws cloudwatch list-metrics \
--region us-east-1 \
--namespace AWS/CloudFront \
--metric-name OriginLatency如果 list-metrics 查不到 OriginLatency / CacheHitRate,YACE 即使配置了也不会导出有效时间序列。先在 CloudFront distribution 的 monitoring 页面启用 additional metrics,再等 CloudWatch 产生新 datapoint。