查询Shard列表

调用ListShards接口查询Logstore的Shard列表。

前提条件

参数说明

def list_shards(self, project_name, logstore_name):

请求参数

名称

类型

是否必填

描述

示例值

project_name

String

project名称。

ali-test-project

logstore_name

String

logstore名称。

test-logstore

返回参数

返回参数说明,请参见SplitShard - 分裂Shard

示例代码

from aliyun.log import LogClient
import os


def main():
    # 本示例从环境变量中获取AccessKey ID和AccessKey Secret
    accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')

    # 日志服务的服务接入点
    endpoint = "cn-hangzhou.log.aliyuncs.com"
    project_name = "ali-test-project"
    logstore_name = "test-logstore"

    client = LogClient(endpoint, accessKeyId, accessKey, "")

    res = client.list_shards(project_name, logstore_name)
    res.log_print()


if __name__ == '__main__':
    main()

示例返回结果

ListShardResponse:
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '335', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Wed, 30 Oct 2024 06:21:26 GMT', 'x-log-time': '1730269286', 'x-log-requestid': '6721D066A5CBF5E0D241541F'}
res: [{'shardID': 0, 'status': 'readwrite', 'inclusiveBeginKey': '00000000000000000000000000000000', 'exclusiveEndKey': '80000000000000000000000000000000', 'createTime': 1716966695}, {'shardID': 1, 'status': 'readwrite', 'inclusiveBeginKey': '80000000000000000000000000000000', 'exclusiveEndKey': 'ffffffffffffffffffffffffffffffff', 'createTime': 1716966695}]

Process finished with exit code 0

相关文档