

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 对 Amazon Managed Service for Prometheus 错误进行故障排除
<a name="AMP-troubleshooting"></a>

利用以下部分来协助排查使用 Amazon Managed Service for Prometheus 时遇到的问题。

**Topics**
+ [429 或超出限制错误](#AMP-troubleshoot-429)
+ [我看到重复的样本](#AMP-troubleshoot-duplicate)
+ [我看到关于样本时间戳的错误](#AMP-troubleshoot-duplicate-ordering)
+ [我看到一条与限制相关的错误消息](#AMP-troubleshoot-limiterror)
+ [您的本地 Prometheus 服务器输出超出了限制。](#AMP-understand-output)
+ [我的一些数据没有出现](#AMP-troubleshoot-discarded-data)
+ [HTTP 422 错误：查询超时](#AMP-troubleshoot-http-422)

## 429 或超出限制错误
<a name="AMP-troubleshoot-429"></a>

如果您看到类似于以下示例的 429 错误，则说明您的请求已超过 Amazon Managed Service for Prometheus 摄取配额。

```
ts=2020-10-29T15:34:41.845Z caller=dedupe.go:112 component=remote level=error remote_name=e13b0c 
url=http://iamproxy-external.prometheus.uswest2-prod.eks:9090/workspaces/{{workspace_id}}/api/v1/remote_write 
msg="non-recoverable error" count=500 err="server returned HTTP status 429 
Too Many Requests: ingestion rate limit (6666.666666666667) exceeded while adding 499 samples and 0 metadata
```

如果您看到类似于以下示例的 429 错误，则说明您的请求已超过 Amazon Managed Service for Prometheus 配额，即工作区中活跃指标数量的配额。

```
ts=2020-11-05T12:40:33.375Z caller=dedupe.go:112 component=remote level=error remote_name=aps 
url=http://iamproxy-external.prometheus.uswest2-prod.eks:9090/workspaces/{{workspace_id}}/api/v1/remote_write 
msg="non-recoverable error" count=500 err="server returned HTTP status 429 Too Many Requests: user={{accountid}}_{{workspace_id}}: 
per-user series limit (local limit: 0 global limit: 3000000 actual local limit: 500000) exceeded
```

如果您看到类似下面示例的 429 错误，则说明您的请求已超过 Amazon Managed Service for Prometheus 对使用与 Prometheus 兼容的 `RemoteWrite` API 向工作区发送数据的速率（每秒事务数）的配额。

```
ts=2024-03-26T16:50:21.780708811Z caller=dedupe.go:112 component=remote level=error remote_name=ab123c 
url=https://aps-workspaces.us-east-1.amazonaws.com/workspaces/{{workspace_id}}/api/v1/remote_write 
msg="non-recoverable error" count=1000 exemplarCount=0 err="server returned HTTP status 429 Too Many Requests: {\"message\":\"Rate exceeded\"}"
```

如果您看到类似下面示例的 400 错误，则说明您的请求已超出 Amazon Managed Service for Prometheus 的活动时间序列配额。有关如何处理活动时间序列配额的详细信息，请参阅[活跃系列默认配额](AMP_quotas.md#AMP-dynamic-series)。

```
ts=2024-03-26T16:50:21.780708811Z caller=push.go:53 level=warn
url=https://aps-workspaces.us-east-1.amazonaws.com/workspaces/{{workspace_id}}/api/v1/remote_write
msg="non-recoverable error" count=500 exemplarCount=0 
err="server returned HTTP status 400 Bad Request: maxFailure (quorum) on a given error family, rpc error: code = Code(400) 
desc = addr=10.1.41.23:9095 state=ACTIVE zone=us-east-1a, rpc error: code = Code(400) 
desc = user={{accountid}}_{{workspace_id}}: per-user series limit of 10000000 exceeded, 
Capacity from 2,000,000 to 10,000,000 is automatically adjusted based on the last 30 min of usage. 
If throttled above 10,000,000 or in case of incoming surges, please contact administrator to raise it. 
(local limit: 0 global limit: 10000000 actual local limit: 92879)"
```

有关 Amazon Managed Service for Prometheus 服务配额以及如何请求提升配额的更多信息，请参阅 [Amazon Managed Service for Prometheus 服务配额](AMP_quotas.md)

## 我看到重复的样本
<a name="AMP-troubleshoot-duplicate"></a>

如果您使用的是高可用性 Prometheus 组，则需要在 Prometheus 实例上使用外部标签来设置重复数据删除。有关更多信息，请参阅 [对发送到 Amazon Managed Service for Prometheus 的高可用性指标进行重复数据删除](AMP-ingest-dedupe.md)。

有关复制数据的其他问题将在下一节讨论。

## 我看到关于样本时间戳的错误
<a name="AMP-troubleshoot-duplicate-ordering"></a>

Amazon Managed Service for Prometheus 按顺序摄取数据，并希望每个样本的时间戳都晚于前一个样本。

如果数据没有按顺序到达，则会出现以下错误：`out-of-order samples`、`duplicate sample for timestamp` 或 `samples with different value but same timestamp`。这些问题通常是由于向 Amazon Managed Service for Prometheus 发送数据的客户端设置不正确造成的。如果使用的是在代理模式下运行的 Prometheus 客户端，请检查配置中是否有系列名称重复或目标重复的规则。如果您的指标直接提供时间戳，请检查它们是否错乱。

您可以为工作空间配置一个无序的时间窗口，以接受乱序样本。有关更多信息，请参阅 [配置工作区](AMP-workspace-configuration.md)。

*有关其工作原理或检查设置方法的更多详细信息，请参阅 Prom Labs 的博客文章《[了解 Prometheus 中的重复样本和 Out-of-order 时间戳错误](https://promlabs.com/blog/2022/12/15/understanding-duplicate-samples-and-out-of-order-timestamp-errors-in-prometheus/)》。*

## 我看到一条与限制相关的错误消息
<a name="AMP-troubleshoot-limiterror"></a>

**注意**  
适用于 Prometheus 的亚马逊托管服务提供[CloudWatch 使用率指标来监控 Prometheus 的资源使用情况](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-CW-usage-metrics.html)。使用 CloudWatch使用情况指标警报功能，您可以监控 Prometheus 的资源和使用情况，以防止出现限制错误。

如果您看到以下错误消息之一，则可以请求增加其中一个 Amazon Managed Service for Prometheus 配额来解决问题。有关更多信息，请参阅 [Amazon Managed Service for Prometheus 服务配额](AMP_quotas.md)。
+ {{<value>}}已超出每用户系列限制，请联系管理员提高该限制
+ {{<value>}}已超出每指标系列的限制，请联系管理员提高
+ 超过了摄取率限制(...)
+ 系列有太多标签(...)系列: '%s'
+ 查询时间范围超出限制(查询长度: xxx，限制: yyy)
+ 查询在从摄取器获取组块时达到最大组块数限制
+ 超出了限制。每个账户的最大工作区。

## 您的本地 Prometheus 服务器输出超出了限制。
<a name="AMP-understand-output"></a>

Amazon Managed Service for Prometheus 为工作区可以从 Prometheus 服务器接收的数据量设定了服务配额。要查找您的 Prometheus 服务器向 Amazon Managed Service for Prometheus 发送的数据量，您可以在 Prometheus 服务器上运行以下查询。如果您发现自己的 Prometheus 输出超出了 Amazon Managed Service for Prometheus 的限制，则可以请求增加相应的服务配额。有关更多信息，请参阅 [Amazon Managed Service for Prometheus 服务配额](AMP_quotas.md)。


**查询您的本地自运行 Prometheus 服务器以查找输出限制。**  

| 数据类型 | 要使用的查询 | 
| --- | --- | 
| 当前活跃系列 | `prometheus_tsdb_head_series` | 
| 当前摄取率 | `rate(prometheus_tsdb_head_samples_appended_total[5m])` | 
| Most-to-least 每个指标名称的活动系列列表 | `sort_desc(count by(__name__) ({__name__!=""}))` | 
| 每个指标系列的标签数 | `group by(mylabelname) ({__name__!=""})` | 

## 我的一些数据没有出现
<a name="AMP-troubleshoot-discarded-data"></a>

由于各种原因，发送到 Amazon Managed Service for Prometheus 的数据可能会被丢弃。下表列出了数据可能被丢弃而不是被摄取的原因。

您可以使用 Amazon CloudWatch 跟踪丢弃数据的数量和原因。有关更多信息，请参阅 [使用 CloudWatch 指标监控亚马逊托管服务的 Prometheus 资源](AMP-CW-usage-metrics.md)。


|  Reason  |  含义  | 
| --- | --- | 
| greater\_than\_max\_sample\_age | 丢弃比当前时间更早的日志行 | 
| new-value-for-timestamp | 发送重复样本的时间戳与上一个样本的时间戳相同，但值不同。 | 
| per\_metric\_series\_limit | 用户已达到每个指标活跃系列数上限 | 
| per\_user\_series\_limit | 用户已达到活跃系列总数上限 | 
| rate\_limited | 摄取率受限制 | 
| sample-out-of-order | 样本发送顺序混乱，无法处理。只有当乱序时间窗口设置为 0 时才会发出此原因。 | 
| 样本太陈旧了 | 样本早于配置的失序时间窗口，因此无法处理。 | 
| 失序速率限制 | Out-of-order 已达到摄取速率限制，无法处理样本。有关更多信息，请参阅 [Amazon Managed Service for Prometheus 服务配额](AMP_quotas.md)。 | 
| label\_value\_too\_long | 标签值超过允许的字符限制 | 
| max\_label\_names\_per\_series | 用户已达到每个指标的标签名称数 | 
| missing\_metric\_name | 未提供指标名称 | 
| metric\_name\_invalid | 提供的指标名称无效 | 
| label\_invalid | 提供的标签无效 | 
| duplicate\_label\_names | 提供的标签名称重复  | 
| 已超出原生直方图样本大小字节 | 原生直方图样本超过允许的最大样本量。减少客户端直方图中存储桶或跨度的数量。 | 
| 原生直方图无效架构 | 本机直方图的架构值无效。有效架构的范围从 -4 到 8。请检查您的 Prometheus 客户端配置以了解设置。`NativeHistogramBucketFactor` | 
| 原生直方图无效 | 原生直方图未能通过验证（例如，存储桶计数为负、存储桶计数不匹配或存储桶跨度格式不正确）。这通常表示仪器库中存在错误。 | 
| 已超出原生直方图存储桶 | 原生直方图超过了最大存储桶数量限制，无法自动降低分辨率。使用`NativeHistogramMaxBucketNumber`减少客户端的存储桶数量。 | 
| 本机直方图速率有限 | 原生直方图样本被拒绝，因为已达到原生直方图摄取速率限制。减少原生直方图序列的数量或抓取频率，或者请求提高限制。 | 
| per\_user\_native\_histive\_直方图系列\_限制 | 用户已达到每个工作空间的本机直方图活动序列限制。减少原生直方图序列的数量或请求提高限制。 | 

## HTTP 422 错误：查询超时
<a name="AMP-troubleshoot-http-422"></a>

如果您的查询运行时间超过 1 分钟，则适用于 Prometheus 的亚马逊托管服务会返回 HTTP 422 状态码。以下示例显示了此错误：

```
{"status":"error","errorType":"execution","error":"query timed out - consider simplifying your query"}
```

要缩短评估时间，请使用以下一种或多种方法：
+ 指定较短的时间窗口，以评估更少的样本。
+ 添加标签匹配器以减少查询评估的系列数量。
+ 使用[录制规则](AMP-ruler-rulesfile.md)来预先计算您经常查询的昂贵聚合。
+ 避免在高基数标签（具有许多唯一值的标签）上使用正则表达式匹配器。

有关更多信息，请参阅 [查询 Prometheus 指标](AMP-query.md)。