Este tópico descreve como consultar a capacidade de armazenamento de um bucket específico, bem como a quantidade e o volume de objetos por classe de armazenamento nesse bucket.
Observações de uso
O código de exemplo deste tópico usa o ID de região
cn-hangzhou, referente à região China (Hangzhou). Por padrão, o acesso aos recursos do bucket ocorre pelo endpoint público. Para acessar esses recursos por meio de outros serviços da Alibaba Cloud na mesma região do bucket, use um endpoint interno. Para mais informações sobre as regiões e endpoints compatíveis com o OSS, consulte Regiões e endpoints.
Definição do método
get_bucket_stat(request: GetBucketStatRequest, **kwargs) → GetBucketStatResult
Parâmetros da solicitação
|
Parâmetro |
Tipo |
Descrição |
|
request |
GetBucketStatRequest |
Os parâmetros da solicitação. Para mais informações, consulte GetBucketStatRequest |
Parâmetros da resposta
|
Tipo |
Descrição |
|
GetBucketStatResult |
Os parâmetros da resposta. Para mais informações, consulte GetBucketStatResult |
Para obter a definição completa do método, consulte get_bucket_stat.
Código de exemplo
Use o código a seguir para consultar a capacidade de armazenamento de um bucket.
import argparse
import alibabacloud_oss_v2 as oss
# Create a command-line argument parser to describe that this script is used to obtain statistical information about a specified bucket.
parser = argparse.ArgumentParser(description="Get statistical information about a specified OSS bucket.")
# Add the --region command-line argument, which specifies the region where the bucket is located. This argument is required.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
# Add the --bucket command-line argument, which specifies the name of the bucket for which to obtain statistics. This argument is required.
parser.add_argument('--bucket', help='The name of the bucket to get statistics for.', required=True)
# Add the --endpoint command-line argument, which specifies the domain name that other services can use to access OSS. This argument is optional.
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS.')
def main():
"""
The main function, which is used to parse command-line arguments and obtain statistical information about a specified bucket.
"""
args = parser.parse_args() # Parse command-line arguments.
# Load credentials from environment variables for identity verification.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use the default configurations of the SDK and set the credential provider and region information.
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
# If the endpoint parameter is provided, set the endpoint in the configuration.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Create an OSS client using the configured information.
client = oss.Client(cfg)
# Construct a request to obtain statistical information about the specified bucket.
request = oss.GetBucketStatRequest(bucket=args.bucket)
# Send the request and obtain the response.
result = client.get_bucket_stat(request)
# Print the statistical information in the response.
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' storage: {result.storage},'
f' object count: {result.object_count},'
f' multi part upload count: {result.multi_part_upload_count},'
f' live channel count: {result.live_channel_count},'
f' last modified time: {result.last_modified_time},'
f' standard storage: {result.standard_storage},'
f' standard object count: {result.standard_object_count},'
f' infrequent access storage: {result.infrequent_access_storage},'
f' infrequent access real storage: {result.infrequent_access_real_storage},'
f' infrequent access object count: {result.infrequent_access_object_count},'
f' archive storage: {result.archive_storage},'
f' archive real storage: {result.archive_real_storage},'
f' archive object count: {result.archive_object_count},'
f' cold archive storage: {result.cold_archive_storage},'
f' cold archive real storage: {result.cold_archive_real_storage},'
f' cold archive object count: {result.cold_archive_object_count},'
f' deep cold archive storage: {result.deep_cold_archive_storage},'
f' deep cold archive real storage: {result.deep_cold_archive_real_storage},'
f' deep cold archive object count: {result.deep_cold_archive_object_count},'
f' delete marker count: {result.delete_marker_count},'
)
if __name__ == "__main__":
main() # The script entry point. The main function is called when the file is run directly.
Informações comuns sobre capacidade de armazenamento
|
Parâmetro |
Descrição |
|
Storage |
Capacidade total de armazenamento do bucket. Unidade: bytes. |
|
ObjectCount |
Quantidade total de objetos no bucket. |
|
MultipartUploadCount |
Número de tarefas de upload multipart iniciadas, mas não concluídas ou abortadas no bucket. |
|
LiveChannelCount |
Total de LiveChannels no bucket. |
|
LastModifiedTime |
Momento em que as informações de armazenamento foram obtidas nesta chamada. O valor é um timestamp UNIX. Unidade: segundos. |
|
StandardStorage |
Capacidade de armazenamento de objetos Standard. Unidade: bytes. |
|
StandardObjectCount |
Quantidade de objetos Standard. |
|
InfrequentAccessStorage |
Capacidade de armazenamento faturável de objetos Infrequent Access (IA). Unidade: bytes. |
|
InfrequentAccessRealStorage |
Capacidade real de armazenamento de objetos IA. Unidade: bytes. |
|
InfrequentAccessObjectCount |
Quantidade de objetos IA. |
|
ArchiveStorage |
Capacidade de armazenamento faturável de objetos Archive Storage. Unidade: bytes. |
|
ArchiveRealStorage |
Capacidade real de armazenamento de objetos Archive Storage. Unidade: bytes. |
|
ArchiveObjectCount |
Quantidade de objetos Archive Storage. |
|
ColdArchiveStorage |
Capacidade de armazenamento faturável de objetos Cold Archive. Unidade: bytes. |
|
ColdArchiveRealStorage |
Capacidade real de armazenamento de objetos Cold Archive. Unidade: bytes. |
|
ColdArchiveObjectCount |
Quantidade de objetos Cold Archive. |
Referências
Para obter o código de exemplo completo, consulte get_bucket_stat.py.