Applying Transformations
1. Using Reduce Transformation
| Property | Value | Description |
|---|---|---|
| type | "reduce" |
Specifies the transformation type as reduce |
| includeTimeField | false |
Whether to include the time field in the result |
| reducer | "sum" |
The reduction function to apply (e.g., sum, avg, min, max) |
Note: The reduce transformation aggregates data points into a single value based on the specified reducer function.
2. Using Filter by Name
| Property | Description | Values |
|---|---|---|
| type | Transformation type | filterByName |
| name | Name pattern to filter by | string |
| match | Matching strategy | contains, equals, startsWith, endsWith |
Example: Filter metrics containing "cpu"
{
"type": "filterByName",
"name": "cpu",
"match": "contains"
}
Note: The
filterByName transformation is useful for reducing the number of time series displayed in a dashboard by filtering based on metric names.
3. Using Filter Data by Values
| Option | Values | Description |
|---|---|---|
| type | "filterByValue" |
Specifies the transformation type to filter data by value |
| settings | {} |
Configuration options for the filter |
Example: Filter Data by Value
{
"type": "filterByValue",
"settings": {
"value": "error",
"field": "level"
}
}
Note: The
field parameter specifies the field to filter on, and value is the value to match.
4. Using Merge Transformation
The Merge transformation in Grafana combines multiple data frames into a single data frame. It's particularly useful when you have multiple queries returning similar data and want to merge them into one view.
| Option | Values | Description |
|---|---|---|
| mode | merge |
Specifies the transformation type as merge |
| frameLimit | 100 |
Maximum number of frames to merge (default: 100) |
Example: Merging Query Results
{
"refId": "A",
"datasource": {
"type": "prometheus",
"uid": "prometheus-datasource-uid"
},
"expr": "up{job=\"api-server\"}"
}
Example: Merging with Different Time Series
{
"refId": "B",
"datasource": {
"type": "prometheus",
"uid": "prometheus-datasource-uid"
},
"expr": "up{job=\"auth-server\"}"
}
Note: The Merge transformation works best when queries return data with matching time series labels.
Warning: If the frames have different time ranges, the merged result may not align properly.
5. Using Join by Field
| Option | Values | Description |
|---|---|---|
| joinByField | string |
The field name to join on. Must exist in both data frames. |
| leftFrame | string |
The identifier of the left data frame to join from. |
| rightFrame | string |
The identifier of the right data frame to join with. |
| mode | string |
Join mode: inner, left, or full. |
Example: Joining Data Frames by Field
const leftFrame = {
name: "cpu_usage",
fields: [
{ name: "time", values: [1, 2, 3] },
{ name: "cpu", values: [75, 80, 85] }
]
};
const rightFrame = {
name: "memory_usage",
fields: [
{ name: "time", values: [1, 2, 3] },
{ name: "memory", values: [512, 520, 530] }
]
};
const joinTransformation = {
type: "joinByField",
joinByField: "time",
leftFrame: "cpu_usage",
rightFrame: "memory_usage",
mode: "left"
};
// Resulting joined frame has fields: time, cpu, memory
Note: The
joinByField transformation is useful for combining data from multiple queries based on a common field like timestamp or ID.
6. Using Add Field from Calculation
| Property | Description | Example |
|---|---|---|
| fieldRef | Reference to the field to use in calculation | fieldRef: 'value' |
| mathExpression | Mathematical expression to calculate new field | mathExpression: 'A * 2' |
| newFieldKey | Name of the new field to be created | newFieldKey: 'doubledValue' |
Example: Add Field from Calculation
{
"type": "math",
"id": "add-field-calculation",
"options": {
"fieldRef": "value",
"mathExpression": "A * 2",
"newFieldKey": "doubledValue"
}
}
7. Using Organize Fields
| Field | Description | Options | Notes |
|---|---|---|---|
| name | Name of the field to organize | string |
Required field |
| label | Label to display for the field | string |
Optional, defaults to name |
| index | Position in the field list | number |
Optional, defaults to end of list |
| hide | Whether to hide the field from display | true or false |
Optional, defaults to false |
| calcs | Calculations to perform on the field | array |
Optional, can include mean, sum, etc. |
Example: Organize Fields in a Panel
{
"panels": [
{
"id": 1,
"type": "graph",
"fieldConfig": {
"overrides": [
{
"matcher": {
"id": "byName",
"options": "value"
},
"properties": [
{
"id": "name",
"value": "value"
},
{
"id": "label",
"value": "Value"
},
{
"id": "index",
"value": 0
},
{
"id": "hide",
"value": false
}
]
}
]
}
}
]
}
Note: The
index property allows reordering fields in the panel display. Fields with lower index values appear first.
8. Using Convert Field Type
| Field | Type | Description |
|---|---|---|
| field | string |
Name of the field to convert |
| type | string |
Target data type (e.g., number, string, boolean) |
| unit | string |
Unit to convert to (e.g., percent, bytes) |
Example: Convert field to number
{
"type": "convertFieldType",
"field": "cpu_usage",
"type": "number"
}
Example: Convert field to string with unit
{
"type": "convertFieldType",
"field": "memory_bytes",
"type": "string",
"unit": "bytes"
}
9. Using Group by Transformation
| Property | Description | Values | Notes |
|---|---|---|---|
| type | Transformation type identifier | groupby |
Required field to specify transformation |
| settings | Configuration options for grouping | {} |
Object containing groupBy and other options |
Example: Grouping by a field in a time series
{
"type": "groupby",
"settings": {
"groupBy": [
{
"type": "field",
"value": "status"
}
]
}
}
Note: The
groupby transformation is particularly useful for aggregating data in dashboards where you want to group metrics by a specific field like status, region, or user type.
10. Using Series to Rows
| Option | Values | Description |
|---|---|---|
| type | "seriesToRows" |
Transformation type to convert series to rows |
| id | "seriesToRows" |
Unique identifier for the transformation |
Note: This transformation is useful for flattening time series data into a tabular format where each series becomes a row.
11. Using Rows to Fields
| Option | Values | Description |
|---|---|---|
| type | "rowsToFields" |
Transformation type to convert rows into fields |
| id | "rowsToFields" |
Unique identifier for the transformation |
| name | "Rows to Fields" |
Name displayed in the Grafana UI |
Example: Transforming Rows to Fields
{
"id": "rowsToFields",
"name": "Rows to Fields",
"type": "rowsToFields"
}
Note: This transformation is useful when your data source returns rows that need to be pivoted into fields for better visualization or analysis.
12. Chaining Multiple Transformations
Example: Chaining transformations in Grafana
{
"targets": [
{
"refId": "A",
"expr": "rate(http_requests_total[5m])"
},
{
"refId": "B",
"expr": "sum by (method) (A)"
},
{
"refId": "C",
"expr": "sort_desc(B)"
}
]
}
| Transformation | Description | Usage |
|---|---|---|
| Reduce | Aggregates data points using a specified function (e.g., sum, avg) | Use to consolidate time series data |
| Filter by Name | Filters time series based on name patterns or regex | Helps isolate specific metrics from a large set |
| Sort | Orders time series by value or name | Useful for consistent visualization order |
| Organize Fields | Reorders or removes fields from results | Improves data clarity and visualization layout |
Note: Transformations are applied in the order they appear in the transformation list. Each step modifies the data before passing it to the next.