指标和标签信息获取¶
GET /api/v1/metric_info/get
概述¶
读取指定指标集的元数据和已查询到的 Tag 说明。
调用前和使用步骤¶
- 从指标集列表的content.data[].name取得准确名称,传入Query参数metric。
- 从content.metric_fields_info[]读取字段及说明,从content.tags_info[]读取Tag说明;需要本地化时设置Accept-Language。
可以先获取指标集名称,再读取字段说明、度量单位和已有的 Tag 描述。没有匹配的字段元数据或 Tag 时,对应数组为空。
字段查询基于当前工作空间当天的数据;标签关联存在约1小时缓存,标签查询失败时可能保留已获取的部分结果。空tags不能单独证明没有标签,也不是全部历史标签的完整枚举。
请求头¶
| 参数名 | 类型 | 必选 | 说明 |
|---|---|---|---|
| Accept-Language | string | 决定字段和 Tag 的可本地化说明语言。 例子: zh获取或填写方式: 按需要返回说明的语言填写,例如 zh。 |
|
| DF-API-KEY | string | Y | AK 标识,AK uuid 例子: <DF-API-KEY>获取或填写方式: 在目标工作空间的 API Key 管理中创建或获取具备本接口权限的 Key。 |
Query 请求参数¶
| 参数名 | 类型 | 必选 | 说明 |
|---|---|---|---|
| metric | string | Y | 指标集的准确名称,例如 cpu。 允许 null: False 允许空字符串: False 例子: cpu获取或填写方式: 从获取指标集列表响应的 content.data[].name 取值。 |
参数补充说明¶
使用 GET 读取当前 API Key 所属工作空间的数据。
请求例子¶
curl --get -H "DF-API-KEY: <DF-API-KEY>" \
"https://openapi.guance.com/api/v1/metric_info/get" \
--data-urlencode "metric=cpu"
响应¶
HTTP 200,application/json。
| 字段 | 类型 | 说明 |
|---|---|---|
| content.metric_fields_info | array<object> |
结果列表。没有匹配结果时为空数组。 |
| content.metric_fields_info[].field | string | 指标字段名。 |
| content.metric_fields_info[].type | string | 字段元数据来源,inner 为内置,custom 为自定义。 |
| content.metric_fields_info[].data_type | string 或 null | 字段的数据类型。 |
| content.metric_fields_info[].unit | string | 指标单位,可为空。 |
| content.metric_fields_info[].desc | string | 指标字段说明。 |
| content.metric_fields_info[].tags | array<string> |
该字段关联的Tag名称数组;可能受缓存或标签查询部分失败影响,空数组不能单独证明没有关联标签。 |
| content.metric_fields_info[].origin_field | string | 原始字段名,部分配置会返回。 |
| content.tags_info | array<object> |
结果列表。没有匹配结果时为空数组。 |
| content.tags_info[].tag_key | string | Tag 名。 |
| content.tags_info[].tag_desc | string | Tag 说明,可为空。 |
| content.declaration | object 或 null | 非空content附带的工作空间公共声明,未配置时可为null或空对象;空content对象不添加。 |
{
"code": 200,
"content": {
"metric_fields_info": [
{
"field": "usage_idle",
"type": "inner",
"data_type": "float",
"unit": "percent",
"desc": "空闲百分比",
"tags": [
"host"
]
}
],
"tags_info": [
{
"tag_key": "host",
"tag_desc": "主机名"
}
],
"declaration": null
},
"errorCode": "",
"message": "",
"success": true,
"traceId": "TRACE-EXAMPLE"
}
错误响应¶
鉴权、限流和公共请求错误参见公共错误定义。
| HTTP 状态 | errorCode | 触发条件 | 消息或响应说明 | 处理方式 |
|---|---|---|---|---|
| 406 | ft.ParameterValidationFailed | 缺少必填 Query 参数,或传入了未声明的 Query 参数 | 请求字段校验失败,消息指出字段或规则。 | 核对参数表和示例。 |
| 403 | ft.ForbiddenQuery | 当前凭据无权查询请求对应的数据 | 查询权限不足。 | 检查 API Key 查询权限和目标数据的授权范围。 |
| 503 | ft.QueryServiceUnavailable | 依赖的查询服务暂不可用 | 查询服务暂不可用,稍后重试。 | 检查 content.retryable,暂时性错误可延时重试。 |