我有几个数据的PiB嵌套在一个桶下面,它们被分类为:
桶/唯一ID/A,B,C,D
现在,我很好奇如何运行一个查询来理解存储的总字节(例如):
桶/唯一ID/A
对于存储在桶中的每个唯一ID。
最具成本效益的分析方法是什么?
发布于 2022-07-21 00:57:48
您可以通过编程检索桶大小,如下所示:
import sys
from google.cloud import storage
bucket_name = 'qpalzm-bucket'
client = storage.Client()
bytes_used = sum(
[blob.size for blob in client.list_blobs(bucket_name, delimiter='/')]
)
print(
f"{bucket_name} is using {bytes_used/1048576:0.6f} MiB."
)
iterator = client.list_blobs(bucket_name, delimiter='/')
response = iterator._get_next_page_response()
for prefix in response['prefixes']:
iterator2 = client.list_blobs(bucket_name, prefix=prefix, delimiter='/')
response2 = iterator2._get_next_page_response()
if ('prefixes' in response2):
for prefix2 in response2['prefixes']:
bytes_used = sum(
[blob.size for blob in client.list_blobs(bucket_name, prefix=prefix2, delimiter='/')]
)
print(
f"{bucket_name}/{prefix2} is using {bytes_used/1048576:0.6f} MiB."
)
bytes_used = sum(
[blob.size for blob in client.list_blobs(bucket_name, prefix=prefix, delimiter='/')]
)
print(
f"{bucket_name}/{prefix} is using {bytes_used/1048576:0.6f} MiB."
)样本输出:

您还可以使用云监视下的Metrics,在Metrics >FilterResource&Metrocby GCS Bucket Total Bytes上显示项目中所有桶的使用情况。

发布于 2022-07-21 02:34:27
您可以使用gsutil,这是用于此分析的工具。没有比这更快的方法了。
但是,如果需要定期这样做,则可能需要启用桶日志记录:
您可以阅读更多关于它的信息,在这里:https://cloud.google.com/storage/docs/access-logs#delivery
虽然是关于成本的,但它被算作B类操作
https://stackoverflow.com/questions/73029770
复制相似问题