

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

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

Amazon Managed Service for Prometheus 提供兩種 APIs：

1. **Amazon Managed Service for Prometheus APIs** – 這些 APIs 可讓您建立和管理 Amazon Managed Service for Prometheus 工作區，包括工作區、抓取器、警示管理員定義、規則群組命名空間和記錄的操作。您可以使用適用於各種程式設計語言 AWS SDKs 來與這些 APIs互動。

1. **Prometheus 相容 APIs** – Amazon Managed Service for Prometheus 支援與 Prometheus 相容的 HTTP APIs。這些 APIs可讓您建置自訂應用程式、自動化工作流程、與其他 服務或工具整合，以及使用 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)
+ [

# 與 Prometheu 相容的 API
](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 操作。這包括工作區、抓取器、警示管理員定義、規則群組命名空間和記錄的 APIs。

如需 Amazon Managed Service for Prometheus APIs的詳細資訊，請參閱 [Amazon Managed Service for Prometheus API 參考](https://docs.aws.amazon.com/prometheus/latest/APIReference/Welcome.html)。

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

AWS 軟體開發套件 SDKs) 適用於許多熱門的程式設計語言。每個 SDK 都提供 API、程式碼範例和文件，可讓開發人員更輕鬆地以他們偏好的語言建置 AWS 應用程式。如需依語言列出的 SDKs 和工具清單，請參閱《 *開發人員中心*》中的 AWS [建置工具 AWS](https://aws.amazon.com/developer/tools/)。

**開發套件版本**  
我們建議您使用在專案中使用的軟體 AWS 開發套件和任何其他SDKs的最新組建，並將軟體SDKs保持在最新狀態。 AWS 開發套件為您提供最新的功能和功能，以及安全性更新。

# 與 Prometheu 相容的 API
<a name="AMP-APIReference-Prometheus-Compatible-Apis"></a>

Amazon Managed Service for Prometheus 支援與 Prometheus 相容的 API相容的 API。

 如需使用 Prometheus 相容 APIs的詳細資訊，請參閱 [使用與 Prometheus 相容的 API 查詢](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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

有效 URI：  
`/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`

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

URL 查詢參數：  
無

`RemoteWrite` 擷取速率為每秒 70,000 個樣本，擷取突發大小為 1,000,000 個樣本。

**請求範例**

```
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\$1L64](https://github.com/prometheus/prometheus/blob/1c624c58ca934f618be737b4995e22051f5724c1/prompb/remote.pb.go#L64) 的協議緩衝區定義。

**回應範例**

```
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
```