11

我正在使用谷歌云存储。我在哪里可以确定我使用的总空间?我似乎无法在仪表板中找到它告诉您以兆字节或千兆字节为单位的总使用量。

仪表板屏幕截图

4

4 回答 4

6

您现在可以通过 Stackdriver Metrics Explorer 获得所需的内容,转到 Stackdriver -> Resources -> Metrics Explorer -> 在 Find resource type and metric entry 字段下选择“Total bytes”或输入“storage.googleapis.com/storage/total_bytes”并单击出现的那个。然后它将向您显示项目中所有存储桶的使用情况。

于 2019-01-23T22:37:03.963 回答
4

您是否安装了gsutil命令行实用程序?如果是这样,您可以使用该gsutil du命令查看用于对象和存储桶的空间。

例如,gsutil du -s gs://my-bucket-name/应该工作。

https://cloud.google.com/storage/docs/gsutil/commands/du

于 2015-10-12T14:47:16.123 回答
3

正如du - 显示对象大小使用中所解释的,我们可以使用gsutil命令

gsutil -o GSUtil:default_project_id=[PROJECT-ID] du -shc

它将像这样显示每个桶的所有空间和使用的总空间

24.18 MiB    gs://appspot.[PROJECT-ID].com
687.46 MiB   gs://artifacts.[PROJECT-ID].appspot.com
947 B        gs://[PROJECT-ID]_cloudbuild
252.55 MiB   gs://staging.[PROJECT-ID].appspot.com
9.36 GiB     gs://us.artifacts.[PROJECT-ID].appspot.com
10.3 GiB     total

注意如果你得到"ImportError: No module named google_compute_engine"请参考这个问题。可以通过在运行export BOTO_CONFIG=/dev/null前运行来解决gsutil

于 2019-04-13T07:02:41.040 回答
0

您还可以通过 API 获取此信息,例如在此 python 示例中:

import os
from google.cloud import storage

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "/path/to/my/credentials.json"
bucket_name = "my-bucket-name"
storage_client = storage.Client()
bytes_used = sum(
    [blob.size for blob in storage_client.list_blobs(bucket_name)]
)
print(
    f"{bucket_name} is using {bytes_used/1048576:0.3f} MiB."
)
于 2022-01-13T17:29:28.303 回答