Apigee Edge のドキュメントを表示しています。
Apigee X のドキュメントに移動。 情報
以下のセクションでは、API を使用してアラートを管理する方法について説明します。
Alerts API の詳細については、Alerts API をご覧ください。
API を使用してアラートと通知を設定する
アラートと通知を設定するには、POST リクエストをリソース https://apimonitoring.enterprise.apigee.com/alerts に対して発行します。
次のセクションでは、API を使用したアラートと通知の設定の例を紹介します。
- API を使用して API プロキシの 5xx ステータス コードのアラートを設定する
- API を使用して API プロキシの p95 レイテンシ アラートを設定する
- API を使用してすべての API プロキシの 404(アプリケーションが見つかりません)ステータス コードのアラートを設定する
- API を使用して API の API プロキシ カウントのアラートを設定する
- API を使用してターゲット サービスのエラーレートのアラートを設定する
- API を使用して Service Callout ポリシーのエラーレートのアラートを設定する
- API を使用して API の障害コードのアラートを設定する
API を使用して、API プロキシの 5xx ステータス コード アラートを設定する
次の例は、いずれかのリージョンの本番環境の hotels API プロキシにおいて、5xx ステータス コードの発生率が、10 分間で 100 トランザクション/秒(TPS)を超えたときにトリガーされるアラートの設定方法を示しています。アラートがトリガーされると、指定したメールアドレスに通知が送信されます。
curl 'https://apimonitoring.enterprise.apigee.com/alerts' \
-X POST \
-H 'Accept: application/json, text/plain, */*' -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"organization":"myorg",
"name":"5xx Alert",
"description":"My 5xx alert",
"environment":"prod",
"enabled":true,
"conditions":[
{
"description":"",
"dimensions":{
"org":"myorg",
"env":"prod",
"proxy":"hotels",
"region":"ANY",
"statusCode":"5xx"
},
"metric":"tps",
"threshold":100,
"durationSeconds":600,
"comparator":">"
}
],
"notifications":[{
"channel":"email",
"destination":"ops@acme.com"
}],
"playbook":"http://acme.com/myplaybook.html",
"throttleIntervalSeconds":3600,
"reportEnabled":true
}'
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
API を使用して、API プロキシの 95 パーセンタイル レイテンシ アラートを設定する
次の例は、いずれかのリージョンの本番環境の hotels API プロキシにおいて、95 パーセンタイルのレスポンス レイテンシの合計が、5 分間で 100 ms を超えた場合にトリガーされるアラートの設定方法を示しています。
アラートがトリガーされる場合は、指定された Webhook に通知が送信されます。
curl 'https://apimonitoring.enterprise.apigee.com/alerts' \
-X POST \
-H 'Accept: application/json, text/plain, */*' -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"organization":"myorg",
"name":"My Alert",
"description":"My first alert",
"environment":"prod",
"enabled":true,
"conditions":[
{
"description":"",
"dimensions":{
"org":"myorg",
"env":"prod",
"proxy" : "hotels",
"region":"ANY",
"percentile":"95"
},
"metric":"totalLatency",
"threshold":100,
"durationSeconds":300,
"comparator":">"
}
],
"notifications":[{ "channel":"webhook", "destination":"https://apigee.com/test-webhook"}],
"playbook":"http://acme.com/myplaybook.html",
"throttleIntervalSeconds":3600,
"reportEnabled":true
}'
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
API を使用して、すべての API プロキシの 404(アプリケーションが見つかりません)ステータス コードのアラートを設定する
次の例は、いずれかのリージョンの本番環境のすべての API プロキシにおいて、HTTP 404 ステータス コードの発生率が、5 分間で 10% を超えたときにトリガーされるアラートの設定方法を示しています。
アラートがトリガーされると、指定した Slack チャネルに通知が送信されます。
curl 'https://apimonitoring.enterprise.apigee.com/alerts' \
-X POST \
-H 'Accept: application/json, text/plain, */*' -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"organization":"myorg",
"name":"404 Application Not Found Alert",
"description":"My 404 alert",
"environment":"prod",
"enabled":true,
"conditions":[
{
"description":"",
"dimensions":{"org":"myorg",
"env":"prod",
"proxy":"ALL",
"region":"ANY",
"statusCode":"404"},
"metric":"rate",
"threshold":0.05,
"durationSeconds":300,
"comparator":">"
}],
"notifications":[{ "channel":"slack", "destination":"https://hooks.slack.com/services/T00000000/B00000000/XXXXX"}],
"playbook":"http://acme.com/myplaybook.html",
"throttleIntervalSeconds":3600,
"reportEnabled":true
}'
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
API を使用して、API の API プロキシ カウントのアラートを設定する
次の例は、いずれかのリージョンで API の 5xx コードカウントが 5 分間に 200 を超えるとトリガーされるアラートの設定方法を示しています。
この例では、API は、クリティカルな API プロキシのコレクション(UUID aeff4394-86b7-11e8-83d7-42010a840040)にキャプチャされます。コレクションの UUID を取得するには、API を使用してすべてのコレクションを表示するをご覧ください。
curl 'https://apimonitoring.enterprise.apigee.com/alerts' \
-X POST \
-H 'Accept: application/json, text/plain, */*' -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"organization":"myorg",
"name":"Proxy Count Alert",
"description":"My proxy count alert",
"environment":"prod",
"enabled":true,
"conditions":[
{
"description":"",
"dimensions":{
"collection":"aeff4394-86b7-11e8-83d7-42010a840040",
"org":"myorg",
"env":"prod",
"proxy" : "ANY",
"region":"ANY",
"statusCode":"5xx"
},
"metric":"count",
"threshold":200,
"durationSeconds":300,
"comparator":">"
}
],
"notifications":[{
"channel":"email",
"destination":"ops@acme.com"
}],
"playbook":"http://acme.com/myplaybook.html",
"throttleIntervalSeconds":3600,
"reportEnabled":true
}'
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
API を使用して、ターゲット サービスのエラー率のアラートを設定する
以下は、いずれかのリージョンでターゲット サービスにおいて、コード 500 の発生率が 1 時間で 10% を超えるとトリガーされるアラートの設定方法の例を示しています。
この例で、ターゲット サービスは、クリティカルなターゲットのコレクション(UUID aeff4394-86b7-11e8-83d7-42010a840040)にキャプチャされます。コレクションの UUID を取得するには、API を使用してすべてのコレクションを表示するをご覧ください。
curl 'https://apimonitoring.enterprise.apigee.com/alerts' \
-X POST \
-H 'Accept: application/json, text/plain, */*' -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"organization":"myorg",
"name":"Error rate Alert",
"description":"My error rate alert",
"environment":"prod",
"enabled":true,
"conditions":[
{
"description":"",
"dimensions":{
"collection":"aeff4394-86b7-11e8-83d7-42010a840040",
"org":"myorg",
"env":"prod",
"proxy" : "ANY",
"region":"ANY",
"statusCode":"500"
},
"metric":"rate",
"threshold":0.1,
"durationSeconds":3600,
"comparator":">"
}
],
"notifications":[{
"channel":"email",
"destination":"ops@acme.com"
}],
"playbook":"http://acme.com/myplaybook.html",
"throttleIntervalSeconds":3600,
"reportEnabled":true
}'
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
API を使用して Service Callout ポリシーのエラー率のアラートを設定する
次の例は、任意のリージョンで ServiceCallout ポリシーによって指定されたサービスにおいて、コード 500 が 1 時間で 10% を超えるレートで発生する場合にトリガーされるアラートを設定する方法を示しています。
curl 'https://apimonitoring.enterprise.apigee.com/alerts' \
-X POST \
-H 'Accept: application/json, text/plain, */*' -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"organization":"myorg",
"name":"Error rate Alert",
"description":"My error rate alert",
"environment":"prod",
"enabled":true,
"conditions":[
{
"description":"",
"dimensions":{
"target": "sc://docstore-api",
"org":"myorg",
"env":"prod",
"proxy" : "ANY",
"region":"ANY",
"statusCode":"500"
},
"metric":"rate",
"threshold":0.1,
"durationSeconds":3600,
"comparator":">"
}
],
"notifications":[{
"channel":"email",
"destination":"ops@acme.com"
}],
"playbook":"http://acme.com/myplaybook.html",
"throttleIntervalSeconds":3600,
"reportEnabled":true
}'
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
API を使用してポリシーの障害コードのアラートを設定する
次の例は、以下の条件が 1 つでも満たされるとトリガーされるアラートの設定方法を示しています。
- いずれかのリージョンの本番環境の API で
SpikeArrestViolation障害コードのカウントが 5 分間で 10 を超えた場合。 - 任意のリージョンの本番環境の API で、すべての API プロトコル障害コードのカウントが 5 分間で 3% を超えている。
この例では、API は、クリティカルな API プロキシのコレクション(UUID aeff4394-86b7-11e8-83d7-42010a840040)にキャプチャされます。コレクションの UUID を取得するには、API を使用してすべてのコレクションを表示するをご覧ください。
アラートがトリガーされると、指定した PagerDuty コードに通知が送信されます。
curl 'https://apimonitoring.enterprise.apigee.com/alerts' \
-X POST \
-H 'Accept: application/json, text/plain, */*' -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{
"organization":"myorg",
"name":"My Fault Code Alert",
"description":"My fault code alert",
"environment":"prod",
"enabled":true,
"conditions":[
{
"description":"",
"dimensions": {
"collection":"aeff4394-86b7-11e8-83d7-42010a840040",
"org":"myorg",
"env":"prod",
"proxy":"ANY",
"region":"ANY",
"faultCodeCategory":"Traffic Mgmt Policy",
"faultCodeSubCategory":"Spike Arrest",
"faultCodeName":"SpikeArrest Violation"
},
"metric":"count,
"threshold":10,
"durationSeconds":300,
"comparator":">"
},
{
"description":"",
"dimensions": {
"collection":"aeff4394-86b7-11e8-83d7-42010a840040",
"org":"myorg",
"env":"prod",
"proxy":"ANY",
"region":"ANY",
"faultCodeCategory":"API Protocol",
"faultCodeSubCategory":"ALL"
},
"metric":"rate",
"threshold":0.03,
"durationSeconds":300,
"comparator":">"
}
],
"notifications":[{ "channel":"pagerduty", "destination":"abcd1234efgh56789"}],
"playbook":"http://acme.com/myplaybook.html",
"throttleIntervalSeconds":3600,
"reportEnabled":true
}'
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
アラートと通知を表示する
次のセクションでは、API を使用してアラートの定義とトリガーされたアラートに関する情報を表示する例を紹介します。
組織のすべてのアラート定義を表示する
すべてのアラートと通知の定義を表示するには、GET リクエストを API https://apimonitoring.enterprise.apigee.com/alerts に発行します。
org クエリ パラメータを使用して、組織の名前を渡す必要があります。
次に例を示します。
curl 'https://apimonitoring.enterprise.apigee.com/alerts?org=myorg'
-X GET
-H 'Accept: application/json, text/plain, */*'
-H "Authorization: Bearer $ACCESS_TOKEN"
レスポンスの uuid 項目にアラートの UUID が表示されます。この UUID は、アラート定義に固有の情報を確認するための呼び出しに必要になります。レスポンスの例を次に示します。
[ { "uuid": "4fa49a87-3463023ea7c4", "name": "PublicAPI latency alert", "enabled": true, "description": "Public API Latency alerts, 90th %ile > 6secs for 5 minute window trigger this alert", "conditions": [ { "uuid": "4fa49a87-3463023ea7c4", "description": "", "dimensions": { "env": "prod", "org": "myorg", "percentile": "90", "proxy": "PublicAPI", "region": "ANY" }, "metric": "totalLatency", "threshold": 6000, "durationSeconds": 300, "comparator": ">", "updatedBy": "me@foo.com" } ], "playbook": "PublicAPI Latency alert, setup to go off when 90th %ile is > 4 secs for 5 minute window", "throttleIntervalSeconds": 3600, "self": "/alerts/4fa49a87-3463023ea7c4", "feed": "/o/myorg/events/4fa49a87-3463023ea7c4", "organization": "myorg", "environment": "prod", "notifications": [ { "channel": "email", "destination": "me@foo.com" } ], "updatedAt": "2018-07-19T18:19:31.654738Z", "updatedBy": "me@foo.com" }, { "uuid": "ef1a5249-345ed3023ea7c4", "name": "Minty API Latency alert", "enabled": true, "description": "Minty API Latency alerts, 90th %ile > 6secs for 5 minute window trigger this alert", "conditions": [ { "uuid": "ef1a5249-345ed3023ea7c4", "description": "", "dimensions": { "env": "prod", "org": "myorg", "percentile": "90", "proxy": "minty", "region": "ANY" }, "metric": "totalLatency", "threshold": 6000, "durationSeconds": 300, "comparator": ">", "updatedBy": "me@foo.com" } ], "playbook": "Minty API", "throttleIntervalSeconds": 3600, "self": "/alerts/ef1a5249-345ed3023ea7c4", "feed": "/o/myorg/events/ef1a5249-345ed3023ea7c4", "organization": "myorg", "environment": "prod", "notifications": [ { "channel": "email", "destination": "me@foo.com" } ], "updatedAt": "2018-07-19T18:19:33.22479Z", "updatedBy": "me@foo.com" }, ... ]
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
特定のアラート定義を表示する
特定のアラート定義を表示するには、リソース https://apimonitoring.enterprise.apigee.com/alerts/alert_uuid に GET リクエストを発行します。ここで、alert_uuid はアラート定義の UUID を表します。 UUID は、アラートを作成するときに取得するか、前のセクションに示されている API 呼び出しを使用して、すべてのアラートとそれらに関連する UUID の一覧を表示して取得します。
次に例を示します。
curl 'https://apimonitoring.enterprise.apigee.com/alerts/4fa49a87-3463023ea7c4'
-X GET
-H 'Accept: application/json, text/plain, */*'
-H "Authorization: Bearer $ACCESS_TOKEN"
レスポンスの例を次に示します。
{ "uuid": "4fa49a87-3463023ea7c4", "name": "PublicAPI latency alert", "enabled": true, "description": "Public API Latency alerts, 90th %ile > 6secs for 5 minute window trigger this alert", "conditions": [ { "uuid": "4fa49a87-3463023ea7c4", "description": "", "dimensions": { "env": "prod", "org": "myorg", "percentile": "90", "proxy": "PublicAPI", "region": "ANY" }, "metric": "totalLatency", "threshold": 6000, "durationSeconds": 300, "comparator": ">", "updatedBy": "me@foo.com" } ], "playbook": "PublicAPI Latency alert, setup to go off when 90th %ile is > 4 secs for 5 minute window", "throttleIntervalSeconds": 3600, "self": "/alerts/4fa49a87-3463023ea7c4", "feed": "/o/myorg/events/4fa49a87-3463023ea7c4", "organization": "myorg", "environment": "prod", "notifications": [ { "channel": "email", "destination": "me@foo.com" } ], "updatedAt": "2018-07-19T18:19:31.654738Z", "updatedBy": "me@foo.com" }
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
組織に対してトリガーされたすべてのアラートの履歴を表示する
組織に対してトリガーされたすべてのアラートを表示するには、GET リクエストをリソース https://apimonitoring.enterprise.apigee.com/metrics/alerthistory に対して発行します。
org クエリ パラメータを使用して、組織の名前を渡す必要があります。オプションで、トリガーされたアラートを検索する期間を指定できます。デフォルトでは、過去 1 時間にトリガーされたすべてのアラートが返されます。
次に例を示します。
curl 'https://apimonitoring.enterprise.apigee.com/metrics/alerthistory?org=myorg'
-X GET
-H 'Accept: application/json, text/plain, */*'
-H "Authorization: Bearer $ACCESS_TOKEN"
レスポンスには、リクエストした期間にトリガーされたすべてのアラートの配列が含まれます。レスポンスの本文では、id 項目にトリガーされたアラートの UUID が指定され、shared_id 項目にトリガーされたアラートに関連付けられているアラート定義の UUID が指定されます。
レスポンスの例を次に示します。
[ { "id": "80cbe560-f6e0-475c6f7ed2d", "shared_id": "4fa49a87-3463023ea7c4", "organization": "myorg", "environment": "prod", "name": "PublicAPI latency alert", "type": "Alert", "source": "null/current", "raw_payload": "{\"reportUUID\":\"\",\"reportEnabled\":false,\"organization\":\"myorg\",\"name\":\"emgmt-api 404\",\"self\":\"/alerts/4fa49a87-3463023ea7c4\",\"description\":\"go/apigee-extensions-playbook\",\"conditions\":[ {\"comparator\":\">\",\"metric\":\"rate\",\"durationSeconds\":300,\"name\":\"PublicAPI latency alert\",\"description\":\"\",\"threshold\":0.05,\"dimensions\":{\"proxy\":\"emgmt-api\",\"org\":\"myorg\",\"env\":\"prod\",\"region\":\"any\",\"statusCode\":\"404\"}}],\"uuid\":\"4fa49a87-3463023ea7c4\",\"playbook\":\"go/apigee-extensions-playbook\"}", "time": "2019-03-25T15:30:18Z" }, { "id": "8131d740-6680-45b9c72c3", "shared_id": "1a64885b-f9-42010a850039", "organization": "apigee-pinpoint", "environment": "prod", "name": "Demo 5xx alert", "type": "Alert", "source": "null/current", "raw_payload": "{\"reportUUID\":\"\",\"reportEnabled\":false,\"organization\":\"myorg\",\"name\":\"Demo 5xx alert\",\"self\":\"/alerts/1a64885b-f9-42010a850039\",\"description\":\"Demo 5xx alert\",\"conditions\":[ {\"comparator\":\">\",\"metric\":\"rate\",\"durationSeconds\":300,\"name\":\"Demo 5xx alert\",\"description\":\"\",\"threshold\":0.4,\"dimensions\":{\"proxy\":\"ALL\",\"org\":\"myorg\",\"env\":\"prod\",\"region\":\"any\",\"statusCode\":\"5xx\"}}],\"uuid\":\"1a64885b-f9-42010a850039\",\"playbook\":\"Recommended Playbook\"}", "time": "2019-03-25T15:57:30Z" }, ... ]
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。
特定のアラートの履歴を表示する
特定のアラート定義でトリガーされたアラートの履歴を表示するには、GET リクエストをリソース https://apimonitoring.enterprise.apigee.com/metrics/alerthistory に対して発行します。
org クエリ パラメータとアラート定義の UUID を使用して、組織の名前を渡す必要があります。オプションで、アラートを検索する期間を指定できます。デフォルトでは、過去 1 時間にトリガーされたすべてのアラートが返されます。
アラート定義の UUID は、アラート定義を作成したときに前のセクションで説明したアラート履歴から取得できます。また、すべてのアラート定義を表示するに示す API 呼び出しを使用して取得できます。
例:
curl 'https://apimonitoring.enterprise.apigee.com/metrics/alerthistory?org=myorg&alertId=4fa49a87-3463023ea7c4'
-X GET
-H 'Accept: application/json, text/plain, */*'
-H "Authorization: Bearer $ACCESS_TOKEN"
レスポンスには、リクエストされた期間内に特定のアラート定義 UUID に対してトリガーされたすべてのアラートの配列が含まれます。レスポンスの本文では、id フィールドはトリガーされたアラートの UUID を指定し、shared_id フィールドはトリガーされたアラートに関連付けられたアラート定義の UUID を指定します。
レスポンスの例を次に示します。
[ { "id": "80cbe560-f6e0-475c6f7ed2d", "shared_id": "4fa49a87-3463023ea7c4", "organization": "myorg", "environment": "prod", "name": "PublicAPI latency alert", "type": "Alert", "source": "null/current", "raw_payload": "{\"reportUUID\":\"\",\"reportEnabled\":false,\"organization\":\"myorg\",\"name\":\"emgmt-api 404\",\"self\":\"/alerts/4fa49a87-3463023ea7c4\",\"description\":\"go/apigee-extensions-playbook\",\"conditions\":[ {\"comparator\":\">\",\"metric\":\"rate\",\"durationSeconds\":300,\"name\":\"PublicAPI latency alert\",\"description\":\"\",\"threshold\":0.05,\"dimensions\":{\"proxy\":\"emgmt-api\",\"org\":\"myorg\",\"env\":\"prod\",\"region\":\"any\",\"statusCode\":\"404\"}}],\"uuid\":\"4fa49a87-3463023ea7c4\",\"playbook\":\"go/apigee-extensions-playbook\"}", "time": "2019-03-25T15:30:18Z" }, { "id": "9fc442d5-d607-40ef118c4e7", "shared_id": "4fa49a87-3463023ea7c4", "organization": "myorg", "environment": "prod", "name": "PublicAPI latency alert", "type": "Alert", "source": "null/current", "raw_payload": "{\"reportUUID\":\"\",\"reportEnabled\":false,\"organization\":\"myorg\",\"name\":\"emgmt-api 404\",\"self\":\"/alerts/4fa49a87-3463023ea7c4\",\"description\":\"go/apigee-extensions-playbook\",\"conditions\":[{\"comparator\":\">\",\"metric\":\"rate\",\"durationSeconds\":300,\"name\":\"PublicAPI latency alert\",\"description\":\"\",\"threshold\":0.05,\"dimensions\":{\"proxy\":\"emgmt-api\",\"org\":\"myorg\",\"env\":\"prod\",\"region\":\"any\",\"statusCode\":\"404\"}}],\"uuid\":\"4fa49a87-3463023ea7c4\",\"playbook\":\"go/apigee-extensions-playbook\"}", "time": "2019-03-25T15:17:55Z" }, ... ]
OAuth 2.0 アクセス トークンの取得の説明に従って、$ACCESS_TOKEN を OAuth 2.0 アクセス トークンに設定します。
この例で使用されている cURL オプションについては、cURL を使用するをご覧ください。