Grafana dashboard: Cost Analysis by Cluster (Correct Price)
Description: A dashboard to help with cost and utilisation

Fork of https://grafana.com/dashboards/6873

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "8.2.1"
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "${DS_PROMETHEUS}",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "A dashboard to help with cost and utilisation",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "gnetId": 8932,
  "graphTooltip": 0,
  "id": null,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": null,
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": true
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "namespace"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Namespace"
              },
              {
                "id": "links",
                "value": [
                  {
                    "targetBlank": false,
                    "title": "View namespace cost analysis",
                    "url": "d/at-cost-analysis-namespace/cost-analysis-by-namespace?&var-namespace=$__cell"
                  }
                ]
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #cpu_requested"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Requested CPU"
              },
              {
                "id": "unit",
                "value": "short"
              },
              {
                "id": "decimals",
                "value": 1
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #memory_requested"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Requested RAM"
              },
              {
                "id": "unit",
                "value": "decgbytes"
              },
              {
                "id": "decimals",
                "value": 1
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #storage_requested"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "Requested Storage"
              },
              {
                "id": "unit",
                "value": "decgbytes"
              },
              {
                "id": "decimals"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "CPU Cost"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Memory Cost"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Storage Cost"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Total Cost"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #H"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "CPU Utilisation"
              },
              {
                "id": "unit",
                "value": "percent"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Value #I"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "RAM Utilisation (with fs cache)"
              },
              {
                "id": "unit",
                "value": "percent"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 25,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "hideTimeOverride": false,
      "id": 73,
      "links": [],
      "maxDataPoints": 800,
      "options": {
        "showHeader": true,
        "sortBy": [
          {
            "desc": false,
            "displayName": "Namespace"
          }
        ]
      },
      "pluginVersion": "8.2.1",
      "repeat": null,
      "repeatDirection": "v",
      "targets": [
        {
          "exemplar": false,
          "expr": "# CPU Requested\navg_over_time(namespace_cpu:kube_pod_container_resource_requests:sum[$__range:$__interval])\nor sum by (namespace, cluster, prometheus, prometheus_replica) (kube_namespace_labels * 0)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{ namespace }}",
          "refId": "cpu_requested"
        },
        {
          "exemplar": true,
          "expr": "# RAM Requested\navg_over_time(namespace_memory:kube_pod_container_resource_requests:sum[$__range:$__interval]) / (1024 * 1024 * 1024)\nor sum by (namespace, cluster, prometheus, prometheus_replica) (kube_namespace_labels * 0)",
          "format": "table",
          "hide": false,
          "instant": true,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{ namespace }}",
          "refId": "memory_requested"
        },
        {
          "exemplar": true,
          "expr": "# Storage Requested\navg_over_time(\n  namespace_persistentvolumeclaim:kube_persistentvolumeclaim_resource_requests_storage_bytes:sum[$__range:$__interval]\n) / 1024 / 1024 / 1024\nor sum by (namespace, cluster, prometheus, prometheus_replica) (kube_namespace_labels * 0) # Allow to list even namespaces without PVC\n",
          "format": "table",
          "instant": true,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "",
          "refId": "storage_requested"
        },
        {
          "exemplar": true,
          "expr": "# CPU Usage (including past and disappeared Pods) / cpu requested (including past and disappeared Pods)\navg_over_time (namespace:container_cpu_usage_seconds_total:sum_rate[$__range])\n/ on (namespace)\n(avg_over_time(namespace:kube_pod_container_resource_requests_cpu_cores:sum[$__range:$__interval]))\n* 100",
          "format": "table",
          "hide": true,
          "instant": true,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{ namespace }}",
          "refId": "H"
        },
        {
          "expr": "# RAM usage (including past and disappeared Pods) / RAM requested (including past and disappeared Pods)\navg_over_time (namespace:container_memory_usage_bytes:sum[$__range])\n/ on (namespace)\n(avg_over_time(namespace:kube_pod_container_resource_requests_memory_bytes:sum[$__range:$__interval]))\n* 100",
          "format": "table",
          "hide": true,
          "instant": true,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{ namespace }}",
          "refId": "I"
        }
      ],
      "timeFrom": "",
      "timeShift": null,
      "title": "Namespace cost and utilisation analysis over the period",
      "transformations": [
        {
          "id": "merge",
          "options": {
            "reducers": []
          }
        },
        {
          "id": "calculateField",
          "options": {
            "alias": "CPU Cost",
            "binary": {
              "left": "Value #cpu_requested",
              "operator": "*",
              "reducer": "sum",
              "right": "6"
            },
            "mode": "binary",
            "reduce": {
              "reducer": "sum"
            },
            "replaceFields": false
          }
        },
        {
          "id": "calculateField",
          "options": {
            "alias": "Memory Cost",
            "binary": {
              "left": "Value #memory_requested",
              "operator": "*",
              "reducer": "sum",
              "right": "2.2"
            },
            "mode": "binary",
            "reduce": {
              "reducer": "sum"
            }
          }
        },
        {
          "id": "calculateField",
          "options": {
            "alias": "Storage Cost",
            "binary": {
              "left": "Value #storage_requested",
              "operator": "*",
              "reducer": "sum",
              "right": "0.104"
            },
            "mode": "binary",
            "reduce": {
              "reducer": "sum"
            }
          }
        },
        {
          "id": "calculateField",
          "options": {
            "binary": {
              "left": "CPU Cost",
              "operator": "+",
              "reducer": "sum",
              "right": "Memory Cost"
            },
            "mode": "binary",
            "reduce": {
              "reducer": "sum"
            }
          }
        },
        {
          "id": "calculateField",
          "options": {
            "alias": "Total Cost",
            "binary": {
              "left": "CPU Cost + Memory Cost",
              "operator": "+",
              "reducer": "sum",
              "right": "Storage Cost"
            },
            "mode": "binary",
            "reduce": {
              "reducer": "sum"
            }
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "CPU Cost + Memory Cost": true,
              "Time": true,
              "prometheus": true,
              "prometheus_replica": true
            },
            "indexByName": {},
            "renameByName": {}
          }
        },
        {
          "id": "filterByValue",
          "options": {
            "filters": [
              {
                "config": {
                  "id": "lower",
                  "options": {
                    "value": 5
                  }
                },
                "fieldName": "Total Cost"
              }
            ],
            "match": "any",
            "type": "exclude"
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": false,
  "schemaVersion": 31,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "2021-10-31T23:00:00.000Z",
    "to": "2021-11-30T22:59:59.000Z"
  },
  "timepicker": {
    "hidden": false,
    "refresh_intervals": [],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "30d"
    ]
  },
  "timezone": "browser",
  "title": "Cost Analysis by Cluster (Correct Price)",
  "uid": "lxBWOdDGz",
  "version": 17
}