Query aggregated data with GraphQL
Total the bytes your applications sent per time bucket with an aggregated GraphQL API query to the metrics endpoint, from curl or any HTTP client.
You can read totals over time from the GraphQL API with an aggregated query, sent from curl or any other HTTP client.
Aggregated data is request data that the metrics endpoint stores grouped into time buckets. An aggregated query applies a function, such as sum, to one field and returns one row per group. For the rules of an aggregated query, refer to Queries. The example below reads the workloadMetrics dataset. The httpMetrics dataset is deprecated and returns the same rows; use workloadMetrics. For the datasets of each endpoint, refer to Features.
Prerequisites
- A personal token. To create one, refer to How to manage a personal token.
- An application on Applications that received requests during the time window you query.
curl, or another HTTP client that sendsPOSTrequests. To run a query from the GraphiQL Playground instead, refer to the GraphQL API quickstart.
Total the bytes sent per time bucket
This query adds up bytesSent, the bytes sent to clients, for each time bucket of a seven-day window. To run it:
Set begin and end in tsRange to the window you want to read, in the YYYY-MM-DDTHH:mm:ss format:
Send the query in the query key of a JSON body to https://api.azion.com/v4/metrics/graphql. Replace [TOKEN VALUE] with your personal token:
The API answers 200 with 10 rows. The response below is cut after its first three rows:
Each row holds the start of a time bucket in ts, in UTC, and the bytes sent during it in sum, oldest bucket first. For a seven-day window, the buckets are one hour long, and an hour with no requests returns no row. The length of the window sets the bucket size, as How the GraphQL API works describes. An empty workloadMetrics array means that no request matched the window.
Three arguments shape the result:
| Argument | In the example | What it does |
|---|---|---|
aggregate | {sum: bytesSent} | Applies the sum function to the bytesSent field. The result comes back in a field named after the function, sum. |
groupBy | [ts] | Returns one row per value of the listed fields. [ts] returns one row per time bucket. Without groupBy, the response holds one row with the total of the whole window. |
orderBy | [ts_ASC] | Sorts the rows by a field and a direction suffix. ts_ASC lists the oldest bucket first, ts_DESC the latest first, and sum_DESC the highest total first. |
To total another field, replace bytesSent in aggregate, such as with requestTime or requests. For the fields that each function accepts, refer to Queries.