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