1 of 20
2 of 20
3 of 20
4 of 20
5 of 20
6 of 20
7 of 20
8 of 20
9 of 20
10 of 20
11 of 20
12 of 20
13 of 20
14 of 20
15 of 20
16 of 20
17 of 20
18 of 20
19 of 20
20 of 20

doc

How to query aggregated data with GraphQL API

Aggregated data can also be considered as structured data that have been clustered. They go through modifications to allow a better analytic processing seeking a segmented analysis.

To query the available aggregated data in the GraphQL API, you need to go through two steps: create a personal token and run your request on Postman. See the next sections and follow the presented steps.

  1. Creating a personal token
  2. Querying aggregated data with Postman

Creating a personal token

Before running your requests with the GraphQL API, you first need to create a personal token to validate your access.

  1. On Real-Time Manager (RTM), select Account menu > Personal Tokens.
  2. Fill the fields to configure the personal token and click the Create Token button.
  3. Copy and save your token in a safe location to use it in the next section.

See the Personal Tokens documentation for more information on how to create one.

As an alternative, you can create a short-duration token through the Azion API.


Querying aggregated data with Postman

After creating your personal token, go to Postman and follow the next steps:

  1. On the header, click the + button to create a new request.
  2. On the Headers tab, click on Bulk Edit and add the following code, replacing [TOKEN VALUE] with the personal token value you created:
Authorization:Token [TOKEN VALUE]

Remain on Postman and create the request’s body:

  1. Select the Body tab.
  2. On the upper-left corner, click the GET option to open a dropdown menu.
  3. Select the POST option.
  4. On the options row, select the GraphQL option.
  5. On the QUERY box, add the following Aggregated Query:
query HttpQuery {
  httpMetrics(
    limit: 10,
    filter: {
      tsRange: {begin:"2022-03-21T10:10:10", end:"2022-06-23T10:10:10"}
    }
    aggregate: {sum: bytesSent}
    groupBy: [ts]
    orderBy: [ts_ASC]
  )
  {
    ts
    sum
  }
}

On the example above, you’ll query for an aggregated table of the HTTP dataset. Furthermore, the sum operator was used to request the aggregated data with information regarding the bytesSent field in a set range of time period, informed through the tsRange field.

Lastly, the presented data were grouped and ordered through the ts (timestamp) field.

To query aggregated data, it’s mandatory to inform:

  • A time range interval for queries, using either tsRange or tsGt + tsLt.
  • The fields whose information you want to group, using groupBy.
  • Which consulted data should be exhibited. On the presented example, the ts and sum fields were used, in which sum represents the response of the bytesSent aggregation.

To aggregate information made available through the GraphQL API as in the presented example, there are a few options that you must inform through the aggregate field in your query. They are:

  • Count: determines the total value of records meeting a specific condition.
  • Sum: returns the sum of the entry values of a column or expression.
  • Max: returns the maximum value of a determined field of a table according to the established selection criteria.
  • Min: returns the minimum value of a determined field of a table according to the established selection criteria.
  • Avg: calculates the arithmetic mean of a set of values in a specific field being consulted.
  • Rate: used for the imagesProcessed dataset. Obtains the rate of images being processed by second while using Image Processor.

You can run a request with one of each of the available options: count, sum, max, min, avg, and rate, as long as each option is only used once and each operator aggregates only one dataset field at a time. See the following example:

aggregate: {
    count: rows, 
    sum: bytesSent, 
    avg: requestTime, 
    max: requestLength,
    min: missedData,
    rate: requestTime
}

Now that you’ve query your request, you can send it to the GraphQL API and receive a response with the data. To send it to the API:

  1. On the Enter URL or paste text field, add the URL being queried: https://api.azionapi.net/metrics/graphql
  2. Click the Send button on the upper-right corner.

You’ll receive a response with the requested data, as in the following example:

{
   "data": {
       "httpMetrics": [
           {
               "ts": "2022-06-09T21:33:13",
               "sum": 1471.0
           },
           {
               "ts": "2022-06-09T21:33:14",
               "sum": 1471.0
           },
           {
               "ts": "2022-06-09T21:33:15",
               "sum": 1471.0
           }
       ]
   }
}

The GraphQL API returned the aggregated data with the sum operator for the bytesSent field, according to the query informed in the request.

For more information on aggregating data with the GraphQL API, visit the datasets documentation page.


Didn’t find what you were looking for? Open a support ticket.