Cloudflare Docs
R2
Edit this page
Give us feedback
Set theme to dark (⇧+D)

Metrics and analytics

R2 exposes analytics that allow you to inspect the requests and storage of the buckets in your account.

The metrics displayed for a bucket in the Cloudflare dashboard are queried from Cloudflare’s GraphQL Analytics API. You can access the metrics programmatically via GraphQL or HTTP client.

​​ Metrics

R2 currently has two datasets:

Dataset
GraphQL Dataset Name
Description
Operationsr2OperationsAdaptiveGroupsThis dataset consists of the operations taken buckets of an account.
Storager2StorageAdaptiveGroupsThis dataset consists of the storage of buckets an account.

​​ Operations Dataset

Field
Description
actionTypeThe name of the operation performed.
actionStatusThe status of the operation. Can be success, userError, or internalError.
bucketNameThe bucket this operation was performed on if applicable. For buckets with a jurisdiction specified, you must include the jurisdiction followed by an underscore before the bucket name. For example: eu_your-bucket-name
objectNameThe object this operation was performed on if applicable.
responseStatusCodeThe http status code returned by this operation.
datetimeThe time of the request.

​​ Storage Dataset

Field
Description
bucketNameThe bucket this storage value is for. For buckets with a jurisdiction specified, you must include the jurisdiction followed by an underscore before the bucket name. For example: eu_your-bucket-name
payloadSizeThe size of the objects in the bucket.
metadataSizeThe size of the metadata of the objects in the bucket.
objectCountThe number of objects in the bucket.
uploadCountThe number of pending multipart uploads in the bucket.
datetimeThe time that this storage value represents.

Metrics can be queried (and are retained) for the past 31 days. These datasets require an accountTag filter with your Cloudflare account ID.

​​ View via the dashboard

Per-database analytics for R2 are available in the Cloudflare dashboard. To view current and historical metrics for a database:

  1. Log in to the Cloudflare dashboard and select your account.
  2. Go to the R2 tab and select your bucket.
  3. Select the Metrics tab.

You can optionally select a time window to query. This defaults to the last 24 hours.

​​ Query via the GraphQL API

You can programmatically query analytics for your R2 databases via the GraphQL Analytics API. This API queries the same dataset as the Cloudflare dashboard, and supports GraphQL introspection.

​​ Examples

​​ Operations

To query the volume of each operation type on a bucket for a given time period you can run a query as such

query {
viewer {
accounts(filter: { accountTag: $accountId }) {
r2OperationsAdaptiveGroups(
limit: 10000
filter: {
datetime_geq: $startDate
datetime_leq: $endDate
bucketName: $bucketName
}
) {
sum {
requests
}
dimensions {
actionType
}
}
}
}
}

The bucketName field can be removed to get an account level overview of operations. The volume of operations can be broken down even further by adding more dimensions to the query.

​​ Storage

To query the storage of a bucket over a given time period you can run a query as such.

query {
viewer {
accounts(filter: { accountTag: $accountId }) {
r2StorageAdaptiveGroups(
limit: 10000
filter: {
datetime_geq: $startDate
datetime_leq: $endDate
bucketName: $bucketName
}
orderBy: [datetime_DESC]
) {
max {
objectCount,
uploadCount,
payloadSize,
metadataSize
}
dimensions {
datetime
}
}
}
}
}