Skip to main content

Combine Time Series Transformation

Introduction

The Combine Time Series transformation is a powerful tool in Grafana that allows you to merge multiple time series into a single combined time series. This transformation is particularly useful when you want to create a unified view of related metrics or when you need to compare data from different sources in a single visualization.

In this guide, you'll learn:

  • What the Combine Time Series transformation does
  • When to use it in your dashboards
  • How to configure it for different scenarios
  • Real-world examples demonstrating its applications

Understanding the Combine Time Series Transformation

What It Does

The Combine Time Series transformation takes multiple time series datasets and combines them into a single time series. This is different from other transformations that might reorganize data while maintaining separate series. With Combine Time Series, the individual series are actually merged into one.

Key Concepts

Before diving into how to use the transformation, let's understand some key concepts:

  1. Time Series: A sequence of data points collected at successive time intervals.
  2. Field: In Grafana, a field represents a specific metric or measurement (like CPU usage, temperature, etc.).
  3. Combine Method: The mathematical or logical approach used to merge values from multiple series into a single value.

When to Use Combine Time Series

This transformation is particularly useful when:

  • You want to calculate an overall metric from multiple related metrics
  • You need to simplify a visualization by showing a single trend line instead of multiple lines
  • You're combining data from multiple sources to create a unified view
  • You want to reduce noise in visualizations with too many series

Configuring the Combine Time Series Transformation

Basic Configuration

To apply the Combine Time Series transformation in Grafana:

  1. Navigate to your dashboard and edit the panel you want to transform
  2. In the panel editor, select the Transform tab
  3. Click the + Add transformation button
  4. Select Combine fields from the dropdown menu

Configuration Options

When configuring the Combine Time Series transformation, you'll need to specify:

  1. Fields to combine: Select the fields from your query results that you want to merge.
  2. Combine method: Choose how you want to combine the values:
    • Sum: Add all values at each timestamp
    • Mean/Average: Calculate the average of all values
    • Min/Max: Take the minimum or maximum value at each timestamp
    • Count: Count the number of series with values at each timestamp

Example Configuration

Here's an example of how to configure this transformation:

jsx
// This represents the configuration object, not actual code you would write
{
transformations: [
{
id: 'seriesToColumns',
options: {
byField: 'Time',
mode: 'combineSeries'
}
}
]
}

Practical Examples

Let's look at some real-world scenarios where the Combine Time Series transformation proves valuable.

Example 1: Calculating Total System Load

Imagine you're monitoring CPU utilization across multiple servers. Instead of showing a line for each server, you can use Combine Time Series to calculate and display the total system load.

Before the transformation, your data might look like:

Series 1: CPU_Server_A [timestamp, value]
Series 2: CPU_Server_B [timestamp, value]
Series 3: CPU_Server_C [timestamp, value]

After applying the transformation with the Sum method:

Combined Series: Total_CPU [timestamp, sum_of_values]

Example 2: Average Response Time Across Microservices

When monitoring a microservice architecture, you might want to see the average response time across all services rather than individual metrics.

Configuration steps:

  1. Query response times from all microservices
  2. Apply the Combine Time Series transformation
  3. Select the Mean method to calculate averages

Example 3: Creating a Health Score

You can combine multiple health indicators into a single "health score" for your system:

jsx
// Sample query to get multiple metrics
const query = `
SELECT
cpu_usage,
memory_utilization,
disk_io_wait,
network_latency
FROM system_metrics
WHERE $__timeFilter(time)
GROUP BY time($__interval)
`;

Then use Combine Time Series with appropriate weights to create a unified health metric.

Common Pitfalls and Solutions

Mismatched Timestamps

When combining time series with different sampling rates or timestamps, Grafana needs to align the data points. This can sometimes lead to interpolation or gaps.

Solution: Ensure your data sources have consistent time intervals or use the "Align fields by time" transformation before combining.

Combining Incompatible Units

Combining metrics with different units (like percentages and absolute values) may produce meaningless results.

Solution: Convert all series to the same unit before combining, or use the "Add field from calculation" transformation to normalize values.

Advanced Techniques

Weighted Combinations

Sometimes you might want to give different weights to different series when combining them. While not directly supported by the transformation, you can:

  1. Use the "Add field from calculation" transformation first to apply weights
  2. Then use Combine Time Series on the weighted fields

Dynamic Thresholds on Combined Series

After combining series, you can apply dynamic thresholds to the resulting series for better alerting:

jsx
// Pseudocode for alert based on combined series
if (combinedSeries.value > threshold) {
sendAlert("Combined metric exceeded threshold");
}

Summary

The Combine Time Series transformation is a powerful tool in Grafana that allows you to merge multiple time series into a single result. This can help simplify your visualizations, create aggregate metrics, and provide a clearer picture of your system's overall behavior.

Key points to remember:

  • Use it when you need to see the overall trend rather than individual metrics
  • Choose the appropriate combination method based on your specific use case
  • Be aware of potential issues with timestamp alignment and unit compatibility
  • Consider pre-processing your data with other transformations for more complex scenarios

Additional Resources

  • Grafana official documentation on transformations
  • Time series analysis concepts and best practices
  • Data visualization principles for effective dashboards

Exercises

  1. Create a dashboard showing system load across multiple servers, then use the Combine Time Series transformation to show the total load.
  2. Experiment with different combine methods (sum, mean, max) on the same dataset and compare the results.
  3. Create a "health score" by combining multiple system metrics with different weights.
  4. Try combining time series with different time intervals and observe how Grafana handles the alignment.


If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)