说明:当前页面接口为旧版 API,未来可能停止维护。容器服务 API 3.0 版本接口定义更加规范,访问时延下降显著,建议使用 容器服务 API 3.0。
接口描述
本接口(CreateLogCollector)用于创建日志收集规则。
接口请求域名:
ccs.api.qcloud.com
输入参数
以下请求参数列表仅列出了接口请求参数,其它参数见 公共请求参数。
参数名称 | 描述 | 类型 | 必选 |
---|---|---|---|
name | 收集规则名称,集群范围内唯一,不可重复 | String | 是 |
clusterId | 集群 ID | String | 是 |
inputType | 收集类型。收集容器日志请传“container-log”,收集主机日志请传“host-log” | String | 是 |
outputType | 消费类型。输出到 Kafka 请传“kafka”,输出到CKafka 请传“ckafka”,输出到 CLS 请传“cls” | String | 是 |
inputOption | 收集选项,参考 收集和消费选项 | Object | 是 |
outputOption | 消费选项,参考 收集和消费选项 | Object | 是 |
收集和消费选项
使用此接口创建日志收集器时,根据 inputType
和 outputType
传入值的不同,inputOption
和 outputOption
需要传入不同结构的 Object
。
当 inputType
为 container-log
时,需要传入的 inputOption 结构为
参数名称 | 描述 | 类型 | 必选 |
---|---|---|---|
allNamespaces | 是否收集所有 namespace 的容器的日志 | Boolean | 是 |
namespaces | 如果 allNamespaces 值为 false,需要传入需要收集的 namespace 的名称的列表 | Array | 否 |
namespaces 字段 Array 中每个 Object 的结构为
参数名称 | 描述 | 类型 | 必选 |
---|---|---|---|
namespace | namespace 名称 | String | 是 |
allContainers | 是否收集所有容器的日志 | Boolean | 是 |
services | 如果 allContainers 值为 false,需要传入此 namespace 下要收集的 pod 对应的 deploy 的名称(仅支持收集由 deployment 创建的 pod) | Array | 是 |
当 inputType
为 host-log
时,需要传入的 inputOption 结构为
参数名称 | 描述 | 类型 | 必选 |
---|---|---|---|
path | 收集的主机日志文件的路径,支持通配路径 | String | 是 |
labels | 为对应的日志记录附加的 metadata,仅支持 k-v 模式,如 {"key": "value"} | Object | 否 |
当 outputType
为 kafka
时,需要传入的 outputOption 结构为
参数名称 | 描述 | 类型 | 必选 |
---|---|---|---|
host | 对应 kafka 的 host | String | 是 |
port | 对应 kafka 的 port | Integer | 是 |
topic | 对应 kafka 的主题名称 | String | 是 |
当 outputType
为 ckafka
时,需要传入的 outputOption 结构为
参数名称 | 描述 | 类型 | 必选 |
---|---|---|---|
instanceId | 对应 CKafka 的 instanceId | String | 是 |
topicId | 对应 CKafka 主题的 topicId | String | 是 |
host | 对应 CKafka 的 host | String | 是 |
port | 对应 CKafka 的 port | Integer | 是 |
topic | 对应 CKafka 的主题名称 | String | 是 |
当 outputType
为 cls
时,需要传入的 outputOption 结构为
参数名称 | 描述 | 类型 | 必选 |
---|---|---|---|
logsetId | 日志集ID | String | 是 |
topicID | 日志主题ID | String | 是 |
输出参数
参数名称 | 描述 | 类型 |
---|---|---|
code | 公共错误码。0 表示成功,其他值表示失败 | Int |
codeDesc | 业务错误码。成功时返回 Success,错误时返回具体业务错误原因 | String |
message | 模块错误信息描述,与接口相关 | String |
data | 日志收集规则相关数据 | Object |
data 字段的结构如下
参数名称 | 描述 | 类型 |
---|---|---|
logCollectorList | 日志收集规则 | Object |
logCollectorList 字段中 Object 的结构如下
参数名称 | 描述 | 类型 |
---|---|---|
name | 收集规则名称,集群范围内唯一,不可重复 | String |
clusterId | 集群 ID | String |
clusterName | 集群名称 | String |
createdAt | 收集规则的创建时间 | String |
inputType | 收集类型。“container-log”代表收集容器日志,“host-log”代表收集主机日志 | String |
outputType | 消费类型。"kafka"代表输出到 Kafka,“ckafka”代表输出到 CKafka | String |
inputOption | 收集选项,参考 收集和消费选项 | Object |
outputOption | 消费选项,参考 收集和消费选项 | Object |
示例
输入
https://ccs.api.qcloud.com/v2/index.php?Action=CreateLogCollector&SecretId=1&Nonce=18088&Timestamp=1520305679&Region=xx&Uin=xxxxxxxxxx&AppId=xxxxxxxxxx&name=test-log&clusterId=cls-xxxxxxxx&inputType=container-log&outputType=kafka&inputOption.allNamespaces=true&outputOption.host=192.168.5.6&outputOption.port=13001&outputOption.topic=containerlogs&Signature=0Hf2%2BzCRgplp2K975KffMU8vRFY%3D
输出
{
"code": 0,
"message": "",
"codeDesc": "Success",
"data": {
"logCollectorList": {
"name": "test-log",
"clusterId": "cls-xxxxxxxx",
"clusterName": "log-test",
"createdAt": "2018-03-06 11:07:59",
"inputType": "container-log",
"outputType": "kafka",
"inputOption": {
"allNamespaces": true
},
"outputOption": {
"host": "192.168.5.6",
"port": 13001,
"topic": "containerlogs"
}
}
}
}