Grafana dashboard: kubernetes pod metrics in elasticsearch
Description: cpu and memory of kubernetes pods collected by heapster using elasticsearch as a sink

This shows cpu and memory metrics from kubernetes pods collected by heapster using elasticsearch as a sink. Cluster, namespace and pod are provided as template variables. Configure heapster to start with
```
/heapster
      --source=kubernetes:https://kubernetes.default
      --sink=elasticsearch:http://elasticsearch-host:9200?cluster_name=your_cluster_name
```
Configure two grafana data sources (for the same elasticsearch url), one using CpuMetricsTimestamp as a time field, another using MemoryMetricsTimestamp as a time field. Seems weird to have the same url in two data sources, but I couldn't get around it. See screenshot for index template. Set `group by time interval` in both data sources to your heapster `--metric-resolution` argument. Heapster default is 1m, so set `group by time interval` to `>1m`, see screenshot.

Software versions used:
 - Heapster version: v1.4.2
 - Elasticsearch version: 5.5.1
 - Grafana version: 4.4.3

{
  "__inputs": [
    {
      "name": "DS_HEAPSTER_CPU",
      "label": "heapster cpu",
      "description": "elasticsearch heapster sink, time field: CpuMetricsTimestamp",
      "type": "datasource",
      "pluginId": "elasticsearch",
      "pluginName": "Elasticsearch"
    },
    {
      "name": "DS_HEAPSTER_MEMORY",
      "label": "heapster memory",
      "description": "elasticsearch heapster sink, time field: MemoryMetricsTimestamp",
      "type": "datasource",
      "pluginId": "elasticsearch",
      "pluginName": "Elasticsearch"
    }
  ],
  "__requires": [
    {
      "type": "datasource",
      "id": "elasticsearch",
      "name": "Elasticsearch",
      "version": "3.0.0"
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "4.4.3"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    }
  ],
  "annotations": {
    "list": []
  },
  "editable": true,
  "gnetId": 4535,
  "graphTooltip": 0,
  "hideControls": false,
  "id": null,
  "links": [],
  "refresh": false,
  "rows": [
    {
      "collapse": false,
      "height": -89,
      "panels": [
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": "${DS_HEAPSTER_CPU}",
          "fill": 1,
          "height": "500",
          "id": 6,
          "interval": ">1m",
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "alias": "{{term MetricsTags.pod_name.raw}} usage",
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "CpuMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.cpu/usage_rate.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace AND MetricsTags.pod_name:$pod",
              "refId": "A",
              "step": 600,
              "timeField": "CpuMetricsTimestamp"
            },
            {
              "alias": "{{term MetricsTags.pod_name.raw}} request",
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "CpuMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.cpu/request.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace AND MetricsTags.pod_name:$pod",
              "refId": "B",
              "step": 600,
              "timeField": "CpuMetricsTimestamp"
            },
            {
              "alias": "{{term MetricsTags.pod_name.raw}} limit",
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "CpuMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.cpu/limit.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace AND MetricsTags.pod_name:$pod",
              "refId": "C",
              "step": 600,
              "timeField": "CpuMetricsTimestamp"
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "$pod cpu",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        },
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": "${DS_HEAPSTER_MEMORY}",
          "fill": 1,
          "height": "500",
          "id": 8,
          "interval": ">1m",
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "alias": "{{term MetricsTags.namespace_name.raw}} {{term MetricsTags.pod_name.raw}} usage",
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "MemoryMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.memory/usage.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace AND MetricsTags.pod_name:$pod",
              "refId": "A",
              "step": 600,
              "timeField": "MemoryMetricsTimestamp"
            },
            {
              "alias": "{{term MetricsTags.namespace_name.raw}} {{term MetricsTags.pod_name.raw}} request",
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "MemoryMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.memory/request.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace AND MetricsTags.pod_name:$pod",
              "refId": "B",
              "step": 600,
              "timeField": "MemoryMetricsTimestamp"
            },
            {
              "alias": "{{term MetricsTags.namespace_name.raw}} {{term MetricsTags.pod_name.raw}} limit",
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "MemoryMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.memory/limit.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace AND MetricsTags.pod_name:$pod",
              "refId": "C",
              "step": 600,
              "timeField": "MemoryMetricsTimestamp"
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "$pod memory",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "bytes",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        }
      ],
      "repeat": null,
      "repeatIteration": null,
      "repeatRowId": null,
      "showTitle": false,
      "title": "Dashboard Row",
      "titleSize": "h6"
    },
    {
      "collapse": false,
      "height": 250,
      "panels": [
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": "${DS_HEAPSTER_CPU}",
          "fill": 1,
          "height": "500",
          "id": 5,
          "interval": "",
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "CpuMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.cpu/usage_rate.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace",
              "refId": "A",
              "step": 600,
              "timeField": "CpuMetricsTimestamp"
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "all pods cpu",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        },
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": "${DS_HEAPSTER_MEMORY}",
          "fill": 1,
          "height": "500",
          "id": 7,
          "interval": ">1m",
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "bucketAggs": [
                {
                  "fake": true,
                  "field": "MetricsTags.namespace_name.raw",
                  "id": "3",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "fake": true,
                  "field": "MetricsTags.pod_name.raw",
                  "id": "4",
                  "settings": {
                    "min_doc_count": 1,
                    "order": "desc",
                    "orderBy": "_term",
                    "size": "0"
                  },
                  "type": "terms"
                },
                {
                  "field": "MemoryMetricsTimestamp",
                  "id": "2",
                  "settings": {
                    "interval": "auto",
                    "min_doc_count": 0,
                    "trimEdges": 0
                  },
                  "type": "date_histogram"
                }
              ],
              "dsType": "elasticsearch",
              "expr": "sum(1-up)",
              "format": "time_series",
              "intervalFactor": 2,
              "legendFormat": "",
              "metric": "up",
              "metrics": [
                {
                  "field": "Metrics.memory/usage.value",
                  "id": "1",
                  "meta": {},
                  "settings": {},
                  "type": "avg"
                }
              ],
              "query": "MetricsTags.type:pod_container AND MetricsTags.cluster_name:$cluster AND MetricsTags.namespace_name:$namespace",
              "refId": "A",
              "step": 600,
              "timeField": "MemoryMetricsTimestamp"
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "all pods memory",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "bytes",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        }
      ],
      "repeat": null,
      "repeatIteration": null,
      "repeatRowId": null,
      "showTitle": false,
      "title": "Dashboard Row",
      "titleSize": "h6"
    }
  ],
  "schemaVersion": 14,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_HEAPSTER_CPU}",
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "cluster",
        "options": [],
        "query": "{\"find\":\"terms\",\"field\":\"MetricsTags.cluster_name\",\"size\":30}",
        "refresh": 2,
        "regex": "",
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_HEAPSTER_CPU}",
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "namespace",
        "options": [],
        "query": "{\"find\":\"terms\",\"field\":\"MetricsTags.namespace_name.raw\",\"size\":30,\"query\":\"MetricsTags.cluster_name:$cluster\"}",
        "refresh": 2,
        "regex": "",
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_HEAPSTER_CPU}",
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": false,
        "name": "pod",
        "options": [],
        "query": "{\"find\":\"terms\",\"field\":\"MetricsTags.pod_name.raw\",\"size\":30,\"query\":\"MetricsTags.namespace_name:$namespace AND MetricsTags.cluster_name:$cluster\"}",
        "refresh": 2,
        "regex": "",
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now/d",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "30d"
    ]
  },
  "timezone": "",
  "title": "kubernetes pod metrics in elasticsearch",
  "version": 4,
  "description": "cpu and memory of kubernetes pods collected by heapster using elasticsearch as a sink"
}