Add new stats subcommands and improve historical stats#1678
Merged
Conversation
Previously, write errors in the JSON and table output paths were logged but silently swallowed. Now they are properly returned to the caller. Also removes an unused service ID parameter from writeBlocksJSON.
Allows filtering historical stats output to a single field (e.g. bandwidth, requests).
Adds `stats aggregate` for viewing cross-service aggregated stats. Supports --from, --to, --by, --region, and --format flags.
Adds `stats usage` for viewing bandwidth/request usage stats. Supports --by-service flag to break down usage per service, and --from, --to, --by, --region, --format flags.
Adds `stats domain-inspector` for viewing domain-level metrics for a Fastly service. Supports service ID/name lookup, time range filtering (RFC3339/Unix), downsampling, domain/datacenter/region filtering, group-by dimensions, pagination, and JSON output.
Adds `stats origin-inspector` for viewing origin-level metrics for a Fastly service. Supports service ID/name lookup, time range filtering (RFC3339/Unix), downsampling, host/datacenter/region filtering, group-by dimensions, pagination, and JSON output.
Reflects the newly added subcommands in the stats help text.
No need to compute the hit rate, the API provides it. Also fixes the --field test cases to use the CLIScenario struct format.
anthony-gomez-fastly
approved these changes
Mar 9, 2026
Contributor
anthony-gomez-fastly
left a comment
There was a problem hiding this comment.
LGTM, if we need a second reviewer for LLM reasons please add them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change summary
This PR adds four new subcommands under stats to expose more of the Fastly stats and metrics APIs through the CLI.
stats aggregateprovides aggregated stats across all services, with the usual time range and region filtering. stats usage shows bandwidth and request usage, with an optional--by-serviceflag to break the numbers down per service.The two inspector commands,
stats domain-inspectorandstats origin-inspector, surface domain-level and origin-level metrics for a specific service.Both accept time ranges as either RFC3339 or Unix timestamps, and support downsampling, datacenter and region filtering, group-by dimensions, pagination via cursors, and JSON output.
This PR also adds a
--fieldflag to the existingstats historicalcommand, allowing output to be filtered to a single stats field like bandwidth or requests.It also fixes a bug where write errors in the output path were silently swallowed instead of being reported back to the caller.
All Submissions:
New Feature Submissions:
Changes to Core Features:
User Impact
Four new commands. Users who previously had to call the API directly for these can now use the CLI.