Querying Magic Transit tunnel bandwidth analytics with GraphQL
In this example, you are going to use the GraphQL Analytics API to query Magic Transit ingress tunnel traffic over a specified time period.
The following API call will request Magic Transit ingress tunnel traffic over a one-hour period and output the requested fields. Be sure to replace <CLOUDFLARE_ACCOUNT_TAG>
with your account ID, <EMAIL>
, <API_KEY>
1 (legacy) or <API_TOKEN>
2 (preferred method) with your API credentials, and adjust the datetime_geq
and datetime_leq
values as needed.
The following example queries for ingress traffic. To query for egress, change the value in the direction filter.
The returned values represent the total bandwidth in bits/second during the five minute interval for a particular tunnel. To use aggregations other than five minutes, make sure that you use the same window for both your metric and date time. For example, to see hourly groups, use bitRateHour
and datetimeHour
.
The result will be in JSON (as requested), so piping the output to jq
will make it easier to read, like in the following example:
-
Refer to Authenticate with a Cloudflare API key for more information. ↩
-
Refer to Configure an Analytics API token for more information on configuration and permissions. ↩