GPU服务API文档
GPU实例
获取实例监控数据

GetCompShareInstanceMonitor — 获取实例监控数据

接口说明

获取算力共享实例的监控数据,包括 CPU 使用率、内存使用率、GPU 使用率和显存使用率等指标。

使用限制

  • 支持批量查询多个实例,但查询多个实例时仅返回最近 60 秒的数据。
  • 查询单个实例时可自定义时间范围(StartTime / EndTime)。
  • 并发查询上限为 10 个实例。

请求参数

名称类型必填描述示例值
ActionString接口名称GetCompShareInstanceMonitor
RegionString地域cn-wlcb
UHostIds.NString实例 ID 列表uhost-xxxx
StartTimeInteger查询起始时间(Unix 时间戳)。仅查询单个实例时有效,不传则默认最近 60 秒1712563200
EndTimeInteger查询结束时间(Unix 时间戳)。仅查询单个实例时有效,不传则默认当前时间1712566800

响应参数

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

Data 结构

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

List 元素结构

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

Metrics 元素结构

名称类型描述
MetricKeyString指标名称,详见下方「指标列表」
TagsObject标签信息,包含 uuiddiskmountgpu_bus_id 数组
ResultsArray of Object指标数据

Results 元素结构

名称类型描述
ResourceIdString资源短 ID
LongResourceIdString资源长 ID
TagMapObject标签键值对映射
ValuesArray of Object时间序列数据点

Values 元素结构

名称类型描述
TimestampInteger时间戳
ValueFloat指标值

指标列表

基础指标(所有查询均返回):

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

扩展指标(仅查询单个实例且指定时间范围时返回):

MetricKey说明单位
uhost_net_in_flow网卡入带宽bps
uhost_net_out_flow网卡出带宽bps
uhost_disk_read磁盘读吞吐Bps
uhost_disk_write磁盘写吞吐Bps

注意:查询多个实例时(UHostIds 数量 > 1),系统强制查询最近 60 秒且仅返回基础指标集;查询单个实例且指定 StartTime/EndTime 时,返回基础 + 扩展全部指标。


请求示例

Python(使用 UCloud SDK)

安装 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",    # 替换为你的公钥,从 https://console.compshare.cn/uaccount/api_manage 获取
        "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['UHostId']}:")
            for metric in inst.get("Metrics", []):
                print(f"  {metric['MetricKey']}: {metric.get('Results', [])}")
    except exc.UCloudException as e:
        print(e)
 
 
if __name__ == "__main__":
    main()

Go(使用 UCloud SDK)

安装依赖:

go get github.com/ucloud/ucloud-sdk-go

示例代码:

package main
 
import (
	"fmt"
 
	"github.com/ucloud/ucloud-sdk-go/services/ucompshare"
	"github.com/ucloud/ucloud-sdk-go/ucloud"
	"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
)
 
func main() {
	cfg := ucloud.NewConfig()
	cfg.Region = "cn-wlcb"
	cfg.BaseUrl = "https://api.compshare.cn"
 
	credential := auth.NewCredential()
	credential.PublicKey = "my_public_key"   // 替换为你的公钥,从 https://console.compshare.cn/uaccount/api_manage 获取
	credential.PrivateKey = "my_private_key" // 替换为你的私钥
	client := ucompshare.NewClient(&cfg, &credential)
 
	req := client.NewGetCompShareInstanceMonitorRequest()
	req.UHostIds = []string{"uhost-xxxx"}
 
	resp, err := client.GetCompShareInstanceMonitor(req)
	if err != nil {
		fmt.Printf("查询失败: %s\n", err)
		return
	}
	fmt.Printf("监控数据: %+v\n", resp.Data)
}

响应示例

{
  "Action": "GetCompShareInstanceMonitorResponse",
  "RetCode": 0,
  "Data": {
    "List": [
      {
        "UHostId": "uhost-xxxx",
        "Metrics": [
          {
            "MetricKey": "uhost_cpu_used",
            "Tags": {"uuid": ["uhost-xxxx"]},
            "Results": [
              {
                "ResourceId": "uhost-xxxx",
                "LongResourceId": "uhost-xxxx-long",
                "TagMap": {},
                "Values": [
                  {"Timestamp": 1712563200, "Value": 35.2},
                  {"Timestamp": 1712563260, "Value": 42.1}
                ]
              }
            ]
          },
          {
            "MetricKey": "cloudwatch_gpu_util",
            "Tags": {"gpu_bus_id": ["00000000:00:07.0"]},
            "Results": [
              {
                "ResourceId": "uhost-xxxx",
                "LongResourceId": "uhost-xxxx-long",
                "TagMap": {"gpu_bus_id": "00000000:00:07.0"},
                "Values": [
                  {"Timestamp": 1712563200, "Value": 78.5},
                  {"Timestamp": 1712563260, "Value": 82.3}
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}
Copyright © 2026 沪ICP备12020087号-61