{
    "title": "System Health (Node Exporter)",
    "description": "CPU, memory, disk, and network monitoring — variable-based, works with any node_exporter instance",
    "tags": ["system", "grafana-lens", "node-exporter"],
    "timezone": "browser",
    "editable": true,
    "schemaVersion": 39,
    "time": { "from": "now-6h", "to": "now" },
    "refresh": "30s",
    "templating": {
        "list": [
            {
                "name": "datasource",
                "type": "datasource",
                "query": "prometheus",
                "current": {},
                "hide": 0
            },
            {
                "name": "instance",
                "type": "query",
                "datasource": { "type": "prometheus", "uid": "$datasource" },
                "query": "label_values(node_uname_info, instance)",
                "refresh": 1,
                "includeAll": true,
                "multi": true,
                "current": {},
                "hide": 0,
                "sort": 1
            }
        ]
    },
    "panels": [
        {
            "id": 1,
            "title": "CPU Usage %",
            "type": "gauge",
            "gridPos": { "h": 6, "w": 6, "x": 0, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "100 - (avg by(instance)(rate(node_cpu_seconds_total{mode=\"idle\",instance=~\"$instance\"}[5m])) * 100)",
                    "legendFormat": "{{ instance }}",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "percent",
                    "min": 0,
                    "max": 100,
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            { "color": "green", "value": null },
                            { "color": "yellow", "value": 70 },
                            { "color": "red", "value": 90 }
                        ]
                    }
                }
            }
        },
        {
            "id": 2,
            "title": "Memory Usage %",
            "type": "gauge",
            "gridPos": { "h": 6, "w": 6, "x": 6, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "(1 - node_memory_MemAvailable_bytes{instance=~\"$instance\"} / node_memory_MemTotal_bytes{instance=~\"$instance\"}) * 100",
                    "legendFormat": "{{ instance }}",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "percent",
                    "min": 0,
                    "max": 100,
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            { "color": "green", "value": null },
                            { "color": "yellow", "value": 75 },
                            { "color": "red", "value": 90 }
                        ]
                    }
                }
            }
        },
        {
            "id": 3,
            "title": "Disk Usage %",
            "type": "gauge",
            "gridPos": { "h": 6, "w": 6, "x": 12, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "(1 - node_filesystem_avail_bytes{instance=~\"$instance\",mountpoint=\"/\"} / node_filesystem_size_bytes{instance=~\"$instance\",mountpoint=\"/\"}) * 100",
                    "legendFormat": "{{ instance }}",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "percent",
                    "min": 0,
                    "max": 100,
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            { "color": "green", "value": null },
                            { "color": "yellow", "value": 80 },
                            { "color": "red", "value": 95 }
                        ]
                    }
                }
            }
        },
        {
            "id": 4,
            "title": "Network Received",
            "type": "stat",
            "gridPos": { "h": 6, "w": 6, "x": 18, "y": 0 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "sum(rate(node_network_receive_bytes_total{instance=~\"$instance\"}[5m]))",
                    "legendFormat": "Received",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "Bps"
                }
            }
        },
        {
            "id": 5,
            "title": "CPU Over Time",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 0, "y": 6 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "avg by(mode)(rate(node_cpu_seconds_total{instance=~\"$instance\"}[5m])) * 100",
                    "legendFormat": "{{ mode }}",
                    "refId": "A"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "percent",
                    "custom": {
                        "fillOpacity": 20,
                        "stacking": { "mode": "normal" }
                    }
                }
            }
        },
        {
            "id": 6,
            "title": "Memory Over Time",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 12, "y": 6 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "node_memory_MemTotal_bytes{instance=~\"$instance\"} - node_memory_MemAvailable_bytes{instance=~\"$instance\"}",
                    "legendFormat": "Used ({{ instance }})",
                    "refId": "A"
                },
                {
                    "expr": "node_memory_MemAvailable_bytes{instance=~\"$instance\"}",
                    "legendFormat": "Available ({{ instance }})",
                    "refId": "B"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "bytes",
                    "custom": {
                        "fillOpacity": 10
                    }
                }
            }
        },
        {
            "id": 7,
            "title": "Disk I/O",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 0, "y": 14 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "rate(node_disk_read_bytes_total{instance=~\"$instance\"}[5m])",
                    "legendFormat": "Read {{ device }}",
                    "refId": "A"
                },
                {
                    "expr": "rate(node_disk_written_bytes_total{instance=~\"$instance\"}[5m])",
                    "legendFormat": "Write {{ device }}",
                    "refId": "B"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "Bps",
                    "custom": {
                        "fillOpacity": 10
                    }
                }
            }
        },
        {
            "id": 8,
            "title": "Network I/O",
            "type": "timeseries",
            "gridPos": { "h": 8, "w": 12, "x": 12, "y": 14 },
            "datasource": { "type": "prometheus", "uid": "$datasource" },
            "targets": [
                {
                    "expr": "rate(node_network_receive_bytes_total{instance=~\"$instance\"}[5m])",
                    "legendFormat": "Recv {{ device }}",
                    "refId": "A"
                },
                {
                    "expr": "rate(node_network_transmit_bytes_total{instance=~\"$instance\"}[5m])",
                    "legendFormat": "Send {{ device }}",
                    "refId": "B"
                }
            ],
            "fieldConfig": {
                "defaults": {
                    "unit": "Bps",
                    "custom": {
                        "fillOpacity": 10
                    }
                }
            }
        }
    ]
}
