Kubernetes Container Stats
Summery metrics about containers running on Kubernetes nodes.
This dashboard provides summary performance and availability metrics of a Kubernetes Node.  The data for this dashboard is expected to come from Snap agents running on every Kubernetes Node.  This is best achieved by using the [snap_k8s](https://hub.docker.com/r/raintank/snap_k8s/) docker image available on docker hub.

To deploy the snap_k8s containers in your Kubernetes environment it is advised to use the following DaemonSet config.
```
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: snap
  namespace: kube-system
spec:
  template:
    metadata:
      name: snap
      labels:
        daemon: snapd
    spec:
      hostPID: true
      hostNetwork: true
      containers:
      - name: snap
        image: raintank/snap_k8s:v4
        volumeMounts:
          - mountPath: /sys/fs/cgroup
            name: cgroup
          - mountPath: /var/run/docker.sock
            name: docker-sock
          - mountPath: /var/lib/docker
            name: fs-stats
          - mountPath: /usr/local/bin/docker
            name: docker
          - mountPath: /proc_host
            name: proc
          - mountPath: /opt/snap/tasks
            name: snap-tasks
        ports:
        - containerPort: 8181
          hostPort: 8181
          name: snap-api
        imagePullPolicy: IfNotPresent
        securityContext:
          privileged: true
        env:
          - name: PROCFS_MOUNT
            value: /proc_host
      volumes:
        - name: dev
          hostPath:
            path: /dev
        - name: cgroup
          hostPath:
            path: /sys/fs/cgroup
        - name: docker-sock
          hostPath:
            path: /var/run/docker.sock
        - name: fs-stats
          hostPath:
            path: /var/lib/docker
        - name: docker
          hostPath:
            path: /usr/bin/docker
        - name: proc
          hostPath:
            path: /proc
        - name: snap-tasks
          configMap:
            name: snap-tasks
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: snap-tasks
  namespace: kube-system
data:
  core.json: |-
    {
        "version": 1,
        "schedule": {
            "type": "simple",
            "interval": "10s"
        },
        "workflow": {
            "collect": {
                "metrics": {
                    "/intel/docker/*":{},
                    "/intel/procfs/cpu/*": {},
                    "/intel/procfs/meminfo/*": {},
                    "/intel/procfs/iface/*": {},
                    "/intel/linux/iostat/*": {},
                    "/intel/procfs/load/*": {}
                },
                "config": {
                    "/intel/procfs": {
                        "proc_path": "/proc_host"
                    }
                },
                "process": null,
                "publish": [
                    {
                        "plugin_name": "graphite",                    
                        "config": {
                            "prefix": "snap.dev.<%NODE%>",
                            "server": "graphite.local",
                            "port": 2003
                        }
                    }
                ]
            }
        }
    }

```

The only section that you should change is the graphite config. 
- The server and port should be that of your Graphite server.  
- The prefix will be inserted at the start of every metric produced by snap. For this dashboard the prefix is expected to be in the format "snap.<environment>.<host>" , where <environment> is something like "dev", "qa" or "prod" and <host> is the hostname of the Kubernetes node.  When using the **snap_k8s** docker image the literal string "<%NODE%>" can be used in the prefix and it will be replaced with the slugified representation of the hostname that the container is running on.  So if the hostname was "k8s-node1.dev.raintank.io" <%NODE%> would be replaced with "k8s-node1_dev_raintank_io".


Simply write the kubernetes DaemonSet and ConfigMap to a file name **snap_ds.yaml**, then run
```
kubectl create -f snap_ds.yaml
```
{
  "__inputs": [
    {
      "name": "DS_GRAPHITE",
      "label": "graphite",
      "description": "Graphite datasource",
      "type": "datasource",
      "pluginId": "graphite",
      "pluginName": "Graphite"
    }
  ],
  "__requires": [
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "4.0.0-pre1"
    },
    {
      "type": "datasource",
      "id": "graphite",
      "name": "Graphite",
      "version": "1.0.0"
    }
  ],
  "id": null,
  "title": "Kubernetes Container Stats",
  "tags": [],
  "style": "dark",
  "timezone": "browser",
  "editable": true,
  "hideControls": false,
  "sharedCrosshair": false,
  "rows": [
    {
      "collapse": false,
      "editable": true,
      "height": "600px",
      "panels": [
        {
          "alert": {
            "crit": {
              "op": ">"
            },
            "warn": {
              "op": ">"
            }
          },
          "alerting": {},
          "aliasColors": {},
          "bars": false,
          "datasource": "${DS_GRAPHITE}",
          "editable": true,
          "error": false,
          "fill": 1,
          "grid": {},
          "id": 1,
          "isNew": true,
          "legend": {
            "alignAsTable": true,
            "avg": true,
            "current": true,
            "hideEmpty": true,
            "max": false,
            "min": false,
            "show": true,
            "sort": "current",
            "sortDesc": true,
            "total": false,
            "values": true
          },
          "lines": true,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "connected",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "span": 3,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "refId": "A",
              "target": "aliasByNode(removeEmptySeries(snap.$environment.$server.intel.docker.$container.stats.cgroups.memory_stats.usage.usage), 5)",
              "textEditor": false
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "Memory Usage",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 0,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "show": true
          },
          "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
            }
          ]
        },
        {
          "alert": {
            "crit": {
              "op": ">"
            },
            "warn": {
              "op": ">"
            }
          },
          "alerting": {},
          "aliasColors": {},
          "bars": false,
          "datasource": "${DS_GRAPHITE}",
          "editable": true,
          "error": false,
          "fill": 1,
          "grid": {},
          "id": 2,
          "isNew": true,
          "legend": {
            "alignAsTable": true,
            "avg": true,
            "current": true,
            "max": false,
            "min": false,
            "show": true,
            "sort": "current",
            "sortDesc": true,
            "total": false,
            "values": true,
            "hideEmpty": true
          },
          "lines": true,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "connected",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [
            {
              "alias": "/.*-out/",
              "transform": "negative-Y"
            }
          ],
          "span": 3,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "refId": "A",
              "target": "aliasSub(groupByNode(perSecond(snap.$environment.$server.intel.docker.$container.stats.network.*.rx_bytes), 5, 'sum'), '(.*)', '\\1-in')",
              "textEditor": false
            },
            {
              "hide": false,
              "refId": "B",
              "target": "aliasSub(groupByNode(perSecond(snap.$environment.$server.intel.docker.$container.stats.network.*.tx_bytes), 5, 'sum'), '(.*)', '\\1-out')",
              "textEditor": false
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "Network Traffic",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 2,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "show": true
          },
          "yaxes": [
            {
              "format": "bps",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        },
        {
          "alert": {
            "crit": {
              "op": ">"
            },
            "warn": {
              "op": ">"
            }
          },
          "alerting": {},
          "aliasColors": {},
          "bars": false,
          "datasource": "${DS_GRAPHITE}",
          "editable": true,
          "error": false,
          "fill": 0,
          "grid": {},
          "id": 3,
          "isNew": true,
          "legend": {
            "alignAsTable": true,
            "avg": true,
            "current": true,
            "max": false,
            "min": false,
            "show": true,
            "sort": "current",
            "sortDesc": true,
            "total": false,
            "values": true,
            "rightSide": false,
            "hideZero": false,
            "hideEmpty": true
          },
          "lines": true,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "connected",
          "percentage": false,
          "pointradius": 3,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "span": 3,
          "stack": false,
          "steppedLine": true,
          "targets": [
            {
              "refId": "A",
              "target": "aliasByNode(removeEmptySeries(snap.$environment.$server.intel.docker.$container.stats.connection.tcp.*), 5, 9)",
              "textEditor": false
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "TCP Connections",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 2,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "show": true
          },
          "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
            }
          ]
        },
        {
          "alert": {
            "crit": {
              "op": ">"
            },
            "warn": {
              "op": ">"
            }
          },
          "alerting": {},
          "aliasColors": {},
          "bars": false,
          "datasource": "${DS_GRAPHITE}",
          "editable": true,
          "error": false,
          "fill": 1,
          "grid": {},
          "id": 6,
          "isNew": true,
          "legend": {
            "alignAsTable": true,
            "avg": true,
            "current": true,
            "hideEmpty": true,
            "hideZero": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": true
          },
          "lines": true,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "connected",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "span": 3,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "refId": "A",
              "target": "aliasByNode(perSecond(snap.$environment.$server.intel.docker.$container.stats.cgroups.cpu_stats.cpu_usage.total_usage), 5)",
              "textEditor": false
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "CPU Usage",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 2,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "show": true
          },
          "yaxes": [
            {
              "format": "ns",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        }
      ],
      "title": "Row"
    },
    {
      "collapse": false,
      "editable": true,
      "height": "250px",
      "panels": [
        {
          "alert": {
            "crit": {
              "op": ">"
            },
            "warn": {
              "op": ">"
            }
          },
          "alerting": {},
          "aliasColors": {},
          "bars": false,
          "datasource": "${DS_GRAPHITE}",
          "editable": true,
          "error": false,
          "fill": 1,
          "grid": {},
          "id": 4,
          "isNew": true,
          "legend": {
            "alignAsTable": true,
            "avg": true,
            "current": true,
            "hideEmpty": true,
            "hideZero": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": true
          },
          "lines": false,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "connected",
          "percentage": false,
          "pointradius": 2,
          "points": true,
          "renderer": "flot",
          "seriesOverrides": [],
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "refId": "A",
              "target": "aliasByNode(sumSeriesWithWildcards(perSecond(snap.$environment.$server.intel.docker.$container.stats.filesystem.*.reads_completed), 8), 5)",
              "textEditor": false
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "Read IOPS",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 0,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "show": true
          },
          "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
            }
          ]
        },
        {
          "alert": {
            "crit": {
              "op": ">"
            },
            "warn": {
              "op": ">"
            }
          },
          "alerting": {},
          "aliasColors": {},
          "bars": false,
          "datasource": "${DS_GRAPHITE}",
          "editable": true,
          "error": false,
          "fill": 1,
          "grid": {},
          "id": 5,
          "isNew": true,
          "legend": {
            "alignAsTable": true,
            "avg": true,
            "current": true,
            "hideEmpty": true,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": true
          },
          "lines": false,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "connected",
          "percentage": false,
          "pointradius": 2,
          "points": true,
          "renderer": "flot",
          "seriesOverrides": [],
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "refId": "A",
              "target": "aliasByNode(sumSeriesWithWildcards(perSecond(snap.$environment.$server.intel.docker.$container.stats.filesystem.*.writes_completed), 8), 5)",
              "textEditor": false
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "Write IOPS",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 0,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "show": true
          },
          "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
            }
          ]
        }
      ],
      "title": "New row"
    },
    {
      "collapse": false,
      "editable": true,
      "height": "250px",
      "panels": [
        {
          "alert": {
            "crit": {
              "op": ">"
            },
            "warn": {
              "op": ">"
            }
          },
          "alerting": {},
          "aliasColors": {},
          "bars": false,
          "datasource": "${DS_GRAPHITE}",
          "editable": true,
          "error": false,
          "fill": 1,
          "grid": {},
          "id": 7,
          "isNew": true,
          "legend": {
            "avg": false,
            "current": false,
            "hideEmpty": true,
            "hideZero": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 2,
          "links": [],
          "nullPointMode": "connected",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "span": 12,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "refId": "A",
              "target": "groupByNode(snap.$environment.$server.intel.docker.$container.stats.connection.tcp.established, 5, 'sum')",
              "textEditor": false
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "ALL ESTABLISHED TCP CONN",
          "tooltip": {
            "msResolution": false,
            "shared": true,
            "sort": 0,
            "value_type": "cumulative"
          },
          "type": "graph",
          "xaxis": {
            "show": true
          },
          "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
            }
          ]
        }
      ],
      "title": "New row"
    }
  ],
  "time": {
    "from": "now-30m",
    "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"
    ]
  },
  "templating": {
    "list": [
      {
        "current": {},
        "datasource": "${DS_GRAPHITE}",
        "hide": 0,
        "includeAll": false,
        "multi": false,
        "name": "environment",
        "options": [],
        "query": "snap.*",
        "refresh": 1,
        "regex": "",
        "type": "query"
      },
      {
        "current": {},
        "datasource": "${DS_GRAPHITE}",
        "hide": 0,
        "includeAll": true,
        "multi": true,
        "name": "server",
        "options": [],
        "query": "snap.$environment.*",
        "refresh": 1,
        "type": "query"
      },
      {
        "current": {},
        "datasource": "${DS_GRAPHITE}",
        "hide": 0,
        "includeAll": true,
        "multi": true,
        "name": "container",
        "options": [],
        "query": "snap.$environment.$server.intel.docker.*",
        "refresh": 1,
        "type": "query"
      }
    ]
  },
  "annotations": {
    "list": []
  },
  "refresh": "10s",
  "schemaVersion": 13,
  "version": 4,
  "links": [],
  "gnetId": 482,
  "description": "Summery metrics about containers running on Kubernetes nodes."
}