Skip to Content
GPU 接口文档GPU实例获取实例监控数据
GPU API 接口

获取实例监控数据

接口说明

获取优云智算 GPU 实例的监控指标(CPU、内存、GPU、磁盘使用率等)。控制台实例列表与「用量详情」均调用本接口。

POSThttps://api.compshare.cnActionGetCompShareInstanceMonitor

调用提示Region 须与实例所在地域一致;UHostIds 直接使用 JSON 字符串数组传入。仅查最近快照时,也可使用 DescribeCompShareInstance 返回的 MonitorMessages 字段。

使用限制

  • 支持批量查询多个实例;具体返回指标以接口为准。
  • 并发查询建议不超过 10 个实例 ID。

请求参数

名称类型必填描述示例值
ActionString接口名称GetCompShareInstanceMonitor
RegionString地域,须与实例一致cn-wlcb
ZoneString可用区cn-wlcb-01
UHostIdsArray of String实例 ID 数组。不传则返回当前 Region 下符合条件的实例["uhost-xxxx"]

响应参数

名称类型描述示例值
ActionString响应名称GetCompShareInstanceMonitorResponse
RetCodeInteger返回码,0 为成功0
DataObject监控数据

Data 结构

名称类型描述
ListArray of Object实例监控数据列表

List 元素结构

名称类型描述
UHostIdString实例 ID
MetricsArray of Object监控指标列表

Metrics 元素结构

名称类型描述
MetricKeyString指标名称
TagsObject标签(如 uuidgpu_bus_id 等)
ResultsArray of Object指标数据

Results / Values

名称类型描述
ValuesArray of Object时间序列数据点
Values[].TimestampIntegerUnix 时间戳
Values[].ValueFloat指标值

常见 MetricKey

MetricKey说明
uhost_cpu_usedCPU 使用率(%)
cloudwatch_memory_usage内存使用率(%)
cloudwatch_sys_disk_used_per系统盘使用率(%)
cloudwatch_data_disk_used_per数据盘使用率(%)
cloudwatch_gpu_utilGPU 使用率(%)
cloudwatch_gpu_memory_usageGPU 显存使用率(%)

请求示例

Python(使用 UCloud SDK)

pip install --upgrade ucloud-sdk-python3
from 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(JSON 数组)

{ "Action": "GetCompShareInstanceMonitor", "Region": "cn-wlcb", "Zone": "cn-wlcb-01", "UHostIds": ["uhost-xxxx"] }

故障排查

现象处理建议
调不通 / RetCode 非 0确认 RegionZoneDescribeCompShareInstance 中实例一致
参数错误使用 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} ] } ] } ] } ] } }
Last updated on