Cloud-Native API Gateway / AI Gateway / API Gateway Instance Inspection
Scenario Description
Perform health inspection on Alibaba Cloud gateway instances, retrieve monitoring metric data, and generate inspection reports.
Architecture: Cloud Monitor (CMS) + API Gateway (cloudapi) + Cloud-Native API Gateway / AI Gateway (apig)
Supported Product Types:
| Product Type |
Instance ID Format |
Query Command |
| Cloud-Native API Gateway |
gw-xxxxxxx |
aliyun apig list-gateways |
| AI Gateway |
gw-xxxxxxx |
aliyun apig list-gateways |
| API Gateway (Dedicated) |
apigateway-xx-xxxxxxx |
aliyun cloudapi describe-instances |
Note: API Gateway shared instances (VPC_SHARED) do not support inspection. Only dedicated instances (VPC_DEDICATED) are supported.
Installation
Pre-check: Aliyun CLI >= 3.3.3 required
Run aliyun version to verify >= 3.3.3. If not installed or version too low,
follow the upgrade/installation instructions below.
Upgrade / Install Aliyun CLI (choose one based on your platform):
- macOS (Homebrew):
brew install aliyun-cli # fresh install
brew upgrade aliyun-cli # upgrade existing
- Linux / macOS (binary):
curl -fsSL https://aliyuncli.alicdn.com/setup.sh | bash
- Windows (PowerShell):
Invoke-WebRequest -Uri "https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip" -OutFile "aliyun-cli.zip"
Expand-Archive -Path aliyun-cli.zip -DestinationPath C:\aliyun-cli
After upgrade, verify with aliyun version.
For more platforms and detailed instructions, see references/cli-installation-guide.md.
Pre-check: Aliyun CLI plugin update required
[MUST] run aliyun configure set --auto-plugin-install true to enable automatic plugin installation.
[MUST] run aliyun plugin update to ensure that any existing plugins are always up-to-date.
Observability (MUST follow for every aliyun command)
Upon loading this skill, generate a random session ID (32-char lowercase hex string) once
for the entire session. Use it as {session-id} below.
Rule: Every aliyun CLI command that calls a cloud API MUST include the --user-agent flag.
Local utility commands (e.g. configure, plugin, version) do not support this flag
and should be excluded.
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
Environment Variables
No additional environment variables required. Credentials are configured via aliyun configure.
Authentication
Pre-check: Alibaba Cloud Credentials Required
Security Rules:
- NEVER read, echo, or print AK/SK values (e.g.,
echo $ALIBABA_CLOUD_ACCESS_KEY_ID is FORBIDDEN)
- NEVER ask the user to input AK/SK directly in the conversation or command line
- NEVER use
aliyun configure set with literal credential values
- ONLY use
aliyun configure list to check credential status
aliyun configure list
Check the output for a valid profile (AK, STS, or OAuth identity).
If no valid profile exists, STOP here.
- Obtain credentials from Alibaba Cloud Console
- Configure credentials outside of this session (via
aliyun configure in terminal or environment variables in shell profile)
- Return and re-run after
aliyun configure list shows a valid profile
RAM Permission Policy
This skill only involves read-only operations and requires the following minimum RAM permissions:
| Product |
RAM Action |
Description |
| API Gateway |
apigateway:DescribeInstances |
List API Gateway instances |
| API Gateway |
apigateway:DescribeInstanceDropPacket |
View dropped packet count |
| API Gateway |
apigateway:DescribeInstanceDropConnections |
View dropped connection count |
| API Gateway |
apigateway:DescribeInstanceSlbConnect |
View concurrent connection count |
| API Gateway |
apigateway:DescribeInstanceTraffic |
View traffic information |
| API Gateway |
apigateway:DescribeInstanceQps |
View QPS data |
| Cloud-Native API Gateway / AI Gateway |
apig:ListGateways |
Query gateway list |
| Cloud Monitor |
cms:QueryMetricData |
Query monitoring data |
Full policy document: references/ram-policies.md
[MUST] Permission Failure Handling: When any command or API call fails due to permission errors at any point during execution, follow this process:
- Read
references/ram-policies.md to get the full list of permissions required by this SKILL
- Use
ram-permission-diagnose skill to guide the user through requesting the necessary permissions
- Pause and wait until the user confirms that the required permissions have been granted
Parameter Confirmation
IMPORTANT: Parameter Confirmation — Before executing any command or API call,
ALL user-customizable parameters (e.g., RegionId, instance names, CIDR blocks,
passwords, domain names, resource specifications, etc.) MUST be confirmed with the
user. Do NOT assume or use default values without explicit user approval.
| Parameter |
Required/Optional |
Description |
Default |
| Product Type |
Required |
Cloud-Native API Gateway / AI Gateway / API Gateway |
None |
| RegionId |
Required |
Region where the instance is located |
None |
| Instance ID |
Required |
Unique identifier of the gateway instance |
None |
| Time Range |
Optional |
Query time point or time range |
Current time |
Available Region Check:
Core Workflow
Step 1: Collect Required Information
Before starting queries, the following information must be confirmed (proactively ask the user if not provided). Using default configurations is prohibited:
- Cloud Product Type — Which cloud product the user wants to query.(Cloud-Native API Gateway / AI Gateway / API Gateway).
- Region (RegionId) — The region where the instance is located.
- Instance ID — The unique identifier of the instance.
- Time Range — The time point or time range for the query.
Step 2: Query Instance Information
[MUST] API Invocation Requirement:
The gateway list MUST be queried by calling the Apig ListGateways API via CLI plugin mode.
This is a mandatory step — skipping the gateway list query is NOT allowed.
[MUST] Plugin Mode Only:
All commands in this skill MUST be executed using CLI plugin mode. Traditional API format (PascalCase action names) is NOT allowed.
If the plugin is not installed, run aliyun plugin install --names apig to install it, then retry.
2.1 Cloud-Native API Gateway / AI Gateway
API Mapping: Product Apig | Action ListGateways | Version 2019-01-01
aliyun apig list-gateways --region ${region_id} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
Note: The gatewayType in the response indicates the instance type: API (Cloud-Native API Gateway), AI (AI Gateway)
2.2 API Gateway
aliyun cloudapi describe-instances --api-version 2016-07-14 --region ${region_id} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
Note: The InstanceType in the response indicates the instance type. Only VPC_DEDICATED (dedicated) instances are supported. VPC_SHARED shared instances do not support inspection.
Step 3: Retrieve Monitoring Metric Data
3.1 Cloud-Native API Gateway / AI Gateway
[MUST] API Invocation Requirement:
Monitoring metrics MUST be queried using the Cms DescribeMetricData API via CLI plugin mode
CRITICAL — PROHIBITED APIs:
- DO NOT USE
DescribeMetricList (aliyun cms describe-metric-list) — returns a different response format and is NOT accepted
- DO NOT USE
DescribeMetricMetaList (aliyun cms describe-metric-meta-list) — DO NOT call this API to discover or list available metrics
ALL metric names are already provided below. No metric discovery is needed:
- For Cloud-Native API Gateway instances: select metric names from the Supported Metrics for Cloud-Native API Gateway table below
- For AI Gateway instances: select metric names from the Supported Metrics for AI Gateway table below
- Use the exact
Metric Name values from the corresponding table directly as the --metric-name parameter
API Mapping: Product Cms | Action DescribeMetricData | Version 2019-01-01 | Namespace acs_cnapigateway
aliyun cms describe-metric-data \
--namespace acs_cnapigateway \
--region ${region} \
--api-version 2019-01-01 \
--metric-name ${metric-name} \
--period 60 \
--start-time ${start-time} \
--end-time ${end-time} \
--dimensions '[{"instanceId": "${instanceId}"}]' \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
Notes:
start-time / end-time use Unix millisecond timestamps
instanceId must be passed in dimensions
- MUST query ALL of the following metric categories: CPU Usage, Memory Usage, Connections, Network IO, Rate Limiting
- Only check CPU, memory, connections, network IO, rate limiting, and bandwidth
Supported Metrics for Cloud-Native API Gateway:
| Metric Name |
Display Name |
Dimensions |
Metric Period |
Unit |
| EnvoyClientActiveConnection |
Current active connections (gateway to client) |
userId,regionId,instanceId |
60300 |
count |
| EnvoyClientDestroyConnection |
Destroyed connections per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| EnvoyClientDestroySSL |
SSL handshake failures per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| EnvoyClientNewConnection |
New connections per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| EnvoyClientNewSSL |
SSL handshakes per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| EnvoyClientReuseSSL |
SSL handshake reuse per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| EnvoyCpuUsageRate |
Gateway CPU usage |
userId,instanceId |
60300 |
% |
| EnvoyFsReadBytes |
Disk read load |
userId,instanceId |
60300 |
B/s |
| EnvoyFsWriteBytes |
Disk write load |
userId,instanceId |
60300 |
B/s |
| EnvoyMemoryUsage |
Memory load |
userId,instanceId |
60300 |
MiB |
| EnvoyMemoryUsageRate |
Gateway memory usage |
userId,instanceId |
60300 |
% |
| EnvoyNetworkInBytes |
Inbound network IO load |
userId,instanceId |
60300 |
B/s |
| EnvoyNetworkOutBytes |
Outbound network IO load |
userId,instanceId |
60300 |
B/s |
| EnvoyRateLimitRequests |
Rate-limited requests |
userId,instanceId |
60300 |
count/s |
| EnvoyUpstreamActiveConnection |
Current active connections (gateway to backend) |
userId,instanceId |
60300 |
count |
| EnvoyUpstreamDestroyConnection |
Destroyed connections per second (gateway to backend) |
userId,instanceId |
60300 |
count/s |
| EnvoyUpstreamNewConnection |
New connections per second (gateway to backend) |
userId,instanceId |
60300 |
count/s |
| Ipv4EipRateIn |
Public IPv4 inbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| Ipv4EipRateOut |
Public IPv4 outbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| Ipv6GatewayRateIn |
Public IPv6 inbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| Ipv6GatewayRateOut |
Public IPv6 outbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| SlbInstanceTrafficRX |
Private network inbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| SlbInstanceTrafficTX |
Private network outbound bandwidth |
userId,instanceId |
60300 |
bit/s |
Supported Metrics for AI Gateway:
| Metric Name |
Display Name |
Dimensions |
Metric Period |
Unit |
| AIGatewayEnvoyClientActiveConnection |
Current active connections (gateway to client) |
userId,regionId,instanceId |
60300 |
count |
| AIGatewayEnvoyClientDestroyConnection |
Destroyed connections per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| AIGatewayEnvoyClientDestroySSL |
SSL handshake failures per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| AIGatewayEnvoyClientNewConnection |
New connections per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| AIGatewayEnvoyClientNewSSL |
SSL handshakes per second (gateway to client) |
userId,regionId,instanceId |
60300 |
count/s |
| AIGatewayEnvoyCpuUsageRate |
Gateway CPU usage |
userId,regionId,instanceId |
60300 |
% |
| AIGatewayEnvoyFsReadBytes |
Disk read load |
userId,regionId,instanceId |
60300 |
B/s |
| AIGatewayEnvoyFsWriteBytes |
Disk write load |
userId,regionId,instanceId |
60300 |
B/s |
| AIGatewayEnvoyMemoryUsage |
Memory load |
userId,regionId,instanceId |
60300 |
MiB |
| AIGatewayEnvoyMemoryUsageRate |
Gateway memory usage |
userId,regionId,instanceId |
60300 |
% |
| AIGatewayEnvoyNetworkInBytes |
Inbound network IO load |
userId,regionId,instanceId |
60300 |
B/s |
| AIGatewayEnvoyNetworkOutBytes |
Outbound network IO load |
userId,regionId,instanceId |
60300 |
B/s |
| AIGatewayEnvoyRateLimitRequests |
Rate-limited requests |
userId,regionId,instanceId |
60300 |
count/s |
| AIGatewayEnvoyUpstreamActiveConnection |
Current active connections (gateway to backend) |
userId,regionId,instanceId |
60300 |
count |
| AIGatewayEnvoyUpstreamDestroyConnection |
Destroyed connections per second (gateway to backend) |
userId,regionId,instanceId |
60300 |
count/s |
| AIGatewayEnvoyUpstreamNewConnection |
New connections per second (gateway to backend) |
userId,regionId,instanceId |
60300 |
count/s |
| Ipv4EipRateIn |
Public IPv4 inbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| Ipv4EipRateOut |
Public IPv4 outbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| Ipv6GatewayRateIn |
Public IPv6 inbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| Ipv6GatewayRateOut |
Public IPv6 outbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| SlbInstanceTrafficRX |
Private network inbound bandwidth |
userId,instanceId |
60300 |
bit/s |
| SlbInstanceTrafficTX |
Private network outbound bandwidth |
userId,instanceId |
60300 |
bit/s |
3.2 API Gateway Dedicated Instances
[MUST] API Invocation Requirement:
For API Gateway dedicated instances, you MUST use the CloudAPI dedicated APIs via CLI plugin mode to query monitoring data.
DO NOT use Cloud Monitor (CMS) for API Gateway dedicated instances. CMS is only for Cloud-Native API Gateway / AI Gateway (Step 3.1).
The following 5 API calls are ALL mandatory:
| # |
API |
Product |
Action |
Version |
Notes |
| 1 |
Dropped packets |
cloudapi |
DescribeInstanceDropPacket |
2016-07-14 |
|
| 2 |
Dropped connections |
cloudapi |
DescribeInstanceDropConnections |
2016-07-14 |
|
| 3 |
SLB connections |
cloudapi |
DescribeInstanceSlbConnect |
2016-07-14 |
|
| 4 |
Traffic |
cloudapi |
DescribeInstanceTraffic |
2016-07-14 |
Query RELEASE, PRE, TEST separately |
| 5 |
QPS |
cloudapi |
DescribeInstanceQps |
2016-07-14 |
Query RELEASE, PRE, TEST separately |
CRITICAL: Traffic and QPS must each be queried 3 times — once for each environment (RELEASE, PRE, TEST).
This means a total of 7 API calls (5 base APIs, but Traffic and QPS each × 3 environments).
Note: For API Gateway, skip 3.1 and execute this step directly. Time format uses ISO8601 UTC (YYYY-MM-DDThh:mm:ssZ)
# 1. Dropped packets
aliyun cloudapi describe-instance-drop-packet \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --sbc-name Maximum \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
# 2. Dropped connections
aliyun cloudapi describe-instance-drop-connections \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --sbc-name Maximum \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
# 3. SLB connections
aliyun cloudapi describe-instance-slb-connect \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --sbc-name Maximum \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
# 4. Traffic — MUST query RELEASE, PRE, and TEST environments separately (3 calls)
aliyun cloudapi describe-instance-traffic \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --stage-name RELEASE \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
aliyun cloudapi describe-instance-traffic \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --stage-name PRE \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
aliyun cloudapi describe-instance-traffic \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --stage-name TEST \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
# 5. QPS — MUST query RELEASE, PRE, and TEST environments separately (3 calls)
aliyun cloudapi describe-instance-qps \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --stage-name RELEASE \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
aliyun cloudapi describe-instance-qps \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --stage-name PRE \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
aliyun cloudapi describe-instance-qps \
--start-time ${start-time} --end-time ${end-time} \
--instance-id ${instanceId} --stage-name TEST \
--api-version 2016-07-14 --region ${region} \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
Step 4: Generate Inspection Report
4.1 Anomaly Check Rules
| Metric |
Normal |
Warning |
Critical |
| CPU Usage |
< 70% |
70%-85% |
> 85% |
| Memory Usage |
< 75% |
75%-90% |
> 90% |
| Connections |
< 70% of max |
70%-85% |
> 85% |
| Network IO |
< 70% of bandwidth |
70%-85% |
> 85% |
| Rate Limiting |
No triggers |
> 0 occurrences |
Continuously increasing |
Spike Detection: Alert when the increase within a period exceeds the threshold (CPU > 30%, Memory > 25%, Connections > 50%, Network IO > 40%)
4.2 Report Structure
The inspection report should include the following sections:
- Basic Information — Product type, instance ID, region, inspection time
- Inspection Results Overview — Table format showing the status of each metric
- Detailed Analysis — Peak values, trends, and analysis for each metric
- Risk Assessment — List of high/medium risk items
- Optimization Recommendations — Recommendations based on actual issues (omit if all metrics are normal)
- Conclusion — Summary of inspection results
Important: All data must come from actual API responses. Fabricating data is strictly prohibited.
Success Verification
For verification methods, see references/verification-method.md
Cleanup
This skill only involves read-only operations. No resource cleanup is required.
Command List
For the full command list, see references/related-commands.md
Best Practices
- Plugin Mode Only: All commands MUST be executed using
aliyun CLI plugin mode. Traditional API format (PascalCase action names) is NOT allowed. If a required plugin is not installed, run aliyun plugin install --names <plugin-name> to install it first.
- Confirm Parameters: All user-customizable parameters must be confirmed before execution
- Check Region: Ensure the region is within the available regions for the corresponding product
- Check Instance Type: API Gateway only supports dedicated instance inspection
- Time Format: Cloud Monitor uses millisecond timestamps; API Gateway uses ISO8601 UTC
- Data Accuracy: Report data must come from actual API responses
- Risk Classification: Strictly follow threshold standards for risk assessment
Reference Links
1---2name: alibabacloud-apigw-inspection3description: Perform instance inspection on Alibaba Cloud Cloud-Native API Gateway, AI Gateway, and API Gateway, and query Cloud Monitor metric data. Use when the user needs to view monitoring metrics of gateway instances (such as CPU usage, memory usage, connections, network IO, bandwidth, rate limiting, etc.), obtain metric data for a specific point in time or time range, or evaluate resource utilization. Trigger scenarios include: "check if the Cloud-Native API Gateway has enough resources", "view monitoring data of the AI Gateway instance", "inspect this API Gateway instance", "how is the gateway performing", "check if the gateway has any anomalies", "check gateway health status", etc.4---5
6# Cloud-Native API Gateway / AI Gateway / API Gateway Instance Inspection
7
8## Scenario Description
9
10Perform health inspection on Alibaba Cloud gateway instances, retrieve monitoring metric data, and generate inspection reports.
11
12**Architecture**: `Cloud Monitor (CMS) + API Gateway (cloudapi) + Cloud-Native API Gateway / AI Gateway (apig)`
13
14**Supported Product Types**:
15| Product Type | Instance ID Format | Query Command |
16|---------|-----------|----------|
17| Cloud-Native API Gateway | gw-xxxxxxx | `aliyun apig list-gateways` |
18| AI Gateway | gw-xxxxxxx | `aliyun apig list-gateways` |
19| API Gateway (Dedicated) | apigateway-xx-xxxxxxx | `aliyun cloudapi describe-instances` |
20
21> **Note**: API Gateway shared instances (VPC_SHARED) do not support inspection. Only dedicated instances (VPC_DEDICATED) are supported.
22
23---
24
25## Installation
26
27**Pre-check: Aliyun CLI >= 3.3.3 required**
28> Run `aliyun version` to verify >= 3.3.3. If not installed or version too low,
29> follow the upgrade/installation instructions below.
30
31**Upgrade / Install Aliyun CLI** (choose one based on your platform):
32
33- **macOS (Homebrew)**:
34 ```bash
35 brew install aliyun-cli # fresh install
36 brew upgrade aliyun-cli # upgrade existing
37 ```
38- **Linux / macOS (binary)**:
39 ```bash
40 curl -fsSL https://aliyuncli.alicdn.com/setup.sh | bash
41 ```
42- **Windows (PowerShell)**:
43 ```powershell
44 Invoke-WebRequest -Uri "https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip" -OutFile "aliyun-cli.zip"
45 Expand-Archive -Path aliyun-cli.zip -DestinationPath C:\aliyun-cli
46 ```
47
48After upgrade, verify with `aliyun version`.
49For more platforms and detailed instructions, see `references/cli-installation-guide.md`.
50
51**Pre-check: Aliyun CLI plugin update required**
52> [MUST] run `aliyun configure set --auto-plugin-install true` to enable automatic plugin installation.
53> [MUST] run `aliyun plugin update` to ensure that any existing plugins are always up-to-date.
54
55---
56
57## Observability (MUST follow for every aliyun command)
58
59Upon loading this skill, generate a random session ID (32-char lowercase hex string) once
60for the entire session. Use it as `{session-id}` below.
61
62**Rule: Every `aliyun` CLI command that calls a cloud API MUST include the `--user-agent` flag.**
63
64Local utility commands (e.g. `configure`, `plugin`, `version`) do not support this flag
65and should be excluded.
66
67```
68--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
69```
70
71---
72
73## Environment Variables
74
75No additional environment variables required. Credentials are configured via `aliyun configure`.
76
77---
78
79## Authentication
80
81> **Pre-check: Alibaba Cloud Credentials Required**
82>
83> **Security Rules:**
84> - **NEVER** read, echo, or print AK/SK values (e.g., `echo $ALIBABA_CLOUD_ACCESS_KEY_ID` is FORBIDDEN)
85> - **NEVER** ask the user to input AK/SK directly in the conversation or command line
86> - **NEVER** use `aliyun configure set` with literal credential values
87> - **ONLY** use `aliyun configure list` to check credential status
88>
89> ```bash
90> aliyun configure list
91> ```
92> Check the output for a valid profile (AK, STS, or OAuth identity).
93>
94> **If no valid profile exists, STOP here.**
95> 1. Obtain credentials from [Alibaba Cloud Console](https://ram.console.aliyun.com/manage/ak)
96> 2. Configure credentials **outside of this session** (via `aliyun configure` in terminal or environment variables in shell profile)
97> 3. Return and re-run after `aliyun configure list` shows a valid profile
98
99---
100
101## RAM Permission Policy
102
103This skill only involves read-only operations and requires the following minimum RAM permissions:
104
105| Product | RAM Action | Description |
106|------|-----------|------|
107| API Gateway | apigateway:DescribeInstances | List API Gateway instances |
108| API Gateway | apigateway:DescribeInstanceDropPacket | View dropped packet count |
109| API Gateway | apigateway:DescribeInstanceDropConnections | View dropped connection count |
110| API Gateway | apigateway:DescribeInstanceSlbConnect | View concurrent connection count |
111| API Gateway | apigateway:DescribeInstanceTraffic | View traffic information |
112| API Gateway | apigateway:DescribeInstanceQps | View QPS data |
113| Cloud-Native API Gateway / AI Gateway | apig:ListGateways | Query gateway list |
114| Cloud Monitor | cms:QueryMetricData | Query monitoring data |
115
116Full policy document: [references/ram-policies.md](references/ram-policies.md)
117
118> **[MUST] Permission Failure Handling:** When any command or API call fails due to permission errors at any point during execution, follow this process:
119> 1. Read `references/ram-policies.md` to get the full list of permissions required by this SKILL
120> 2. Use `ram-permission-diagnose` skill to guide the user through requesting the necessary permissions
121> 3. Pause and wait until the user confirms that the required permissions have been granted
122
123---
124
125## Parameter Confirmation
126
127> **IMPORTANT: Parameter Confirmation** — Before executing any command or API call,
128> ALL user-customizable parameters (e.g., RegionId, instance names, CIDR blocks,
129> passwords, domain names, resource specifications, etc.) MUST be confirmed with the
130> user. Do NOT assume or use default values without explicit user approval.
131
132| Parameter | Required/Optional | Description | Default |
133|-------|---------|------|-------|
134| Product Type | Required | Cloud-Native API Gateway / AI Gateway / API Gateway | None |
135| RegionId | Required | Region where the instance is located | None |
136| Instance ID | Required | Unique identifier of the gateway instance | None |
137| Time Range | Optional | Query time point or time range | Current time |
138
139**Available Region Check**:
140- [AI Gateway Available Regions](https://help.aliyun.com/zh/api-gateway/ai-gateway/product-overview/supported-regions)
141- [Cloud-Native API Gateway Available Regions](https://help.aliyun.com/zh/api-gateway/cloud-native-api-gateway/product-overview/regions)
142- [API Gateway Available Regions](https://help.aliyun.com/zh/api-gateway/traditional-api-gateway/developer-reference/api-cloudapi-2016-07-14-endpoint)
143
144---
145
146## Core Workflow
147
148### Step 1: Collect Required Information
149
150Before starting queries, the following information must be confirmed (proactively ask the user if not provided). Using default configurations is prohibited:
151
1521. **Cloud Product Type** — Which cloud product the user wants to query.(Cloud-Native API Gateway / AI Gateway / API Gateway).
1532. **Region (RegionId)** — The region where the instance is located.
1543. **Instance ID** — The unique identifier of the instance.
1554. **Time Range** — The time point or time range for the query.
156
157### Step 2: Query Instance Information
158
159> **[MUST] API Invocation Requirement:**
160> The gateway list MUST be queried by calling the **Apig ListGateways** API via CLI plugin mode.
161> This is a mandatory step — skipping the gateway list query is NOT allowed.
162>
163> **[MUST] Plugin Mode Only:**
164> All commands in this skill MUST be executed using CLI plugin mode. Traditional API format (PascalCase action names) is NOT allowed.
165> If the plugin is not installed, run `aliyun plugin install --names apig` to install it, then retry.
166
167#### 2.1 Cloud-Native API Gateway / AI Gateway
168
169**API Mapping**: Product `Apig` | Action `ListGateways` | Version `2019-01-01`
170
171```bash
172aliyun apig list-gateways --region ${region_id} \
173--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
174```
175
176Note: The `gatewayType` in the response indicates the instance type: `API` (Cloud-Native API Gateway), `AI` (AI Gateway)
177
178#### 2.2 API Gateway
179
180```bash
181aliyun cloudapi describe-instances --api-version 2016-07-14 --region ${region_id} \
182--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
183```
184
185Note: The `InstanceType` in the response indicates the instance type. Only `VPC_DEDICATED` (dedicated) instances are supported. `VPC_SHARED` shared instances do not support inspection.
186
187### Step 3: Retrieve Monitoring Metric Data
188
189#### 3.1 Cloud-Native API Gateway / AI Gateway
190
191> **[MUST] API Invocation Requirement:**
192> Monitoring metrics MUST be queried using the **Cms DescribeMetricData** API via CLI plugin mode
193>
194> **CRITICAL — PROHIBITED APIs:**
195> - **DO NOT USE** `DescribeMetricList` (`aliyun cms describe-metric-list`) — returns a different response format and is NOT accepted
196> - **DO NOT USE** `DescribeMetricMetaList` (`aliyun cms describe-metric-meta-list`) — DO NOT call this API to discover or list available metrics
197>
198> **ALL metric names are already provided below. No metric discovery is needed:**
199> - For **Cloud-Native API Gateway** instances: select metric names from the **Supported Metrics for Cloud-Native API Gateway** table below
200> - For **AI Gateway** instances: select metric names from the **Supported Metrics for AI Gateway** table below
201> - Use the exact `Metric Name` values from the corresponding table directly as the `--metric-name` parameter
202
203**API Mapping**: Product `Cms` | Action `DescribeMetricData` | Version `2019-01-01` | Namespace `acs_cnapigateway`
204
205```bash
206aliyun cms describe-metric-data \
207--namespace acs_cnapigateway \
208--region ${region} \
209--api-version 2019-01-01 \
210--metric-name ${metric-name} \
211--period 60 \
212--start-time ${start-time} \
213--end-time ${end-time} \
214--dimensions '[{"instanceId": "${instanceId}"}]' \
215--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
216```
217
218**Notes**:
219- `start-time / end-time` use Unix millisecond timestamps
220- `instanceId` must be passed in dimensions
221- **MUST query ALL of the following metric categories**: CPU Usage, Memory Usage, Connections, Network IO, Rate Limiting
222- Only check CPU, memory, connections, network IO, rate limiting, and bandwidth
223
224**Supported Metrics for Cloud-Native API Gateway**:
225| Metric Name | Display Name | Dimensions | Metric Period | Unit |
226|---|---|---|---|---|
227| EnvoyClientActiveConnection | Current active connections (gateway to client) | userId,regionId,instanceId | 60300 | count |
228| EnvoyClientDestroyConnection | Destroyed connections per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
229| EnvoyClientDestroySSL | SSL handshake failures per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
230| EnvoyClientNewConnection | New connections per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
231| EnvoyClientNewSSL | SSL handshakes per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
232| EnvoyClientReuseSSL | SSL handshake reuse per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
233| EnvoyCpuUsageRate | Gateway CPU usage | userId,instanceId | 60300 | % |
234| EnvoyFsReadBytes | Disk read load | userId,instanceId | 60300 | B/s |
235| EnvoyFsWriteBytes | Disk write load | userId,instanceId | 60300 | B/s |
236| EnvoyMemoryUsage | Memory load | userId,instanceId | 60300 | MiB |
237| EnvoyMemoryUsageRate | Gateway memory usage | userId,instanceId | 60300 | % |
238| EnvoyNetworkInBytes | Inbound network IO load | userId,instanceId | 60300 | B/s |
239| EnvoyNetworkOutBytes | Outbound network IO load | userId,instanceId | 60300 | B/s |
240| EnvoyRateLimitRequests | Rate-limited requests | userId,instanceId | 60300 | count/s |
241| EnvoyUpstreamActiveConnection | Current active connections (gateway to backend) | userId,instanceId | 60300 | count |
242| EnvoyUpstreamDestroyConnection | Destroyed connections per second (gateway to backend) | userId,instanceId | 60300 | count/s |
243| EnvoyUpstreamNewConnection | New connections per second (gateway to backend) | userId,instanceId | 60300 | count/s |
244| Ipv4EipRateIn | Public IPv4 inbound bandwidth | userId,instanceId | 60300 | bit/s |
245| Ipv4EipRateOut | Public IPv4 outbound bandwidth | userId,instanceId | 60300 | bit/s |
246| Ipv6GatewayRateIn | Public IPv6 inbound bandwidth | userId,instanceId | 60300 | bit/s |
247| Ipv6GatewayRateOut | Public IPv6 outbound bandwidth | userId,instanceId | 60300 | bit/s |
248| SlbInstanceTrafficRX | Private network inbound bandwidth | userId,instanceId | 60300 | bit/s |
249| SlbInstanceTrafficTX | Private network outbound bandwidth | userId,instanceId | 60300 | bit/s |
250
251**Supported Metrics for AI Gateway**:
252| Metric Name | Display Name | Dimensions | Metric Period | Unit |
253|---|---|---|---|---|
254| AIGatewayEnvoyClientActiveConnection | Current active connections (gateway to client) | userId,regionId,instanceId | 60300 | count |
255| AIGatewayEnvoyClientDestroyConnection | Destroyed connections per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
256| AIGatewayEnvoyClientDestroySSL | SSL handshake failures per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
257| AIGatewayEnvoyClientNewConnection | New connections per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
258| AIGatewayEnvoyClientNewSSL | SSL handshakes per second (gateway to client) | userId,regionId,instanceId | 60300 | count/s |
259| AIGatewayEnvoyCpuUsageRate | Gateway CPU usage | userId,regionId,instanceId | 60300 | % |
260| AIGatewayEnvoyFsReadBytes | Disk read load | userId,regionId,instanceId | 60300 | B/s |
261| AIGatewayEnvoyFsWriteBytes | Disk write load | userId,regionId,instanceId | 60300 | B/s |
262| AIGatewayEnvoyMemoryUsage | Memory load | userId,regionId,instanceId | 60300 | MiB |
263| AIGatewayEnvoyMemoryUsageRate | Gateway memory usage | userId,regionId,instanceId | 60300 | % |
264| AIGatewayEnvoyNetworkInBytes | Inbound network IO load | userId,regionId,instanceId | 60300 | B/s |
265| AIGatewayEnvoyNetworkOutBytes | Outbound network IO load | userId,regionId,instanceId | 60300 | B/s |
266| AIGatewayEnvoyRateLimitRequests | Rate-limited requests | userId,regionId,instanceId | 60300 | count/s |
267| AIGatewayEnvoyUpstreamActiveConnection | Current active connections (gateway to backend) | userId,regionId,instanceId | 60300 | count |
268| AIGatewayEnvoyUpstreamDestroyConnection | Destroyed connections per second (gateway to backend) | userId,regionId,instanceId | 60300 | count/s |
269| AIGatewayEnvoyUpstreamNewConnection | New connections per second (gateway to backend) | userId,regionId,instanceId | 60300 | count/s |
270| Ipv4EipRateIn | Public IPv4 inbound bandwidth | userId,instanceId | 60300 | bit/s |
271| Ipv4EipRateOut | Public IPv4 outbound bandwidth | userId,instanceId | 60300 | bit/s |
272| Ipv6GatewayRateIn | Public IPv6 inbound bandwidth | userId,instanceId | 60300 | bit/s |
273| Ipv6GatewayRateOut | Public IPv6 outbound bandwidth | userId,instanceId | 60300 | bit/s |
274| SlbInstanceTrafficRX | Private network inbound bandwidth | userId,instanceId | 60300 | bit/s |
275| SlbInstanceTrafficTX | Private network outbound bandwidth | userId,instanceId | 60300 | bit/s |
276
277#### 3.2 API Gateway Dedicated Instances
278
279> **[MUST] API Invocation Requirement:**
280> For API Gateway dedicated instances, you MUST use the **CloudAPI dedicated APIs** via CLI plugin mode to query monitoring data.
281> **DO NOT use Cloud Monitor (CMS) for API Gateway dedicated instances.** CMS is only for Cloud-Native API Gateway / AI Gateway (Step 3.1).
282>
283> **The following 5 API calls are ALL mandatory:**
284>
285> | # | API | Product | Action | Version | Notes |
286> |---|-----|---------|--------|---------|-------|
287> | 1 | Dropped packets | `cloudapi` | `DescribeInstanceDropPacket` | `2016-07-14` | |
288> | 2 | Dropped connections | `cloudapi` | `DescribeInstanceDropConnections` | `2016-07-14` | |
289> | 3 | SLB connections | `cloudapi` | `DescribeInstanceSlbConnect` | `2016-07-14` | |
290> | 4 | Traffic | `cloudapi` | `DescribeInstanceTraffic` | `2016-07-14` | Query RELEASE, PRE, TEST separately |
291> | 5 | QPS | `cloudapi` | `DescribeInstanceQps` | `2016-07-14` | Query RELEASE, PRE, TEST separately |
292>
293> **CRITICAL: Traffic and QPS must each be queried 3 times** — once for each environment (RELEASE, PRE, TEST).
294> This means a total of **7 API calls** (5 base APIs, but Traffic and QPS each × 3 environments).
295
296**Note**: For API Gateway, skip 3.1 and execute this step directly. Time format uses ISO8601 UTC (YYYY-MM-DDThh:mm:ssZ)
297
298```bash
299# 1. Dropped packets
300aliyun cloudapi describe-instance-drop-packet \
301--start-time ${start-time} --end-time ${end-time} \
302--instance-id ${instanceId} --sbc-name Maximum \
303--api-version 2016-07-14 --region ${region} \
304--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
305
306# 2. Dropped connections
307aliyun cloudapi describe-instance-drop-connections \
308--start-time ${start-time} --end-time ${end-time} \
309--instance-id ${instanceId} --sbc-name Maximum \
310--api-version 2016-07-14 --region ${region} \
311--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
312
313# 3. SLB connections
314aliyun cloudapi describe-instance-slb-connect \
315--start-time ${start-time} --end-time ${end-time} \
316--instance-id ${instanceId} --sbc-name Maximum \
317--api-version 2016-07-14 --region ${region} \
318--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
319
320# 4. Traffic — MUST query RELEASE, PRE, and TEST environments separately (3 calls)
321aliyun cloudapi describe-instance-traffic \
322--start-time ${start-time} --end-time ${end-time} \
323--instance-id ${instanceId} --stage-name RELEASE \
324--api-version 2016-07-14 --region ${region} \
325--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
326
327aliyun cloudapi describe-instance-traffic \
328--start-time ${start-time} --end-time ${end-time} \
329--instance-id ${instanceId} --stage-name PRE \
330--api-version 2016-07-14 --region ${region} \
331--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
332
333aliyun cloudapi describe-instance-traffic \
334--start-time ${start-time} --end-time ${end-time} \
335--instance-id ${instanceId} --stage-name TEST \
336--api-version 2016-07-14 --region ${region} \
337--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
338
339# 5. QPS — MUST query RELEASE, PRE, and TEST environments separately (3 calls)
340aliyun cloudapi describe-instance-qps \
341--start-time ${start-time} --end-time ${end-time} \
342--instance-id ${instanceId} --stage-name RELEASE \
343--api-version 2016-07-14 --region ${region} \
344--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
345
346aliyun cloudapi describe-instance-qps \
347--start-time ${start-time} --end-time ${end-time} \
348--instance-id ${instanceId} --stage-name PRE \
349--api-version 2016-07-14 --region ${region} \
350--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
351
352aliyun cloudapi describe-instance-qps \
353--start-time ${start-time} --end-time ${end-time} \
354--instance-id ${instanceId} --stage-name TEST \
355--api-version 2016-07-14 --region ${region} \
356--user-agent AlibabaCloud-Agent-Skills/alibabacloud-apigw-inspection/{session-id}
357```
358
359### Step 4: Generate Inspection Report
360
361#### 4.1 Anomaly Check Rules
362
363| Metric | Normal | Warning | Critical |
364|------|------|------|------|
365| CPU Usage | < 70% | 70%-85% | > 85% |
366| Memory Usage | < 75% | 75%-90% | > 90% |
367| Connections | < 70% of max | 70%-85% | > 85% |
368| Network IO | < 70% of bandwidth | 70%-85% | > 85% |
369| Rate Limiting | No triggers | > 0 occurrences | Continuously increasing |
370
371**Spike Detection**: Alert when the increase within a period exceeds the threshold (CPU > 30%, Memory > 25%, Connections > 50%, Network IO > 40%)
372
373#### 4.2 Report Structure
374
375The inspection report should include the following sections:
3761. **Basic Information** — Product type, instance ID, region, inspection time
3772. **Inspection Results Overview** — Table format showing the status of each metric
3783. **Detailed Analysis** — Peak values, trends, and analysis for each metric
3794. **Risk Assessment** — List of high/medium risk items
3805. **Optimization Recommendations** — Recommendations based on actual issues (omit if all metrics are normal)
3816. **Conclusion** — Summary of inspection results
382
383**Important**: All data must come from actual API responses. Fabricating data is strictly prohibited.
384
385---
386
387## Success Verification
388
389For verification methods, see [references/verification-method.md](references/verification-method.md)
390
391---
392
393## Cleanup
394
395This skill only involves read-only operations. No resource cleanup is required.
396
397---
398
399## Command List
400
401For the full command list, see [references/related-commands.md](references/related-commands.md)
402
403---
404
405## Best Practices
406
4071. **Plugin Mode Only**: All commands MUST be executed using `aliyun` CLI plugin mode. Traditional API format (PascalCase action names) is NOT allowed. If a required plugin is not installed, run `aliyun plugin install --names <plugin-name>` to install it first.
4082. **Confirm Parameters**: All user-customizable parameters must be confirmed before execution
4093. **Check Region**: Ensure the region is within the available regions for the corresponding product
4104. **Check Instance Type**: API Gateway only supports dedicated instance inspection
4115. **Time Format**: Cloud Monitor uses millisecond timestamps; API Gateway uses ISO8601 UTC
4126. **Data Accuracy**: Report data must come from actual API responses
4137. **Risk Classification**: Strictly follow threshold standards for risk assessment
414
415---
416
417## Reference Links
418
419| Document | Path |
420|------|------|
421| CLI Installation Guide | [references/cli-installation-guide.md](references/cli-installation-guide.md) |
422| RAM Permission Policy | [references/ram-policies.md](references/ram-policies.md) |
423| Related Commands | [references/related-commands.md](references/related-commands.md) |
424| Verification Method | [references/verification-method.md](references/verification-method.md) |
425| Acceptance Criteria | [references/acceptance-criteria.md](references/acceptance-criteria.md) |
426| AI Gateway Available Regions | https://help.aliyun.com/zh/api-gateway/ai-gateway/product-overview/supported-regions |
427| Cloud-Native API Gateway Available Regions | https://help.aliyun.com/zh/api-gateway/cloud-native-api-gateway/product-overview/regions |
428| API Gateway Available Regions | https://help.aliyun.com/zh/api-gateway/traditional-api-gateway/developer-reference/api-cloudapi-2016-07-14-endpoint |