{
  "title": "StoatFlow \u2014 memory",
  "uid": "stoatflow-memory",
  "editable": true,
  "schemaVersion": 39,
  "version": 1,
  "tags": [
    "stoatflow",
    "memory"
  ],
  "time": {
    "from": "now-24h",
    "to": "now"
  },
  "refresh": "1m",
  "description": "The StoatFlow memory report as a dashboard: fits against the limit, the plan, the verdicts, resident memory, the residue and the pressure valve. See https://stoatflow.io/docs/operating/right-sizing-memory",
  "templating": {
    "list": [
      {
        "name": "datasource",
        "type": "datasource",
        "query": "prometheus",
        "label": "Data source"
      },
      {
        "name": "app",
        "type": "query",
        "label": "Application",
        "datasource": {
          "type": "prometheus",
          "uid": "${datasource}"
        },
        "refresh": 2,
        "includeAll": true,
        "multi": true,
        "query": {
          "query": "label_values(stoatflow_memory_verdict, application_id)",
          "refId": "app"
        },
        "definition": "label_values(stoatflow_memory_verdict, application_id)"
      },
      {
        "name": "pod",
        "type": "query",
        "label": "Pod",
        "datasource": {
          "type": "prometheus",
          "uid": "${datasource}"
        },
        "refresh": 2,
        "includeAll": true,
        "multi": true,
        "query": {
          "query": "label_values(stoatflow_memory_verdict{application_id=~\"$app\"}, pod)",
          "refId": "pod"
        },
        "definition": "label_values(stoatflow_memory_verdict{application_id=~\"$app\"}, pod)"
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "row",
      "title": "Does it fit?",
      "collapsed": false,
      "gridPos": {
        "x": 0,
        "y": 0,
        "w": 24,
        "h": 1
      },
      "panels": []
    },
    {
      "id": 2,
      "type": "timeseries",
      "title": "fits against the limit",
      "description": "The smallest container limit at which every pool holds what it uses, against the limit the plan used. NaN until measured.",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "gridPos": {
        "x": 0,
        "y": 1,
        "w": 12,
        "h": 8
      },
      "fieldConfig": {
        "defaults": {
          "unit": "bytes",
          "custom": {
            "lineWidth": 1,
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "stoatflow_memory_fits_bytes{application_id=~\"$app\",pod=~\"$pod\"}",
          "legendFormat": "fits {{pod}}"
        },
        {
          "refId": "B",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "stoatflow_memory_limit_bytes{application_id=~\"$app\",pod=~\"$pod\"}",
          "legendFormat": "limit {{pod}}"
        }
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Largest fits over the range, of the limit",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "description": "Above 100 %: the pod is too small. Well below: it could shrink (check with GET /memory/what-if?limit=\u2026).",
      "gridPos": {
        "x": 12,
        "y": 1,
        "w": 6,
        "h": 8
      },
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "decimals": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "blue",
                "value": null
              },
              {
                "color": "green",
                "value": 0.6
              },
              {
                "color": "orange",
                "value": 0.9
              },
              {
                "color": "red",
                "value": 1.0
              }
            ]
          }
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ]
        },
        "colorMode": "background"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "max_over_time(stoatflow_memory_fits_bytes{application_id=~\"$app\",pod=~\"$pod\"}[$__range]) / on(pod) stoatflow_memory_limit_bytes{application_id=~\"$app\",pod=~\"$pod\"}",
          "legendFormat": "{{pod}}"
        }
      ]
    },
    {
      "id": 4,
      "type": "bargauge",
      "title": "The plan's split",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "description": "The memory plan's split of the limit per pool (memtables are accounted inside the block cache).",
      "gridPos": {
        "x": 18,
        "y": 1,
        "w": 6,
        "h": 8
      },
      "fieldConfig": {
        "defaults": {
          "unit": "bytes"
        },
        "overrides": []
      },
      "options": {
        "displayMode": "basic",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ]
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "max by (pool) (stoatflow_memory_plan_bytes{application_id=~\"$app\",pod=~\"$pod\"})",
          "legendFormat": "{{pool}}",
          "instant": true
        }
      ]
    },
    {
      "id": 5,
      "type": "row",
      "title": "How does each pool fare?",
      "collapsed": false,
      "gridPos": {
        "x": 0,
        "y": 9,
        "w": 24,
        "h": 1
      },
      "panels": []
    },
    {
      "id": 6,
      "type": "state-timeline",
      "title": "Verdict per pool",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "description": "0 oversized, 1 comfortable, 2 tight, 3 starved, -1 unknown. A tight block cache costs latency; a tight container risks an OOM kill.",
      "gridPos": {
        "x": 0,
        "y": 10,
        "w": 24,
        "h": 7
      },
      "fieldConfig": {
        "defaults": {
          "mappings": [
            {
              "type": "value",
              "options": {
                "-1": {
                  "text": "unknown",
                  "color": "text",
                  "index": 0
                },
                "0": {
                  "text": "oversized",
                  "color": "blue",
                  "index": 1
                },
                "1": {
                  "text": "comfortable",
                  "color": "green",
                  "index": 2
                },
                "2": {
                  "text": "tight",
                  "color": "orange",
                  "index": 3
                },
                "3": {
                  "text": "starved",
                  "color": "red",
                  "index": 4
                }
              }
            }
          ],
          "color": {
            "mode": "thresholds"
          },
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "text",
                "value": null
              }
            ]
          }
        },
        "overrides": []
      },
      "options": {
        "showValue": "never",
        "mergeValues": true,
        "rowHeight": 0.8
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "max by (pool) (stoatflow_memory_verdict{application_id=~\"$app\",pod=~\"$pod\"})",
          "legendFormat": "{{pool}}"
        }
      ]
    },
    {
      "id": 7,
      "type": "row",
      "title": "What is resident?",
      "collapsed": false,
      "gridPos": {
        "x": 0,
        "y": 17,
        "w": 24,
        "h": 1
      },
      "panels": []
    },
    {
      "id": 8,
      "type": "timeseries",
      "title": "Resident memory against the limit",
      "description": "The container's resident memory (cAdvisor). The kernel kills a container on its memory, not on what the JVM accounts.",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "gridPos": {
        "x": 0,
        "y": 18,
        "w": 12,
        "h": 8
      },
      "fieldConfig": {
        "defaults": {
          "unit": "bytes",
          "custom": {
            "lineWidth": 1,
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "max by (pod) (container_memory_rss{pod=~\"$pod\",container!=\"\",container!=\"POD\"})",
          "legendFormat": "resident {{pod}}"
        },
        {
          "refId": "B",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "stoatflow_memory_limit_bytes{application_id=~\"$app\",pod=~\"$pod\"}",
          "legendFormat": "limit {{pod}}"
        }
      ]
    },
    {
      "id": 9,
      "type": "timeseries",
      "title": "Native residue against its reserve",
      "description": "Resident memory no reading accounts for. Its budget also includes the JVM's native share its own pools do not report, so a stateless pod's residue is judged too.",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "gridPos": {
        "x": 12,
        "y": 18,
        "w": 12,
        "h": 8
      },
      "fieldConfig": {
        "defaults": {
          "unit": "bytes",
          "custom": {
            "lineWidth": 1,
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "stoatflow_memory_native_unaccounted_bytes{application_id=~\"$app\",pod=~\"$pod\"}",
          "legendFormat": "residue {{pod}}"
        },
        {
          "refId": "B",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum by (pod) (stoatflow_memory_plan_bytes{application_id=~\"$app\",pod=~\"$pod\",pool=~\"native-reserve|allocator-slack\"})",
          "legendFormat": "reserve + slack {{pod}}"
        }
      ]
    },
    {
      "id": 10,
      "type": "row",
      "title": "Under pressure?",
      "collapsed": false,
      "gridPos": {
        "x": 0,
        "y": 26,
        "w": 24,
        "h": 1
      },
      "panels": []
    },
    {
      "id": 11,
      "type": "timeseries",
      "title": "Pressure-valve steps",
      "description": "Block-cache capacity lowered or raised. Any step means the container passed 90 % of its limit.",
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "gridPos": {
        "x": 0,
        "y": 27,
        "w": 24,
        "h": 6
      },
      "fieldConfig": {
        "defaults": {
          "unit": "short",
          "custom": {
            "lineWidth": 1,
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "increase(stoatflow_memory_valve_steps_total{application_id=~\"$app\",pod=~\"$pod\"}[$__rate_interval])",
          "legendFormat": "{{pod}}"
        }
      ]
    }
  ]
}
