Query Data Stream usage data
Read the usage that Data Stream accounts on your account, per workload and metric, with a GraphQL query to the Azion consumption API.
You can query the usage that Data Stream accounts on your account with the Azion GraphQL API. To check the sends of a stream and the status code of each one instead, refer to How Data Stream works.
The workloadConsumptionMetrics dataset aggregates the usage accounted for each Azion product, Data Stream included, and keeps it for up to 24 months. The consumption endpoint serves it at https://api.azion.com/v4/consumption/graphql. To compare the totals with what your plan includes, refer to Data Stream limits.
Prerequisites
- A stream that sent logs during the period you query. To create one, refer to the Data Stream quickstart.
- A personal token. To create one, refer to How to manage a personal token.
curl.
Query the usage of Data Stream
The query filters the dataset on the product ID of Data Stream, 1498670028, and on its two metrics, data_streamed and requests. It sums the accounted usage for each workload and metric:
The query uses these arguments:
tsRangesets the period, withbeginandendin theYYYY-MM-DDTHH:mm:ssformat.productIdkeeps the usage of Data Stream only.metricNameIntakes a list of metrics. To read one metric, usemetricNamewith one string, such asmetricName: "data_streamed".sum: accountedadds up the usage accounted for the events that match the filter, for each group.limitcaps the number of rows. The maximum is10000.groupByreturns one row for each combination of client, workload, product, and metric.
To send the query, make a POST request to the consumption endpoint. Replace [TOKEN VALUE] with your personal token, and the dates with your own:
On an account with no Data Stream usage accounted in the period, the API answers 200 with an empty list:
An empty list means that no usage of Data Stream matches the filter in that period. When usage exists, each row carries these fields:
clientId: the identifier of your account on Azion.workloadId: the workload the usage belongs to.productId:1498670028, the product ID of Data Stream.metricName:data_streamedorrequests.total: fordata_streamed, the data that Data Stream sent for the workload, in bytes. Forrequests, the number of requests processed.
To see how much data your streams sent for each workload, read the total of the data_streamed rows. A list in metricName fails with 400 and Expected type "String". Use metricNameIn for a list.
You can also paste the query into the GraphiQL Playground at https://api.azion.com/v4/consumption/graphql, signed in to your Azion account. For every field of the dataset, refer to Consumption GraphQL fields.
Check an empty result
An empty list can also come from a wrong period or a filter that matches nothing. To confirm that the dataset returns usage for your account, query it without the product and metric filters. This query groups one day of usage by product and metric:
The API answers 200 with one row for each product and metric that has accounted usage:
Rows for other products, with none that carries 1498670028, mean that the token and the dataset work and that the account has no Data Stream usage accounted that day. If this query also returns an empty list, the account has no usage accounted in that period.