{{- /*
Generated from 'node-cluster-rsrc-use' from https://raw.githubusercontent.com/prometheus-operator/kube-prometheus/8e16c980bf74e26709484677181e6f94808a45a3/manifests/grafana-dashboardDefinitions.yaml
Do not change in-place! In order to change this file first read following link:
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack/hack
*/ -}}
{{- $kubeTargetVersion := default .Capabilities.KubeVersion.GitVersion .Values.kubeTargetVersionOverride }}
{{- if and (or .Values.grafana.enabled .Values.grafana.forceDeployDashboards) (semverCompare ">=1.14.0-0" $kubeTargetVersion) (semverCompare "<9.9.9-9" $kubeTargetVersion) .Values.grafana.defaultDashboardsEnabled (or .Values.nodeExporter.enabled .Values.nodeExporter.forceDeployDashboards) }}
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: {{ template "kube-prometheus-stack-grafana.namespace" . }}
  name: {{ printf "%s-%s" (include "kube-prometheus-stack.fullname" $) "node-cluster-rsrc-use" | trunc 63 | trimSuffix "-" }}
  annotations:
{{ toYaml .Values.grafana.sidecar.dashboards.annotations | indent 4 }}
  labels:
    {{- if $.Values.grafana.sidecar.dashboards.label }}
    {{ $.Values.grafana.sidecar.dashboards.label }}: {{ ternary $.Values.grafana.sidecar.dashboards.labelValue "1" (not (empty $.Values.grafana.sidecar.dashboards.labelValue)) | quote }}
    {{- end }}
    app: {{ template "kube-prometheus-stack.name" $ }}-grafana
{{ include "kube-prometheus-stack.labels" $ | indent 4 }}
data:
  node-cluster-rsrc-use.json: |-
    {{`{
        "graphTooltip": 1,
        "panels": [
            {
                "collapsed": false,
                "gridPos": {
                    "h": 1,
                    "w": 24,
                    "x": 0,
                    "y": 0
                },
                "id": 1,
                "panels": [

                ],
                "title": "CPU",
                "type": "row"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "percentunit"
                    }
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 0,
                    "y": 1
                },
                "id": 2,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "((\n  instance:node_cpu_utilisation:rate5m{job=\"node-exporter\", cluster=\"$cluster\"}\n  *\n  instance:node_num_cpu:sum{job=\"node-exporter\", cluster=\"$cluster\"}\n) != 0 )\n/ scalar(sum(instance:node_num_cpu:sum{job=\"node-exporter\", cluster=\"$cluster\"}))\n",
                        "legendFormat": "{{ instance }}"
                    }
                ],
                "title": "CPU Utilisation",
                "type": "timeseries"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "percentunit"
                    }
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 12,
                    "y": 1
                },
                "id": 3,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "(\n  instance:node_load1_per_cpu:ratio{job=\"node-exporter\", cluster=\"$cluster\"}\n  / scalar(count(instance:node_load1_per_cpu:ratio{job=\"node-exporter\", cluster=\"$cluster\"}))\n)  != 0\n",
                        "legendFormat": "{{ instance }}"
                    }
                ],
                "title": "CPU Saturation (Load1 per CPU)",
                "type": "timeseries"
            },
            {
                "collapsed": false,
                "gridPos": {
                    "h": 1,
                    "w": 24,
                    "x": 0,
                    "y": 8
                },
                "id": 4,
                "panels": [

                ],
                "title": "Memory",
                "type": "row"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "percentunit"
                    }
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 0,
                    "y": 9
                },
                "id": 5,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "(\n  instance:node_memory_utilisation:ratio{job=\"node-exporter\", cluster=\"$cluster\"}\n  / scalar(count(instance:node_memory_utilisation:ratio{job=\"node-exporter\", cluster=\"$cluster\"}))\n) != 0\n",
                        "legendFormat": "{{ instance }}"
                    }
                ],
                "title": "Memory Utilisation",
                "type": "timeseries"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "rds"
                    }
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 12,
                    "y": 9
                },
                "id": 6,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "instance:node_vmstat_pgmajfault:rate5m{job=\"node-exporter\", cluster=\"$cluster\"}",
                        "legendFormat": "{{ instance }}"
                    }
                ],
                "title": "Memory Saturation (Major Page Faults)",
                "type": "timeseries"
            },
            {
                "collapsed": false,
                "gridPos": {
                    "h": 1,
                    "w": 24,
                    "x": 0,
                    "y": 16
                },
                "id": 7,
                "panels": [

                ],
                "title": "Network",
                "type": "row"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "Bps"
                    },
                    "overrides": [
                        {
                            "matcher": {
                                "id": "byRegexp",
                                "options": "/Transmit/"
                            },
                            "properties": [
                                {
                                    "id": "custom.transform",
                                    "value": "negative-Y"
                                }
                            ]
                        }
                    ]
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 0,
                    "y": 17
                },
                "id": 8,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "instance:node_network_receive_bytes_excluding_lo:rate5m{job=\"node-exporter\", cluster=\"$cluster\"} != 0",
                        "legendFormat": "{{ instance }} Receive"
                    },
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "instance:node_network_transmit_bytes_excluding_lo:rate5m{job=\"node-exporter\", cluster=\"$cluster\"} != 0",
                        "legendFormat": "{{ instance }} Transmit"
                    }
                ],
                "title": "Network Utilisation (Bytes Receive/Transmit)",
                "type": "timeseries"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "Bps"
                    },
                    "overrides": [
                        {
                            "matcher": {
                                "id": "byRegexp",
                                "options": "/Transmit/"
                            },
                            "properties": [
                                {
                                    "id": "custom.transform",
                                    "value": "negative-Y"
                                }
                            ]
                        }
                    ]
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 12,
                    "y": 17
                },
                "id": 9,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "instance:node_network_receive_drop_excluding_lo:rate5m{job=\"node-exporter\", cluster=\"$cluster\"} != 0",
                        "legendFormat": "{{ instance }} Receive"
                    },
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "instance:node_network_transmit_drop_excluding_lo:rate5m{job=\"node-exporter\", cluster=\"$cluster\"} != 0",
                        "legendFormat": "{{ instance }} Transmit"
                    }
                ],
                "title": "Network Saturation (Drops Receive/Transmit)",
                "type": "timeseries"
            },
            {
                "collapsed": false,
                "gridPos": {
                    "h": 1,
                    "w": 24,
                    "x": 0,
                    "y": 24
                },
                "id": 10,
                "panels": [

                ],
                "title": "Disk IO",
                "type": "row"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "percentunit"
                    }
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 0,
                    "y": 25
                },
                "id": 11,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "instance_device:node_disk_io_time_seconds:rate5m{job=\"node-exporter\", cluster=\"$cluster\"}\n/ scalar(count(instance_device:node_disk_io_time_seconds:rate5m{job=\"node-exporter\", cluster=\"$cluster\"}))\n",
                        "legendFormat": "{{ instance }} {{device}}"
                    }
                ],
                "title": "Disk IO Utilisation",
                "type": "timeseries"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "percentunit"
                    }
                },
                "gridPos": {
                    "h": 7,
                    "w": 12,
                    "x": 12,
                    "y": 25
                },
                "id": 12,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "instance_device:node_disk_io_time_weighted_seconds:rate5m{job=\"node-exporter\", cluster=\"$cluster\"}\n/ scalar(count(instance_device:node_disk_io_time_weighted_seconds:rate5m{job=\"node-exporter\", cluster=\"$cluster\"}))\n",
                        "legendFormat": "{{ instance }} {{device}}"
                    }
                ],
                "title": "Disk IO Saturation",
                "type": "timeseries"
            },
            {
                "collapsed": false,
                "gridPos": {
                    "h": 1,
                    "w": 24,
                    "x": 0,
                    "y": 34
                },
                "id": 13,
                "panels": [

                ],
                "title": "Disk Space",
                "type": "row"
            },
            {
                "datasource": {
                    "type": "prometheus",
                    "uid": "${datasource}"
                },
                "fieldConfig": {
                    "defaults": {
                        "custom": {
                            "fillOpacity": 100,
                            "showPoints": "never",
                            "stacking": {
                                "mode": "normal"
                            }
                        },
                        "unit": "percentunit"
                    }
                },
                "gridPos": {
                    "h": 7,
                    "w": 24,
                    "x": 0,
                    "y": 35
                },
                "id": 14,
                "options": {
                    "legend": {
                        "showLegend": false
                    },
                    "tooltip": {
                        "mode": "multi",
                        "sort": "desc"
                    }
                },
                "pluginVersion": "v11.4.0",
                "targets": [
                    {
                        "datasource": {
                            "type": "prometheus",
                            "uid": "$datasource"
                        },
                        "expr": "sum without (device) (\n  max without (fstype, mountpoint) ((\n    node_filesystem_size_bytes{job=\"node-exporter\", fstype!=\"\", mountpoint!=\"\", cluster=\"$cluster\"}\n    -\n    node_filesystem_avail_bytes{job=\"node-exporter\", fstype!=\"\", mountpoint!=\"\", cluster=\"$cluster\"}\n  ) != 0)\n)\n/ scalar(sum(max without (fstype, mountpoint) (node_filesystem_size_bytes{job=\"node-exporter\", fstype!=\"\", mountpoint!=\"\", cluster=\"$cluster\"})))\n",
                        "legendFormat": "{{ instance }}"
                    }
                ],
                "title": "Disk Space Utilisation",
                "type": "timeseries"
            }
        ],
        "refresh": "30s",
        "schemaVersion": 39,
        "tags": [
            "node-exporter-mixin"
        ],
        "templating": {
            "list": [
                {
                    "name": "datasource",
                    "query": "prometheus",
                    "type": "datasource"
                },
                {
                    "datasource": {
                        "type": "prometheus",
                        "uid": "${datasource}"
                    },
                    "hide": 2,
                    "includeAll": false,
                    "name": "cluster",
                    "query": "label_values(node_time_seconds, cluster)",
                    "refresh": 2,
                    "sort": 1,
                    "type": "query"
                },
                {
                    "datasource": {
                        "type": "prometheus",
                        "uid": "${datasource}"
                    },
                    "refresh": 2,
                    "sort": 1
                }
            ]
        },
        "time": {
            "from": "now-1h",
            "to": "now"
        },
        "timezone": "`}}{{ .Values.grafana.defaultDashboardsTimezone }}{{`",
        "title": "Node Exporter / USE Method / Cluster",
        "uid": "3e97d1d02672cdd0861f4c97c64f89b2"
    }`}}
{{- end }}