

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

# Amazon Managed Service for Prometheus API 参考
<a name="AMP-APIReference"></a>

Amazon Managed Service for Prometheus 提供两种类型的 API：

1. **Amazon Managed Service for Prometheus API** – 借助这些 API，您可以创建和管理 Amazon Managed Service for Prometheus 工作区，包括针对工作区、抓取程序、警报管理器定义、规则组命名空间和日志记录的操作。您可以使用适用于各种编程语言的 AWS SDK 与这些 API 交互。

1. **与 Prometheus 兼容的 API** – Amazon Managed Service for Prometheus 支持与 Prometheus 兼容的 HTTP API。通过这些 API，可以构建自定义应用程序、自动执行工作流、与其他服务或工具集成，以及使用 Prometheus 查询语言（PromQL）查询监控数据并与之交互。

本部分列出了 Amazon Managed Service for Prometheus 支持的 API 操作和数据结构。

有关系列、标签和 API 请求配额的信息，请参阅《Amazon Managed Service for Prometheus 用户指南》**中的 [Amazon Managed Service for Prometheus 服务配额](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP_quotas.html)。

**Topics**
+ [Amazon Managed Service for Prometheus API](AMP-APIReference-AMPApis.md)
+ [兼容普罗米修斯 APIs](AMP-APIReference-Prometheus-Compatible-Apis.md)

# Amazon Managed Service for Prometheus API
<a name="AMP-APIReference-AMPApis"></a>

Amazon Managed Service for Prometheus 提供创建和维护 Amazon Managed Service for Prometheus 工作区的相关 API 操作。其中包括用于工作区、抓取程序、警报管理器定义、规则组命名空间和日志记录的 API。

