gmail_usage_report
Retrieve daily Gmail send and receive counts per domain for a specified number of days. Solves the need to know how much Gmail traffic each domain sent or received on any given day.
Instructions
Daily Gmail send/receive counts per domain (Admin SDK customerUsageReports).
Answers "how much Gmail traffic did this domain send/receive on day X" --
a customer-level daily counter, NOT a per-user or per-message breakdown
(the Reports API has no such thing; login_audit's activity stream is
the per-event alternative for that, at the cost of no volume total).
Each day's fetch is independent: a domain missing the DWD scope reports
one whole-domain error (there is no point retrying days times for
an identical scope failure), but a single date's fetch failing for some
other reason (Google's processing for that day not finished yet is a
known lag on this API family; a transient error) only skips that one
date, recorded in date_errors -- the rest of the window still comes
back. The per-domain result also carries capped -- true if ANY
date's fetch hit the (rare, since a single day's customer report is
normally one record) pagination limit -- so a truncated day's counters
are never mistaken for the complete picture.
Requires the admin.reports.usage.readonly DWD scope, granted PER
SERVICE ACCOUNT CLIENT ID in the Admin console (Security > API controls >
Domain-wide delegation) -- a DIFFERENT scope from
admin.reports.audit.readonly (the one login_audit,
drive_external_sharing, drive_doc_activity,
shared_drive_membership_changes and daily_brief use), even though
both live under the same Admin SDK Reports API. Having one does not
imply the other; grant this one separately.
Read-only: only customerUsageReports().get() is issued, restricted to
the two Gmail counters this tool reports via the API's own parameters
filter (:data:GMAIL_USAGE_PARAMETERS) rather than pulling every
application's counters.
Args:
days: How many days back to report, ending YESTERDAY (not today --
the current day's data is not final until it ends) in the
Reports API's own UTC-8:00/Pacific-Standard-Time date anchor.
Must be 1..:data:MAX_USAGE_REPORT_DAYS -- 0/negative
would otherwise silently return a well-formed, error-free empty
result indistinguishable from "queried correctly, zero Gmail
traffic that window", and an unbounded value drives an unbounded
(domain x date) fan-out (one blocking API call per task, even
though they run concurrently).
domain: Configured [domain.*] section to report on. Default: all
configured domains.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | ||
| domain | No |