GetCompShareInstanceMonitor — 获取实例监控数据
接口说明
获取优云智算 GPU 实例的监控指标(CPU、内存、GPU、磁盘使用率等)。控制台实例列表与「用量详情」均调用本接口。
调用提示:
Region须与实例所在地域一致;UHostIds为数组(HTTP 表单编码为UHostIds.0、UHostIds.1…)。仅查最近快照时,也可使用 DescribeCompShareInstance 返回的MonitorMessages字段。
使用限制
- 支持批量查询多个实例;具体返回指标以接口为准。
- 并发查询建议不超过 10 个实例 ID。
请求参数
| 名称 | 类型 | 必填 | 描述 | 示例值 |
|---|---|---|---|---|
| Action | String | 是 | 接口名称 | GetCompShareInstanceMonitor |
| Region | String | 是 | 地域,须与实例一致 | cn-wlcb |
| Zone | String | 否 | 可用区 | cn-wlcb-01 |
| UHostIds.N | String | 否 | 【数组】实例 ID。UHostIds.0 为第一台,UHostIds.1 为第二台。不传则返回当前 Region 下符合条件的实例 | uhost-xxxx |
响应参数
| 名称 | 类型 | 描述 | 示例值 |
|---|---|---|---|
| Action | String | 响应名称 | GetCompShareInstanceMonitorResponse |
| RetCode | Integer | 返回码,0 为成功 | 0 |
| Data | Object | 监控数据 | — |
Data 结构
| 名称 | 类型 | 描述 |
|---|---|---|
| List | Array of Object | 实例监控数据列表 |
List 元素结构
| 名称 | 类型 | 描述 |
|---|---|---|
| UHostId | String | 实例 ID |
| Metrics | Array of Object | 监控指标列表 |
Metrics 元素结构
| 名称 | 类型 | 描述 |
|---|---|---|
| MetricKey | String | 指标名称 |
| Tags | Object | 标签(如 uuid、gpu_bus_id 等) |
| Results | Array of Object | 指标数据 |
Results / Values
| 名称 | 类型 | 描述 |
|---|---|---|
| Values | Array of Object | 时间序列数据点 |
| Values[].Timestamp | Integer | Unix 时间戳 |
| Values[].Value | Float | 指标值 |
常见 MetricKey
| MetricKey | 说明 |
|---|---|
uhost_cpu_used | CPU 使用率(%) |
cloudwatch_memory_usage | 内存使用率(%) |
cloudwatch_sys_disk_used_per | 系统盘使用率(%) |
cloudwatch_data_disk_used_per | 数据盘使用率(%) |
cloudwatch_gpu_util | GPU 使用率(%) |
cloudwatch_gpu_memory_usage | GPU 显存使用率(%) |
请求示例
Python(使用 UCloud SDK)
pip install --upgrade ucloud-sdk-python3from ucloud.core import exc
from ucloud.client import Client
def main():
client = Client({
"region": "cn-wlcb",
"public_key": "my_public_key",
"private_key": "my_private_key",
"base_url": "https://api.compshare.cn",
})
try:
resp = client.ucompshare().get_comp_share_instance_monitor({
"UHostIds": ["uhost-xxxx"],
})
for inst in resp.get("Data", {}).get("List", []):
print(f"实例 {inst.get('UHostId')}:")
for metric in inst.get("Metrics", []):
print(f" {metric.get('MetricKey')}")
except exc.UCloudException as e:
print(e)
if __name__ == "__main__":
main()Go(使用 UCloud SDK)
req := client.NewGetCompShareInstanceMonitorRequest()
req.UHostIds = []string{"uhost-xxxx"}
resp, err := client.GetCompShareInstanceMonitor(req)HTTP(表单数组)
POST https://api.compshare.cn/
Action=GetCompShareInstanceMonitor
&Region=cn-wlcb
&Zone=cn-wlcb-01
&UHostIds.0=uhost-xxxx故障排查
| 现象 | 处理建议 |
|---|---|
| 调不通 / RetCode 非 0 | 确认 Region、Zone 与 DescribeCompShareInstance 中实例一致 |
| 参数错误 | 使用 UHostIds 数组,勿将单个 ID 写成 UHostId(除非网关兼容) |
| 仅需当前使用率 | 调用 DescribeCompShareInstance,读取 MonitorMessages |
响应示例
{
"Action": "GetCompShareInstanceMonitorResponse",
"RetCode": 0,
"Data": {
"List": [
{
"UHostId": "uhost-xxxx",
"Metrics": [
{
"MetricKey": "uhost_cpu_used",
"Results": [
{
"Values": [
{"Timestamp": 1712563200, "Value": 35.2}
]
}
]
}
]
}
]
}
}