【问题标题】:Google Cloud Storage: How Much Total Space Am I Using?谷歌云存储:我使用了多少总空间?
【发布时间】:2016-01-10 00:43:47
【问题描述】:

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

【问题讨论】:

    标签: google-cloud-storage dashboard google-cloud-platform google-cloud-console


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • Eeks...没有办法在仪表板中看到它?如果非程序员可以看到我们使用了多少空间,那就太好了。
      • @speedplane - 感谢您的反馈,我已将其传递给团队。同时也可以在控制台点击Google Cloud Shell按钮运行命令,这样就不用在本地安装gcloud了。
      • 能够看到仪表板上正在使用的空间量真的很有用 - 我有点惊讶它已经不可能添加到仪表板上
      • 这对于大桶不实用。另一个答案虽然需要更多步骤,但对于包含大量文件的存储桶更有用。
      • 仍然缺少在仪表板中查看总存储空间的功能。
      【解决方案3】:

      正如du - Display object size usage 中所述,我们可以使用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",请参阅此issue。可以通过在运行gsutil之前运行export BOTO_CONFIG=/dev/null来解决。

      【讨论】:

        【解决方案4】:

        您还可以通过 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."
        )
        

        【讨论】:

          猜你喜欢
          • 2020-09-10
          • 1970-01-01
          • 2016-10-12
          • 1970-01-01
          • 2020-04-18
          • 1970-01-01
          • 2015-06-23
          • 2012-03-02
          相关资源
          最近更新 更多