有关 Amazon Managed Service for Prometheus API 的详细信息，请参阅 [Amazon Managed Service for Prometheus API 参考](https://docs.aws.amazon.com/prometheus/latest/APIReference/Welcome.html)。

## 将 Amazon Managed Service for Prometheus 与 AWS SDK 配合使用
<a name="AMP-APIReference-SDKs"></a>

AWS 软件开发工具包（SDK）适用于许多常用编程语言。每个 SDK 都提供 API、代码示例和文档，使开发人员能够更轻松地以其首选语言构建 AWS 应用程序。有关按语言划分的 SDK 和工具列表，请参阅 AWS *开发人员中心* 的[用于在 AWS 上进行构建的工具](https://aws.amazon.com/developer/tools/)。

**开发工具包版本**  
我们建议您使用项目中使用的最新版本的 AWS 开发工具包以及任何其他开发工具包，并使开发工具包保持最新。AWS 开发工具包为您提供最新的特性和功能以及安全更新。

# 兼容普罗米修斯 APIs
<a name="AMP-APIReference-Prometheus-Compatible-Apis"></a>

适用于 Prometheus 的亚马逊托管服务支持以下与 Prometheus 兼容的服务。 APIs

 有关使用兼容 Prometheus 的更多信息，请参阅。 APIs [使用兼容普罗米修斯进行查询 APIs](AMP-onboard-query-APIs.md)

**Topics**
+ [CreateAlertManagerAlerts](AMP-APIReference-CreateAlertManagerAlerts.md)
+ [DeleteAlertManagerSilence](AMP-APIReference-DeleteSilence.md)
+ [GetAlertManagerStatus](AMP-APIReference-GetAlertManagerStatus.md)
+ [GetAlertManagerSilence](AMP-APIReference-GetAlertManagerSilence.md)
+ [GetLabels](AMP-APIReference-GetLabels.md)
+ [GetMetricMetadata](AMP-APIReference-GetMetricMetadata.md)
+ [GetSeries](AMP-APIReference-GetSeries.md)
+ [ListAlerts](AMP-APIReference-ListAlerts.md)
+ [ListAlertManagerAlerts](AMP-APIReference-ListAlertManagerAlerts.md)
+ [ListAlertManagerAlertGroups](AMP-APIReference-ListAlertManagerAlertGroups.md)
+ [ListAlertManagerReceivers](AMP-APIReference-ListAlertManagerReceivers.md)
+ [ListAlertManagerSilences](AMP-APIReference-ListAlertManagerSilences.md)
+ [ListRules](AMP-APIReference-ListRules.md)
+ [PutAlertManagerSilences](AMP-APIReference-PutAlertManagerSilences.md)
+ [QueryMetrics](AMP-APIReference-QueryMetrics.md)
+ [RemoteWrite](AMP-APIReference-RemoteWrite.md)

# CreateAlertManagerAlerts
<a name="AMP-APIReference-CreateAlertManagerAlerts"></a>

`CreateAlertManagerAlerts` 操作在工作区中创建警报。

有效的 HTTP 动词：  
`POST`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/alerts`

URL 查询参数：  
`alerts` 对象数组，其中每个对象代表一个警报。以下是警报对象的示例。  

```
[
  {
    "startsAt": "2021-09-24T17:14:04.995Z",
    "endsAt": "2021-09-24T17:14:04.995Z",
    "annotations": {
      "additionalProp1": "string",
      "additionalProp2": "string",
      "additionalProp3": "string"
    },
    "labels": {
      "additionalProp1": "string",
      "additionalProp2": "string",
      "additionalProp3": "string"
    },
    "generatorURL": "string"
  }
]
```

**示例请求**

```
POST /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/alerts HTTP/1.1
Content-Length: 203, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0

[
  {
    "labels": {
      "alertname": "test-alert"
    },
    "annotations": {
      "summary": "this is a test alert used for demo purposes"
    },
    "generatorURL": "https://www.amazon.com/"
  }
]
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 0
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin
```

# DeleteAlertManagerSilence
<a name="AMP-APIReference-DeleteSilence"></a>

`DeleteSilence` 删除一个警报静默。

有效的 HTTP 动词：  
`DELETE`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/silence/silenceID`

URL 查询参数：无  


**示例请求**

```
DELETE /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/silence/d29d9df3-9125-4441-912c-70b05f86f973 HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 0
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin
```

# GetAlertManagerStatus
<a name="AMP-APIReference-GetAlertManagerStatus"></a>

`GetAlertManagerStatus` 检索有关警报管理器状态的信息。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/status`

URL 查询参数：无  


**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/status HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 941
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

{
    "cluster": null,
    "config": {
        "original": "global:\n  resolve_timeout: 5m\n  http_config:\n    follow_redirects: true\n  smtp_hello: localhost\n  smtp_require_tls: true\nroute:\n  receiver: sns-0\n  group_by:\n  - label\n  continue: false\nreceivers:\n- name: sns-0\n  sns_configs:\n  - send_resolved: false\n    http_config:\n      follow_redirects: true\n    sigv4: {}\n    topic_arn: arn:aws:sns:us-west-2:123456789012:test\n    subject: '{{ template \"sns.default.subject\" . }}'\n    message: '{{ template \"sns.default.message\" . }}'\n    workspace_arn: arn:aws:aps:us-west-2:123456789012:workspace/ws-58a6a446-5ec4-415b-9052-a449073bbd0a\ntemplates: []\n"
    },
    "uptime": null,
    "versionInfo": null
}
```

# GetAlertManagerSilence
<a name="AMP-APIReference-GetAlertManagerSilence"></a>

`GetAlertManagerSilence` 检索有关一个警报静默的信息。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/silence/silenceID`

URL 查询参数：无  


**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/silence/d29d9df3-9125-4441-912c-70b05f86f973 HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 310
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

{
    "id": "d29d9df3-9125-4441-912c-70b05f86f973",
    "status": {
        "state": "active"
    },
    "updatedAt": "2021-10-22T19:32:11.763Z",
    "comment": "hello-world",
    "createdBy": "test-person",
    "endsAt": "2023-07-24T01:05:36.000Z",
    "matchers": [
        {
            "isEqual": true,
            "isRegex": true,
            "name": "job",
            "value": "hello"
        }
    ],
    "startsAt": "2021-10-22T19:32:11.763Z"
}
```

# GetLabels
<a name="AMP-APIReference-GetLabels"></a>

`GetLabels` 操作检索与时间序列关联的标签。

有效的 HTTP 动词：  
`GET`, `POST`

有效 URIs：  
`/workspaces/workspaceId/api/v1/labels`  
`/workspaces/workspaceId/api/v1/label/label-name/values` 此 URI 仅支持 GET 请求。

URL 查询参数：  
`match[]=<series_selector>` 重复的序列选择器参数，用于选择要从中读取标签名称的序列。可选。  
`start=<rfc3339 | unix_timestamp>` 开始时间戳。可选。  
`end=<rfc3339 | unix_timestamp>` 结束时间戳。可选。

**`/workspaces/workspaceId/api/v1/labels` 的示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/labels HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**`/workspaces/workspaceId/api/v1/labels` 的示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 1435
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

{
    "status": "success",
    "data": [
        "__name__",
        "access_mode",
        "address",
        "alertname",
        "alertstate",
        "apiservice",
        "app",
        "app_kubernetes_io_instance",
        "app_kubernetes_io_managed_by",
        "app_kubernetes_io_name",
        "area",
        "beta_kubernetes_io_arch",
        "beta_kubernetes_io_instance_type",
        "beta_kubernetes_io_os",
        "boot_id",
        "branch",
        "broadcast",
        "buildDate",
        ...
    ]
}
```

**`/workspaces/workspaceId/api/v1/label/label-name/values` 的示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/label/access_mode/values HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**`/workspaces/workspaceId/api/v1/label/label-name/values` 的示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 74
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

{
    "status": "success",
    "data": [
        "ReadWriteOnce"
    ]
}
```

# GetMetricMetadata
<a name="AMP-APIReference-GetMetricMetadata"></a>

`GetMetricMetadata` 操作检索有关当前正在从目标中抓取的指标的元数据。它不提供任何目标信息。

查询结果的数据部分由一个对象组成，其中每个键是一个指标名称，每个值是唯一的元数据对象的列表，在所有目标中针对该指标名称公开。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/api/v1/metadata`

URL 查询参数：  
`limit=<number>` 要返回的最大指标数。  
`metric=<string>` 要筛选元数据的指标名称。如果将其保留为空，则会检索所有指标元数据。

**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/metadata HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
Transfer-Encoding: chunked

{
    "status": "success",
    "data": {
        "aggregator_openapi_v2_regeneration_count": [
            {
                "type": "counter",
                "help": "[ALPHA] Counter of OpenAPI v2 spec regeneration count broken down by causing APIService name and reason.",
                "unit": ""
            }
        ],
        ...
    }
}
```

# GetSeries
<a name="AMP-APIReference-GetSeries"></a>

`GetSeries` 操作检索与特定标签集匹配的时间序列列表。

有效的 HTTP 动词：  
`GET`, `POST`

有效 URIs：  
`/workspaces/workspaceId/api/v1/series`

URL 查询参数：  
`match[]=<series_selector>` 重复的序列选择器参数，用于选择要返回的序列。必须至少提供一个 `match[]` 参数。  
`start=<rfc3339 | unix_timestamp>` 开始时间戳。可选  
`end=<rfc3339 | unix_timestamp>` 结束时间戳。可选

**示例请求**

```
POST /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/series --data-urlencode 'match[]=node_cpu_seconds_total{app="prometheus"}' --data-urlencode 'start=1634936400' --data-urlencode 'end=1634939100' HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
content-encoding: gzip

{
    "status": "success",
    "data": [
        {
            "__name__": "node_cpu_seconds_total",
            "app": "prometheus",
            "app_kubernetes_io_managed_by": "Helm",
            "chart": "prometheus-11.12.1",
            "cluster": "cluster-1",
            "component": "node-exporter",
            "cpu": "0",
            "heritage": "Helm",
            "instance": "10.0.100.36:9100",
            "job": "kubernetes-service-endpoints",
            "kubernetes_name": "servicesstackprometheuscf14a6d7-node-exporter",
            "kubernetes_namespace": "default",
            "kubernetes_node": "ip-10-0-100-36.us-west-2.compute.internal",
            "mode": "idle",
            "release": "servicesstackprometheuscf14a6d7"
        },
        {
            "__name__": "node_cpu_seconds_total",
            "app": "prometheus",
            "app_kubernetes_io_managed_by": "Helm",
            "chart": "prometheus-11.12.1",
            "cluster": "cluster-1",
            "component": "node-exporter",
            "cpu": "0",
            "heritage": "Helm",
            "instance": "10.0.100.36:9100",
            "job": "kubernetes-service-endpoints",
            "kubernetes_name": "servicesstackprometheuscf14a6d7-node-exporter",
            "kubernetes_namespace": "default",
            "kubernetes_node": "ip-10-0-100-36.us-west-2.compute.internal",
            "mode": "iowait",
            "release": "servicesstackprometheuscf14a6d7"
        },
        ...
    ]
}
```

# ListAlerts
<a name="AMP-APIReference-ListAlerts"></a>

`ListAlerts` 操作检索工作区中当前处于活动状态的警报。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/api/v1/alerts`

**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/alerts HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 386
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

{
  "status": "success",
  "data": {
    "alerts": [
      {
        "labels": {
          "alertname": "test-1.alert",
          "severity": "none"
        },
        "annotations": {
          "message": "message"
        },
        "state": "firing",
        "activeAt": "2020-12-01T19:37:25.429565909Z",
        "value": "1e+00"
      }
    ]
  },
  "errorType": "",
  "error": ""
}
```

# ListAlertManagerAlerts
<a name="AMP-APIReference-ListAlertManagerAlerts"></a>

`ListAlertManagerAlerts` 检索有关工作区警报管理器中当前触发的警报的信息。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/alerts`

**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/alerts HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 354
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

[
    {
        "annotations": {
            "summary": "this is a test alert used for demo purposes"
        },
        "endsAt": "2021-10-21T22:07:31.501Z",
        "fingerprint": "375eab7b59892505",
        "receivers": [
            {
                "name": "sns-0"
            }
        ],
        "startsAt": "2021-10-21T22:02:31.501Z",
        "status": {
            "inhibitedBy": [],
            "silencedBy": [],
            "state": "active"
        },
        "updatedAt": "2021-10-21T22:02:31.501Z",
        "labels": {
            "alertname": "test-alert"
        }
    }
]
```

# ListAlertManagerAlertGroups
<a name="AMP-APIReference-ListAlertManagerAlertGroups"></a>

`ListAlertManagerAlertGroups` 操作检索工作区警报管理器中配置的警报组列表。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/alerts/groups`

URL 查询参数：  
`active` 布尔值。如果为 true，则返回的列表包括活动警报。默认值为 true。可选  
`silenced` 布尔值。如果为 true，则返回的列表包括静默警报。默认值为 true。可选  
`inhibited` 布尔值。如果为 true，则返回的列表包括抑制的警报。默认值为 true。可选  
`filter` 字符串数组。用于筛选警报的匹配器列表。可选  
`receiver` 字符串。匹配接收方以筛选警报的正则表达式。可选

**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/alerts/groups HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 443
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

[
    {
        "alerts": [
            {
                "annotations": {
                    "summary": "this is a test alert used for demo purposes"
                },
                "endsAt": "2021-10-21T22:07:31.501Z",
                "fingerprint": "375eab7b59892505",
                "receivers": [
                    {
                        "name": "sns-0"
                    }
                ],
                "startsAt": "2021-10-21T22:02:31.501Z",
                "status": {
                    "inhibitedBy": [],
                    "silencedBy": [],
                    "state": "unprocessed"
                },
                "updatedAt": "2021-10-21T22:02:31.501Z",
                "generatorURL": "https://www.amazon.com/",
                "labels": {
                    "alertname": "test-alert"
                }
            }
        ],
        "labels": {},
        "receiver": {
            "name": "sns-0"
        }
    }
]
```

# ListAlertManagerReceivers
<a name="AMP-APIReference-ListAlertManagerReceivers"></a>

`ListAlertManagerReceivers` 操作检索有关警报管理器中配置的接收方的信息。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/receivers`

URL 查询参数：无  


**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/receivers HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 19
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

[
    {
        "name": "sns-0"
    }
]
```

# ListAlertManagerSilences
<a name="AMP-APIReference-ListAlertManagerSilences"></a>

`ListAlertManagerSilences` 操作检索有关在工作区中配置的警报静默的信息。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/silences`

**示例请求**

```
GET /workspaces/ws-58a6a446-5ec4-415b-9052-a449073bbd0a/alertmanager/api/v2/silences HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 312
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

[
    {
        "id": "d29d9df3-9125-4441-912c-70b05f86f973",
        "status": {
            "state": "active"
        },
        "updatedAt": "2021-10-22T19:32:11.763Z",
        "comment": "hello-world",
        "createdBy": "test-person",
        "endsAt": "2023-07-24T01:05:36.000Z",
        "matchers": [
            {
                "isEqual": true,
                "isRegex": true,
                "name": "job",
                "value": "hello"
            }
        ],
        "startsAt": "2021-10-22T19:32:11.763Z"
    }
]
```

# ListRules
<a name="AMP-APIReference-ListRules"></a>

`ListRules` 检索有关工作区中配置的规则的信息。

有效的 HTTP 动词：  
`GET`

有效 URIs：  
`/workspaces/workspaceId/api/v1/rules`

**示例请求**

```
GET /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/rules HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 423
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

{
    "status": "success",
    "data": {
        "groups": [
            {
                "name": "test-1.rules",
                "file": "test-rules",
                "rules": [
                    {
                        "name": "record:1",
                        "query": "sum(rate(node_cpu_seconds_total[10m:1m]))",
                        "labels": {},
                        "health": "ok",
                        "lastError": "",
                        "type": "recording",
                        "lastEvaluation": "2021-10-21T21:22:34.429565909Z",
                        "evaluationTime": 0.001005399
                    }
                ],
                "interval": 60,
                "lastEvaluation": "2021-10-21T21:22:34.429563992Z",
                "evaluationTime": 0.001010504
            }
        ]
    },
    "errorType": "",
    "error": ""
}
```

# PutAlertManagerSilences
<a name="AMP-APIReference-PutAlertManagerSilences"></a>

`PutAlertManagerSilences` 操作创建新的警报静默或更新现有的警报静默。

有效的 HTTP 动词：  
`POST`

有效 URIs：  
`/workspaces/workspaceId/alertmanager/api/v2/silences`

URL 查询参数：  
`silence` 表示静默的对象。格式如下：  

```
{
  "id": "string",
  "matchers": [
    {
      "name": "string",
      "value": "string",
      "isRegex": Boolean,
      "isEqual": Boolean
    }
  ],
  "startsAt": "timestamp",
  "endsAt": "timestamp",
  "createdBy": "string",
  "comment": "string"
}
```

**示例请求**

```
POST /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/alertmanager/api/v2/silences HTTP/1.1
Content-Length: 281, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0

{
   "matchers":[
      {
         "name":"job",
         "value":"up",
         "isRegex":false,
         "isEqual":true
      }
   ],
   "startsAt":"2020-07-23T01:05:36+00:00",
   "endsAt":"2023-07-24T01:05:36+00:00",
   "createdBy":"test-person",
   "comment":"test silence"
}
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 53
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin

{
    "silenceID": "512860da-74f3-43c9-8833-cec026542b32"
}
```

# QueryMetrics
<a name="AMP-APIReference-QueryMetrics"></a>

`QueryMetrics` 操作评估单个时间点或一段时间内的即时查询。

有效的 HTTP 动词：  
`GET`, `POST`

有效 URIs：  
`/workspaces/workspaceId/api/v1/query` 此 URI 评估单个时间点的即时查询。  
`/workspaces/workspaceId/api/v1/query_range` 此 URI 评估一段时间内的即时查询。

URL 查询参数：  
`query=<string>` Prometheus 表达式查询字符串。在 `query` 和 `query_range` 中使用。  
`time=<rfc3339 | unix_timestamp>`（可选）如果您对单个时间点的即时查询使用 `query`，则为评估时间戳。  
`timeout=<duration>`（可选）评估超时。默认为以 `-query.timeout` 标志的值为上限。在 `query` 和 `query_range` 中使用。  
`start=<rfc3339 | unix_timestamp>` 如果您使用 `query_range` 查询一段时间范围，则为开始时间戳。  
`end=<rfc3339 | unix_timestamp>` 如果您使用 `query_range` 查询一段时间范围，则为结束时间戳。  
`step=<duration | float>` `duration` 格式的查询解析步长，或者是 `float` 秒数。仅在您使用 `query_range` 查询一段时间范围时使用，并且对于此类查询是必需的。  
`max_samples_processed_warning_threshold=<integer>`（可选）为已处理的查询样本（QSP）设置警告阈值。当查询达到此阈值时，将在 API 响应中返回一条警告消息。  
`max_samples_processed_error_threshold=<integer>>`（可选）为已处理的查询样本（QSP）设置错误阈值。超过此阈值的查询将被拒绝并显示错误，并且不收费。用于防止过高的查询成本。

**Duration**

与 Prometheus 兼容的 API 中的 `duration` 是一个数值，后面紧跟以下单位之一：
+ `ms` 毫秒
+ `s` 秒
+ `m` 分钟
+ `h` 小时
+ `d` 天，假设一天始终是 24 小时
+ `w` 周，假设一周总始终是 7 天
+ `y` 年，假设一年始终是 365 天

**示例请求**

```
POST /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/query?query=sum(node_cpu_seconds_total) HTTP/1.1
Content-Length: 0, 
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Grafana/8.1.0
```

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length: 132
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
content-encoding: gzip

{
    "status": "success",
    "data": {
        "resultType": "vector",
        "result": [
            {
                "metric": {},
                "value": [
                    1634937046.322,
                    "252590622.81000024"
                ]
            }
        ]
    }
}
```

# RemoteWrite
<a name="AMP-APIReference-RemoteWrite"></a>

`RemoteWrite` 操作以标准格式将指标从 Prometheus 服务器写入远程 URL。通常，您将使用现有客户端（例如 Prometheus 服务器）来调用此操作。

有效的 HTTP 动词：  
`POST`

有效 URIs：  
`/workspaces/workspaceId/api/v1/remote_write`

URL 查询参数：  
无

`RemoteWrite` 摄取率为每秒 7 万个样本，摄入突增大小为 100 万个样本。

**示例请求**

```
POST /workspaces/ws-b226cc2a-a446-46a9-933a-ac50479a5568/api/v1/remote_write --data-binary "@real-dataset.sz" HTTP/1.1
Authorization: AUTHPARAMS
X-Amz-Date: 20201201T193725Z
User-Agent: Prometheus/2.20.1
Content-Type: application/x-protobuf
Content-Encoding: snappy
X-Prometheus-Remote-Write-Version: 0.1.0

body
```

**注意**  
有关请求正文语法，请参阅 [ https://github.com/prometheus/prometheus/blob/1c624c58ca934f618be737b4995e22051f5724c1/prompb/remote.pb.go](https://github.com/prometheus/prometheus/blob/1c624c58ca934f618be737b4995e22051f5724c1/prompb/remote.pb.go#L64) \$1L64 上的协议缓冲区定义。

**示例响应**

```
HTTP/1.1 200 OK
x-amzn-RequestId: 12345678-abcd-4442-b8c5-262b45e9b535
Content-Length:0
Connection: keep-alive
Date: Tue, 01 Dec 2020 19:37:25 GMT
Content-Type: application/json
Server: amazon
vary: Origin
```