Monitoring and Querying K2 Stream Metrics via Cloudflare Dashboard and GraphQL API
Explore how Cloudflare's K2 metrics dashboard and GraphQL Analytics API enable detailed monitoring of stream production, consumption, storage, and subscription lag.

Introduction to K2 Metrics in Cloudflare Ecosystem
Cloudflare has introduced comprehensive monitoring capabilities for K2 streams, accessible both through its dashboard and a GraphQL Analytics API. These metrics provide visibility into the performance and health of data streams, including production and consumption rates, storage usage, and subscription lag. This development enhances operational insight for teams managing real-time data pipelines.
The K2 metrics are designed to track how fast records are produced and consumed, how much data each stream stores, and how far behind each subscription is in processing records. This level of granularity is crucial for maintaining data integrity and ensuring timely processing in event-driven architectures.
The availability of these metrics in both a user-friendly dashboard and a programmable API caters to different user needs. Dashboard users can visually monitor streams, while developers and data engineers can integrate these metrics into custom monitoring or alerting systems via the API. This dual approach supports both operational and programmatic workflows.
Dashboard Metrics Overview and Navigation
Within the Cloudflare dashboard, users can navigate to the K2 Streams page to select individual streams for monitoring. The dashboard organizes metrics into three main views: Overview, Metrics, and Subscription page, each offering different insights into stream performance.
The Overview page provides high-level metrics such as produce and consume rates over the last five minutes, stored bytes, and subscription-specific data like records behind, oldest unread record, lag over the last hour, and bytes consumed. This snapshot helps quickly assess stream health and identify potential bottlenecks.
The Metrics page offers detailed charts showing bytes produced by input source, bytes stored, and bytes delivered to each subscription over user-defined time ranges. This temporal flexibility allows for trend analysis and capacity planning.
On the Subscription page, users can drill down into individual subscriptions to view records and bytes behind, oldest unread record, consume rate, and charts depicting lag and throughput. This detailed view assists in diagnosing subscription-specific issues that may affect data delivery or processing.
GraphQL Analytics API Beta Datasets for K2 Metrics
The same K2 metrics available in the dashboard are exposed via four beta datasets in the GraphQL Analytics API, enabling programmatic access and integration. These datasets include k2ProduceAdaptiveGroups, k2ConsumeAdaptiveGroups, k2StorageAdaptiveGroups, and k2SubscriptionLagAdaptiveGroups.
k2ProduceAdaptiveGroups tracks bytes produced to a stream by input type, such as HTTP or binding sources. This dataset helps quantify data ingestion volume and source distribution.
k2ConsumeAdaptiveGroups reports bytes delivered to each subscription, providing insight into consumption rates and potential lag in downstream processing.
k2StorageAdaptiveGroups measures the bytes a stream stores, sampled approximately every ten minutes. This metric is essential for monitoring storage utilization and managing retention policies.
k2SubscriptionLagAdaptiveGroups records the number of uncommitted records for a subscription and the age of the oldest uncommitted record in milliseconds. This dataset is critical for understanding processing delays and ensuring subscriptions keep up with the stream.
Querying K2 Metrics with GraphQL: Structure and Permissions
The GraphQL query example provided demonstrates how to retrieve bytes produced by input in five-minute buckets alongside a subscription's current lag. This query aggregates data over a specified time range and filters by account, stream, and subscription identifiers.
To obtain a subscription's full lag, the query's time range must cover the entire stream retention period, which is seven days in the example. Shorter time ranges may omit older uncommitted records, potentially underrepresenting lag.
The query requires an API token with the Account Analytics Read permission, ensuring secure access to sensitive stream metrics. This permission model aligns with best practices for API security and access control.
The query structure uses nested fields and filters to precisely target the desired data, reflecting the flexibility of GraphQL in querying complex datasets. Developers can customize these queries to support monitoring dashboards, alerting systems, or analytics workflows.
Implications for Data Engineering and Stream Monitoring
The introduction of detailed K2 metrics in both dashboard and API form significantly enhances observability for real-time data streams managed on Cloudflare. Data engineers can now monitor ingestion rates, storage consumption, and subscription lag with precision, enabling proactive troubleshooting and capacity planning.
This visibility is particularly important for systems relying on event-driven architectures and streaming data pipelines, where delays or data loss can impact downstream applications and analytics. Subscription lag metrics help identify processing backlogs before they escalate into failures.
From an implementation perspective, integrating the GraphQL Analytics API into existing monitoring and alerting platforms can automate anomaly detection and operational responses. The granularity of metrics supports fine-tuned thresholds and performance baselines.
Practitioners should evaluate their current monitoring setups and consider incorporating these K2 metrics to gain comprehensive insights. Ensuring appropriate API permissions and understanding the retention period are key to effective metric utilization.
Next Steps for Developers and API Consumers
Developers should begin by exploring the K2 Streams page in the Cloudflare dashboard to familiarize themselves with available metrics and visualizations. This hands-on experience aids in identifying key performance indicators relevant to their use cases.
Subsequently, integrating the GraphQL Analytics API into custom tools or workflows allows for automated data collection and analysis. Developers must generate API tokens with the required permissions and construct queries tailored to their monitoring needs.
It is advisable to implement queries that cover the full retention period to capture complete subscription lag data, ensuring accurate assessment of stream health. Additionally, monitoring storage metrics can inform retention and scaling strategies.
Finally, teams should consider establishing alerting mechanisms based on these metrics to promptly detect and respond to anomalies, thereby maintaining stream reliability and performance. Continuous review and adjustment of these metrics will support evolving operational requirements.
Sources and verification
Researched and drafted with AI assistance from the primary sources cited below. Every factual statement is checked automatically against a verbatim passage in its source before publication. No interviews or quotations are fabricated. Read our editorial standards.


