This page shows you how get information on the size and metadata of your Cloud Storage buckets.
Required permissions
Console
In order to complete this guide using the Google Cloud console, you must have the proper IAM permissions. If you did not create the bucket you want to access, you might need the project owner to give you a role that contains the necessary permissions.
For a list of permissions required for specific actions, see IAM permissions for the Google Cloud console.
For a list of relevant roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
Command line
In order to complete this guide using a command-line utility, you must have the proper IAM permissions. If you did not create the bucket you want to access, you might need the project owner to give you a role that contains the necessary permissions.
For a list of permissions required for specific actions, see IAM permissions for gsutil commands.
For a list of relevant roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
Client libraries
In order to complete this guide using the Cloud Storage client libraries, you must have the proper IAM permissions. If you did not create the bucket you want to access, you might need the project owner to give you a role that contains the necessary permissions.
Unless otherwise noted, client library requests are made through the JSON API and require permissions as listed in IAM permissions for JSON methods. To see which JSON API methods are invoked when you make requests using a client library, log the raw requests.
For a list of relevant IAM roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
REST APIs
JSON API
In order to complete this guide using the JSON API, you must have the proper IAM permissions. If you did not create the bucket you want to access, you might need the project owner to give you a role that contains the necessary permissions.
For a list of permissions required for specific actions, see IAM permissions for JSON methods.
For a list of relevant roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
Determine a bucket's size
Console
To use Metrics Explorer to view the metrics for a monitored resource, follow these steps:
- In the Google Cloud console, go to the Metrics Explorer page within Monitoring.
- In the toolbar, select the Explorer tab.
- Select the Configuration tab.
- Expand the Select a metric menu, enter
Total bytes
in the filter bar, and then use the submenus to select a specific resource type and metric:- In the Active resources menu, select GCS Bucket.
- In the Active metric categories menu, select Storage.
- In the Active metrics menu, select Total bytes.
- Click Apply.
- Optional: To configure how the data is viewed, add filters and use the Group By, Aggregator, and chart-type menus. For example, you can group by resource or metric labels. For more information, see Select metrics when using Metrics Explorer.
- Optional: Change the graph settings:
- For quota and other metrics that report one sample per day, set the time frame to at least one week and set the plot type to Stacked bar chart.
- For distribution valued metrics, set the plot type to Heatmap chart.
You can also use the Metrics Explorer to measure other bucket metrics such as storage.googleapis.com/storage/object_count and storage.googleapis.com/storage/total_byte_seconds, which measure the daily number of objects and the daily storage consumed, respectively. See the Google Cloud metrics documentation for a complete list of available metrics and Metrics, time series, and resources for more information about using the Metrics Explorer.
Command line
Use the gsutil du
command with a -s
flag:
gsutil du -s gs://BUCKET_NAME
where BUCKET_NAME
is the name of the relevant
bucket.
The response looks like the following example:
134620 gs://my-bucket
In this example, the size of the bucket named my-bucket
is 134,620 bytes.
Display a bucket's metadata
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
In the bucket list, click the name of the bucket whose metadata you want to view.
Click the Configuration tab to view bucket details such as the included regions, storage class, permissions, and replication type.
Command line
Use the following gsutil ls
command:
gsutil ls -L -b gs://BUCKET_NAME
where BUCKET_NAME
is the name of the relevant
bucket.
The response looks like the following example:
gs://my-bucket/ : Storage class: STANDARD Location type: multi-region Location constraint: US ...
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
For more information, see the
Cloud Storage C# API
reference documentation.
For more information, see the
Cloud Storage Go API
reference documentation.
For more information, see the
Cloud Storage Java API
reference documentation.
For more information, see the
Cloud Storage Node.js API
reference documentation.
For more information, see the
Cloud Storage PHP API
reference documentation.
For more information, see the
Cloud Storage Python API
reference documentation.
For more information, see the
Cloud Storage Ruby API
reference documentation.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
Terraform
You can use a Terraform resource to view a bucket's metadata.
REST APIs
JSON API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials. For instructions, see API authentication.
Use
cURL
to call the JSON API with aGET
Bucket request:curl -X GET \ -H "Authorization: Bearer OAUTH2_TOKEN" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME"
Where:
OAUTH2_TOKEN
is the name of the access token you generated in Step 1.BUCKET_NAME
is the name of the relevant bucket. For example,my-bucket
.
Optionally, you can narrow down the metadata results by using the
fields
query string parameter. For example:curl -X GET \ -H "Authorization: Bearer OAUTH2_TOKEN" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?fields=FIELD1%2CFIELD2"
Where
FIELD#
is a bucket property you want to include in the result. For example,location
andstorageClass
.
The response looks like the following example:
{ "location": "US", "storageClass": "STANDARD" }
XML API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials. For instructions, see API authentication.
Use
cURL
to call the XML API with aGET
Bucket request:curl -X GET \ -H "Authorization: Bearer OAUTH2_TOKEN" \ "https://storage.googleapis.com/BUCKET_NAME?QUERY_PARAMETER"
Where:
OAUTH2_TOKEN
is the name of the access token you generated in Step 1.BUCKET_NAME
is the name of the relevant bucket. For example,my-bucket
.QUERY_PARAMETER
is the metadata field you want to return. For example,location
for getting the location of the bucket. You can only use one query parameter at a time with the XML API. For a list of metadata fields supported by the XML API, see theGET
Bucket reference page.
The response looks like the following example:
<LocationConstraint>US</LocationConstraint>
.
What's next
- Read the bucket metadata overview.
- List the objects in your bucket.
- Change the default storage class for your bucket.
- Add, remove, and view the labels on your bucket.
- Learn more about monitoring your resources in Monitoring.
Try it for yourself
If you're new to Google Cloud, create an account to evaluate how Cloud Storage performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
Try Cloud Storage free