Metrics and analytics
D1 exposes database analytics that allow you to inspect query volume, response size, and query latency across all and/or each database in your account.
The metrics displayed in the Cloudflare dashboard charts are queried from Cloudflare’s GraphQL Analytics API. You can access the metrics programmatically via GraphQL or HTTP client.
Metrics
D1 currently exports the below metrics:
Metric | GraphQL Field Name | Description |
---|---|---|
Read Queries (qps) | readQueries | The number of read queries issued against a database. This is the raw number of read queries, and is not used for billing. |
Write Queries (qps) | writeQueries | The number of write queries issued against a database. This is the raw number of write queries, and is not used for billing. |
Rows read (count) | rowsRead | The number of rows read (scanned) across your queries. See Pricing for more details on how rows are counted. |
Rows written (count) | rowsWritten | The number of rows written across your queries. |
Query Response (bytes) | queryBatchResponseBytes | The total response size of the serialized query response, including any/all column names, rows and metadata. Reported in bytes. |
Query Latency (ms) | queryBatchTimeMs | The total query response time, including response serialization, on the server-side. Reported in milliseconds. |
Metrics can be queried (and are retained) for the past 31 days.
Row counts
D1 returns the number of rows read, rows written (or both) in response to each individual query via the client API.
Row counts are a precise count of how many rows were read (scanned) or written by that query. Inspect row counts to understand the performance and cost of a given query, including whether you can reduce the rows read using indexes. Use query counts to understand the total volume of traffic against your databases and to discern which databases are actively in-use.
Refer to the Pricing documentation for more details on how rows are counted.
View via the dashboard
Per-database analytics for D1 are available in the Cloudflare dashboard. To view current and historical metrics for a database:
- Log in to the Cloudflare dashboard and select your account.
- Go to Workers & Pages > D1.
- Select an existing database.
- 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 D1 databases via the GraphQL Analytics API. This API queries the same dataset as the Cloudflare dashboard, and supports GraphQL introspection.
D1’s GraphQL dataset is d1AnalyticsAdaptiveGroups
and requires an accountTag
filter with your Cloudflare account ID.
Examples
To query the sum of readQueries
, writeQueries
for a given $databaseId
, grouping by databaseId
and date
:
query {viewer {accounts(filter: { accountTag: $accountId }) {d1AnalyticsAdaptiveGroups(limit: 10000filter: {date_geq: $startDatedate_leq: $endDatedatabaseId: $databaseId}orderBy: [date_DESC]) {sum {readQuerieswriteQueries}dimensions {datedatabaseId}}}}}
To query both the average queryBatchTimeMs
and the 90th percentile queryBatchTimeMs
per database:
query {viewer {accounts(filter: { accountTag: $accountId }) {d1AnalyticsAdaptiveGroups(limit: 10000filter: {date_geq: $startDatedate_leq: $endDatedatabaseId: $databaseId}orderBy: [date_DESC]) {quantiles {queryBatchTimeMsP90}dimensions {datedatabaseId}}}}}
To query your account-wide readQueries
and writeQueries
:
query {viewer {accounts(filter: { accountTag: $accountId }) {d1AnalyticsAdaptiveGroups(limit: 10000filter: {date_geq: $startDatedate_leq: $endDatedatabaseId: $databaseId}) {sum {readQuerieswriteQueries}}}}}