Before we can jump into querying the telemetry let us quickly recap what time series and aggregations are.
Imagine you wanted to know how the temperature outside changes throughout the day. Once every hour, you would check the thermometer and write down the time along with the current temperature. After a while, you would have something like this:
Temperature data like this is one example of what we call a time series — a sequence of measurements, ordered in time. Every row in the table represents one individual measurement at a specific time.
Tables are useful when you want to identify individual measurements, but they make it difficult to see the big picture. A more common visualization for time series is the graph, which instead places each measurement along a time axis. Visual representations like the graph make it easier to discover patterns and features of the data that otherwise would be difficult to see.
Depending on what you are measuring, the data can vary greatly. What if you wanted to compare periods longer than the interval between measurements? If you would measure the temperature once every hour, you would end up with 24 data points per day. To compare the temperature in August over the years, you would have to combine the 31 times 24 data points into one.
Combining a collection of measurements is called aggregation. There are several ways to aggregate time series data. Here are some common ones:
- Average returns the sum of all values divided by the total number of values.
- Min and Max return the smallest and largest value in the collection.
- Sum returns the sum of all values in the collection.
- Count returns the number of values in the collection.
For example, by aggregating the data in a month, you can determine that August 2017 was, on average, warmer than the year before. Instead, to see which month had the highest temperature, you would compare the maximum temperature for each month.
How you choose to aggregate your time series data is an important decision and depends on the story you want to tell with your data. It is common to use different aggregations to visualize the same time series data in different ways.
The explanation above is based on Grafana docs. Check them out if you would like to learn more about data visualization and analysis.