Skip to content

A Dashboard Variables Example

Video Lecture

Using Dashboard Variables Example Using Dashboard Variables Example

Description

We will create a simple dashboard that uses a dashboard variable in multiple ways.

The final dashboard will show the available Prometheus node exporters in a table, and we can filter the time series visualization by clicking the node exporter instance in the table cell.

The queries I used in the CPU visualization were,

rate(node_cpu_seconds_total{instance="$instance",mode="system",job="node"}[$__rate_interval]) * 100
rate(node_cpu_seconds_total{instance="$instance",mode="user",job="node"}[$__rate_interval]) * 100
rate(node_cpu_seconds_total{instance="$instance",mode="iowait",job="node"}[$__rate_interval]) * 100

The URL I used in the data link override was,

d/ae351db5d47i8b/prometheus-node-exporters-cpu?var-instance=${__value.text}

Remember that the ID shown in the URL above (ae351db5d47i8b) will be different on your server. You should copy the URL from your own browsers address field.

Dashboard Model JSON

Grafana v11.2.2

{
    "annotations": {
        "list": [
            {
                "builtIn": 1,
                "datasource": {
                    "type": "grafana",
                    "uid": "-- Grafana --"
                },
                "enable": true,
                "hide": true,
                "iconColor": "rgba(0, 211, 255, 1)",
                "name": "Annotations & Alerts",
                "type": "dashboard"
            }
        ]
    },
    "editable": true,
    "fiscalYearStartMonth": 0,
    "graphTooltip": 0,
    "id": 33,
    "links": [],
    "panels": [
        {
            "datasource": {
                "default": false,
                "type": "prometheus",
                "uid": "ee0jwnzdenfgga"
            },
            "description": "",
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "mode": "thresholds"
                    },
                    "custom": {
                        "align": "auto",
                        "cellOptions": {
                            "type": "auto"
                        },
                        "inspect": false
                    },
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "green",
                                "value": null
                            },
                            {
                                "color": "red",
                                "value": 80
                            }
                        ]
                    }
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "instance"
                        },
                        "properties": [
                            {
                                "id": "links",
                                "value": [
                                    {
                                        "title": "",
                                        "url": "d/ae351db5d47i8b/prometheus-node-exporters-cpu?var-instance=${__value.text}"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 5,
                "w": 24,
                "x": 0,
                "y": 0
            },
            "id": 1,
            "options": {
                "cellHeight": "sm",
                "footer": {
                    "countRows": false,
                    "fields": "",
                    "reducer": ["sum"],
                    "show": false
                },
                "showHeader": true
            },
            "pluginVersion": "11.2.2",
            "targets": [
                {
                    "datasource": {
                        "type": "prometheus",
                        "uid": "ee0jwnzdenfgga"
                    },
                    "editorMode": "code",
                    "exemplar": false,
                    "expr": "node_uname_info{job=\"node\"}",
                    "format": "table",
                    "instant": true,
                    "legendFormat": "__auto",
                    "range": false,
                    "refId": "A"
                }
            ],
            "title": "Node Exporters",
            "transformations": [
                {
                    "id": "organize",
                    "options": {
                        "excludeByName": {
                            "Time": true,
                            "Value": true,
                            "__name__": true,
                            "domainname": true
                        },
                        "includeByName": {},
                        "indexByName": {},
                        "renameByName": {}
                    }
                }
            ],
            "type": "table"
        },
        {
            "datasource": {
                "default": false,
                "type": "prometheus",
                "uid": "ee0jwnzdenfgga"
            },
            "description": "",
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "mode": "palette-classic"
                    },
                    "custom": {
                        "axisBorderShow": false,
                        "axisCenteredZero": false,
                        "axisColorMode": "text",
                        "axisLabel": "",
                        "axisPlacement": "auto",
                        "barAlignment": 0,
                        "barWidthFactor": 0.6,
                        "drawStyle": "line",
                        "fillOpacity": 0,
                        "gradientMode": "none",
                        "hideFrom": {
                            "legend": false,
                            "tooltip": false,
                            "viz": false
                        },
                        "insertNulls": false,
                        "lineInterpolation": "linear",
                        "lineWidth": 1,
                        "pointSize": 5,
                        "scaleDistribution": {
                            "type": "linear"
                        },
                        "showPoints": "auto",
                        "spanNulls": false,
                        "stacking": {
                            "group": "A",
                            "mode": "none"
                        },
                        "thresholdsStyle": {
                            "mode": "off"
                        }
                    },
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "green",
                                "value": null
                            },
                            {
                                "color": "red",
                                "value": 80
                            }
                        ]
                    }
                },
                "overrides": []
            },
            "gridPos": {
                "h": 13,
                "w": 24,
                "x": 0,
                "y": 5
            },
            "id": 2,
            "options": {
                "legend": {
                    "calcs": [],
                    "displayMode": "list",
                    "placement": "bottom",
                    "showLegend": true
                },
                "tooltip": {
                    "mode": "single",
                    "sort": "none"
                }
            },
            "targets": [
                {
                    "datasource": {
                        "type": "prometheus",
                        "uid": "ee0jwnzdenfgga"
                    },
                    "editorMode": "code",
                    "expr": "rate(node_cpu_seconds_total{instance=\"$instance\",mode=\"system\",job=\"node\"}[$__rate_interval]) * 100",
                    "instant": false,
                    "legendFormat": "System",
                    "range": true,
                    "refId": "A"
                },
                {
                    "datasource": {
                        "type": "prometheus",
                        "uid": "ee0jwnzdenfgga"
                    },
                    "editorMode": "code",
                    "expr": "rate(node_cpu_seconds_total{instance=\"$instance\",mode=\"user\",job=\"node\"}[$__rate_interval]) * 100",
                    "hide": false,
                    "instant": false,
                    "legendFormat": "User",
                    "range": true,
                    "refId": "B"
                },
                {
                    "datasource": {
                        "type": "prometheus",
                        "uid": "ee0jwnzdenfgga"
                    },
                    "editorMode": "code",
                    "expr": "rate(node_cpu_seconds_total{instance=\"$instance\",mode=\"iowait\",job=\"node\"}[$__rate_interval]) * 100",
                    "hide": false,
                    "instant": false,
                    "legendFormat": "Iowait",
                    "range": true,
                    "refId": "C"
                }
            ],
            "title": "CPU : $instance",
            "type": "timeseries"
        }
    ],
    "refresh": "",
    "schemaVersion": 39,
    "tags": [],
    "templating": {
        "list": [
            {
                "current": {
                    "selected": false,
                    "text": "10.116.0.3:9100",
                    "value": "10.116.0.3:9100"
                },
                "datasource": {
                    "type": "prometheus",
                    "uid": "ee0jwnzdenfgga"
                },
                "definition": "label_values({job=\"node\"},instance)",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "instance",
                "options": [],
                "query": {
                    "qryType": 1,
                    "query": "label_values({job=\"node\"},instance)",
                    "refId": "PrometheusVariableQueryEditor-VariableQuery"
                },
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            }
        ]
    },
    "time": {
        "from": "now-6h",
        "to": "now"
    },
    "timepicker": {},
    "timezone": "browser",
    "title": "Prometheus Node Exporters CPU",
    "uid": "ae351db5d47i8b",
    "version": 8,
    "weekStart": ""
}

Comments