Skip to content

Metrics Dashboard

Temp edited this page Feb 11, 2026 · 3 revisions

Metrics Dashboard

The Metrics Dashboard provides comprehensive analytics for your D1 databases, powered by the Cloudflare GraphQL Analytics API.

Overview

The Metrics Dashboard features two tabs:

Overview Tab

  • πŸ“Š Query Volume - Total reads and writes across all databases
  • ⏱️ Latency - Average P90 query latency
  • πŸ“ˆ Rows Read - Total rows read (important for billing visibility)
  • πŸ’Ύ Storage - Total storage used across databases
  • πŸ“‰ Trend Charts - Query volume and rows read over time
  • πŸ“‹ Per-Database Breakdown - Detailed metrics for each database

Query Insights Tab

  • πŸ” Slow Query Analysis - Identify and optimize slow queries
  • πŸ“Š Performance Summary - Critical, Moderate, and Fast query counts
  • πŸ“‹ Sortable Table - Sort by total time, avg time, count, or rows read
  • πŸ“ Query Details - View full SQL and detailed metrics

Accessing the Dashboard

  1. Click the Metrics tab in the main navigation
  2. Select a time range (24h, 7d, or 30d)
  3. View summary cards and trend charts

Dashboard Components

Summary Cards

Four cards at the top provide key metrics at a glance:

Card Description
Total Queries Combined read and write queries
Rows Read Total rows read across all databases
Avg P90 Latency 90th percentile query latency
Total Storage Combined storage for all databases

Time Range Selector

Choose the time range for your metrics:

Range Description Best For
Last 24 Hours Hourly granularity Recent activity monitoring
Last 7 Days Daily granularity Weekly trends
Last 30 Days Daily granularity Monthly planning

Query Volume Chart

An SVG-based line chart showing:

  • Read Queries (blue line) - SELECT operations
  • Write Queries (orange line) - INSERT/UPDATE/DELETE operations

Hover over data points to see exact values and timestamps.

Rows Read Chart

A separate chart tracking rows read over time, useful for:

  • Monitoring query efficiency
  • Planning for billing (D1 charges based on rows read)
  • Identifying usage spikes

Per-Database Breakdown

Horizontal bar charts showing metrics for each database:

  • Query count comparison
  • Relative usage visualization
  • Quick identification of high-traffic databases

Detailed Metrics Table

A sortable table with columns for:

  • Database name
  • Read count
  • Write count
  • Rows read
  • Storage size
  • P90 latency

Caching

The Metrics Dashboard uses client-side caching for performance:

  • Cache Duration: 2 minutes per time range
  • Cache Key: Time range (24h, 7d, 30d)
  • Refresh: Click the refresh button to bypass cache

The shorter TTL (2 minutes vs 5 minutes for other features) reflects the more dynamic nature of metrics data.

Query Insights

The Query Insights tab provides slow query analysis powered by Cloudflare's d1QueriesAdaptiveGroups GraphQL Analytics API.

Performance Summary Cards

Three summary cards show query distribution by performance:

Card Criteria Description
Critical πŸ”΄ >100ms avg Queries needing immediate optimization
Moderate 🟑 50-100ms avg Queries that could benefit from optimization
Fast 🟒 <50ms avg Well-performing queries

Slow Query Table

A sortable table lists your queries with these columns:

Column Description
Query The SQL query string (truncated, expandable)
Total Time Cumulative execution time
Avg Time Average execution time per query
Count Number of times the query was executed
Rows Read Total rows read by the query

Click any column header to sort. Click a row to expand and see:

  • Full SQL query
  • Rows written
  • Detailed execution metrics

Performance Badges

Queries are tagged with performance badges:

  • πŸ”΄ CRITICAL - Average time >100ms
  • 🟑 WARNING - Average time 50-100ms
  • 🟒 GOOD - Average time <50ms

Optimization Tips

For slow queries identified in Query Insights:

  1. Add Indexes: Use the Index-Analyzer to find missing indexes
  2. Limit Results: Add LIMIT clauses to paginated queries
  3. Filter Early: Add WHERE clauses to reduce rows scanned
  4. Avoid SELECT *: Only select columns you need
  5. Use Covering Indexes: Include all needed columns in the index

API Reference

Get Metrics

GET /api/metrics?range=24h|7d|30d

Query Parameters:

Parameter Type Default Description
range string 24h Time range: 24h, 7d, or 30d

Response:

{
  "success": true,
  "result": {
    "summary": {
      "totalQueries": 125000,
      "totalReads": 100000,
      "totalWrites": 25000,
      "totalRowsRead": 5000000,
      "avgLatencyP90": 15.5,
      "totalStorage": 52428800
    },
    "timeSeries": [
      {
        "timestamp": "2025-12-05T00:00:00Z",
        "reads": 4500,
        "writes": 1200,
        "rowsRead": 225000
      }
    ],
    "databases": [
      {
        "databaseId": "uuid-...",
        "databaseName": "my-database",
        "reads": 50000,
        "writes": 12500,
        "rowsRead": 2500000,
        "storage": 26214400,
        "latencyP90": 12.3
      }
    ]
  }
}

Understanding the Metrics

Query Volume

  • Reads: SELECT queries that retrieve data
  • Writes: INSERT, UPDATE, DELETE, and schema modification queries
  • High read/write ratios are typical for most applications
  • Sudden spikes may indicate issues or new features

Rows Read

D1 billing is based on rows read, so monitoring this metric helps:

  • Predict monthly costs
  • Identify inefficient queries
  • Optimize database access patterns

Tips to reduce rows read:

  • Use appropriate indexes
  • Add WHERE clauses to limit results
  • Use LIMIT for paginated queries
  • Avoid SELECT * when possible

Latency

The P90 latency represents the 90th percentile query time:

  • Values under 10ms are excellent
  • 10-50ms is typical for D1
  • Values over 100ms may indicate issues

High latency causes:

  • Missing indexes
  • Complex queries
  • Large result sets
  • Network issues

Storage

Storage includes:

  • Table data
  • Index data
  • SQLite overhead

D1 storage is charged per GB, so monitor growth over time.

Accessibility

The Metrics Dashboard is designed with accessibility in mind:

  • Screen Reader Support: ARIA labels on all interactive elements
  • Keyboard Navigation: Full keyboard accessibility
  • Color Contrast: WCAG-compliant colors for charts
  • Text Alternatives: Data tables available alongside charts

Best Practices

Regular Monitoring

  • Check metrics daily for production databases
  • Set up alerts for unusual activity (via webhooks)
  • Review weekly trends for capacity planning

Cost Optimization

  • Monitor rows read trends
  • Optimize high-read queries with indexes
  • Use caching where appropriate
  • Consider read replicas for global distribution

Performance Optimization

  • Watch for latency increases
  • Use the Index Analyzer for recommendations
  • Run ANALYZE (Optimize) after bulk operations

Troubleshooting

"Failed to load metrics"

Causes:

  • GraphQL API temporarily unavailable
  • Invalid time range parameter
  • Network connectivity issue

Solutions:

  1. Try refreshing the page
  2. Check Cloudflare status page
  3. Verify API credentials are correct

Metrics Not Updating

Causes:

  • Data is cached (2 minute TTL)
  • GraphQL API delay (up to 5 minutes)

Solutions:

  1. Click the refresh button
  2. Wait a few minutes for data propagation

Missing Databases

Causes:

  • Database was just created (metrics take time to appear)
  • Database has no activity in selected time range

Solutions:

  1. Try a longer time range
  2. Run a query on the database to generate activity

Related Documentation


Need Help? See Troubleshooting or open an issue.

Clone this wiki locally