Find the top values with GraphQL
Rank the values of one request field, such as the most requested URIs, by counting the raw request records of the GraphQL API events endpoint.
You can rank the values of one request field by the number of requests that carry each value, such as the most requested URIs. The GraphQL API query counts the raw request records of the events endpoint. To follow a measure over time instead, refer to Query aggregated data with GraphQL.
Prerequisites
- A personal token. To create one, refer to Personal tokens.
- A tool that sends a GraphQL query, such as an HTTP client or the GraphiQL Playground. For the setup, refer to GraphQL API first steps or Run GraphQL queries in Postman.
- An application that received requests in the past seven days. The events endpoint keeps records for about seven days.
Rank the most requested URIs
The query counts the records of workloadEvents, one record per request, for each value of requestUri. It then returns the five values with the highest count. To run it:
Send a POST request to https://api.azion.com/v4/events/graphql with the header Authorization: Token [TOKEN VALUE]. The metrics endpoint does not serve workloadEvents and returns 400 with Cannot query field "workloadEvents" on type "Query".
Paste the query in the request body. Change tsRange to a window inside the past seven days:
Each argument does one part of the ranking:
| Argument | What it does |
|---|---|
filter with tsRange | Sets the time window. A time filter is required: tsRange, or tsGt and tsLt. Without one, the API returns 400 with To execute queries it is mandatory to provide the desired time interval. |
aggregate with count: requestUri | Counts the records. The result comes back in the count field. |
groupBy: [requestUri] | Returns one row per value of requestUri. Without groupBy, the aggregate returns one row with the total for the whole window. |
orderBy: [count_DESC] | Sorts the rows from the highest count to the lowest. |
limit: 5 | Keeps the first five rows. |
The API returns one object per URI, with its request count. This response is cut after the third of its five rows:
The first row of the response holds the most requested URI in the window.
Rank another field
The same query ranks any field that workloadEvents accepts in groupBy. For the top 10 hosts, replace requestUri with host in aggregate, groupBy, and the selected fields, and set limit: 10. For the top status codes, use status the same way.
The fields of workloadEvents are listed on Real-Time Events GraphQL API fields. The other raw datasets of the events endpoint are on Datasets and query arguments.