Grafana dashboard: k6.io metrics with statsd_exporter and Prometheus
Description: k6.io load tests results

## Overview

The dashboard is divided in three parts:

- the variables panel
- the global metrics panel
- a panel for each HTTP request

Through the variables panel, you can choose to observe one or multiple specific HTTP requests (tracked by their "name" tag).
You can then choose which HTTP timing to observe amongst [the seven standard Go HTTP timings](https://k6.io/docs/using-k6/metrics#http-specific-built-in-metrics).

The global metrics panel provides an overview of the running test:

- Number of test iterations per second
- Number of [Virtual Users](https://k6.io/docs/using-k6/scenarios#executors) scheduled
- Percentage of [failed checks](https://k6.io/docs/using-k6/checks)
- Network throughput (number of bytes sent and received per second)
- Number of script errors

A panel is instantiated for each K6 request name that the user enabled in the **K6 Request Name** dropdown list.
The request panel shows throughput and latencies for each selected request:

- Number of HTTP requests per second, grouped by HTTP status code
- Heatmap of the request latencies over time
- Mean latency with threshold at 20 ms and 200 ms
- 90th percentile latency with threshold at 100 ms and 1000 ms

## Setup

More information on how to setup the whole stack in this article: [How to run performance tests with K6, Prometheus and Grafana](https://www.itix.fr/blog/how-to-run-performance-tests-with-k6-prometheus-grafana/)

{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "Prometheus scrapping the statsd_exporter",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "7.3.6"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "panel",
      "id": "heatmap",
      "name": "Heatmap",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "prometheus",
      "name": "Prometheus",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": 13861,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1612798951336,
  "links": [],
  "panels": [
    {
      "collapsed": false,
      "datasource": null,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 10,
      "panels": [],
      "title": "Global metrics",
      "type": "row"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": null,
            "filterable": false
          },
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 4,
        "x": 0,
        "y": 1
      },
      "id": 6,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "last"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.6",
      "targets": [
        {
          "expr": "sum(rate(k6_iterations[$__rate_interval]))",
          "format": "time_series",
          "interval": "",
          "legendFormat": "{{scenario}}",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Iterations per second",
      "transformations": [],
      "type": "stat"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          },
          "unit": "VUs"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 4,
        "x": 4,
        "y": 1
      },
      "id": 4,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "last"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.6",
      "targets": [
        {
          "expr": "k6_vus",
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Virtual Users",
      "type": "stat"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "decimals": 0,
          "mappings": [],
          "noValue": "0",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 0.01
              }
            ]
          },
          "unit": "percentunit"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 4,
        "x": 8,
        "y": 1
      },
      "id": 2,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "last"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.6",
      "targets": [
        {
          "expr": "sum(rate(k6_check{outcome=\"fail\"}[$__rate_interval])) / sum(rate(k6_check[$__rate_interval]))",
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "% Failed Checks",
      "transformations": [],
      "type": "stat"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          },
          "unit": "Bps"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 7,
        "x": 12,
        "y": 1
      },
      "id": 8,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.6",
      "targets": [
        {
          "expr": "sum(rate(k6_data_received[$__rate_interval]))",
          "interval": "",
          "legendFormat": "Received",
          "queryType": "randomWalk",
          "refId": "A"
        },
        {
          "expr": "sum(rate(k6_data_sent[$__rate_interval]))",
          "interval": "",
          "legendFormat": "Sent",
          "refId": "B"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Throughput",
      "type": "stat"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 1
              }
            ]
          },
          "unit": "none"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 3,
        "x": 19,
        "y": 1
      },
      "id": 12,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "last"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.6",
      "targets": [
        {
          "expr": "sum(rate(k6_script_errors[$__rate_interval]))",
          "interval": "",
          "legendFormat": "Script errors",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Errors",
      "type": "stat"
    },
    {
      "collapsed": false,
      "datasource": null,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 7
      },
      "id": 14,
      "panels": [],
      "repeat": "K6RequestName",
      "title": "K6 HTTP Request: ${K6RequestName}",
      "type": "row"
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_PROMETHEUS}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "fill": 8,
      "fillGradient": 0,
      "gridPos": {
        "h": 8,
        "w": 6,
        "x": 0,
        "y": 8
      },
      "hiddenSeries": false,
      "id": 16,
      "legend": {
        "avg": true,
        "current": false,
        "max": true,
        "min": true,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "alertThreshold": false
      },
      "percentage": false,
      "pluginVersion": "7.3.6",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": true,
      "steppedLine": false,
      "targets": [
        {
          "expr": "sum by (status) (rate(k6_http_reqs{name=\"${K6RequestName}\"}[$__rate_interval]))",
          "interval": "",
          "legendFormat": "HTTP {{status}}",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Throughput",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:122",
          "format": "short",
          "label": "",
          "logBase": 1,
          "max": null,
          "min": "0",
          "show": true
        },
        {
          "$$hashKey": "object:123",
          "format": "short",
          "label": "",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "cards": {
        "cardPadding": null,
        "cardRound": null
      },
      "color": {
        "cardColor": "#F2495C",
        "colorScale": "linear",
        "colorScheme": "interpolateRdYlGn",
        "exponent": 0.5,
        "mode": "spectrum"
      },
      "dataFormat": "tsbuckets",
      "datasource": "${DS_PROMETHEUS}",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": null,
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 10,
        "x": 6,
        "y": 8
      },
      "heatmap": {},
      "hideZeroBuckets": false,
      "highlightCards": true,
      "id": 20,
      "legend": {
        "show": false
      },
      "pluginVersion": "7.3.6",
      "reverseYBuckets": false,
      "targets": [
        {
          "expr": "sum(rate(k6_http_${GoHttpMetricName}_bucket{name=\"${K6RequestName}\"}[$__rate_interval])) by (le)",
          "format": "heatmap",
          "instant": false,
          "interval": "",
          "intervalFactor": 2,
          "legendFormat": "{{le}}",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Latency (${GoHttpMetricName})",
      "tooltip": {
        "show": true,
        "showHistogram": false
      },
      "tooltipDecimals": null,
      "type": "heatmap",
      "xAxis": {
        "show": true
      },
      "xBucketNumber": null,
      "xBucketSize": null,
      "yAxis": {
        "decimals": null,
        "format": "short",
        "logBase": 10,
        "max": "10",
        "min": "0",
        "show": true,
        "splitFactor": null
      },
      "yBucketBound": "auto",
      "yBucketNumber": null,
      "yBucketSize": null
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 20
              },
              {
                "color": "dark-red",
                "value": 200
              }
            ]
          },
          "unit": "ms"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 3,
        "x": 16,
        "y": 8
      },
      "id": 25,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "last"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.6",
      "targets": [
        {
          "expr": "1000*sum (rate(k6_http_${GoHttpMetricName}_sum{name=\"${K6RequestName}\"}[$__rate_interval]))/sum (rate(k6_http_${GoHttpMetricName}_count{name=\"${K6RequestName}\"}[$__rate_interval]))",
          "interval": "",
          "legendFormat": "{{status}}",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Mean latency (${GoHttpMetricName})",
      "type": "stat"
    },
    {
      "datasource": "${DS_PROMETHEUS}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "mappings": [],
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 100
              },
              {
                "color": "red",
                "value": 1000
              }
            ]
          },
          "unit": "ms"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 3,
        "x": 19,
        "y": 8
      },
      "id": 27,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "last"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.6",
      "targets": [
        {
          "expr": "1000*histogram_quantile(0.90, sum(rate(k6_http_${GoHttpMetricName}_bucket{name=\"${K6RequestName}\"}[$__rate_interval])) by (le))",
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "90th percentile latency (${GoHttpMetricName})",
      "type": "stat"
    }
  ],
  "refresh": "1s",
  "schemaVersion": 26,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_PROMETHEUS}",
        "definition": "label_values(k6_http_req_duration_count, name)",
        "error": {
          "config": {
            "headers": {
              "X-Grafana-Org-Id": 1
            },
            "hideFromInspector": true,
            "method": "GET",
            "retry": 0,
            "url": "api/datasources/proxy/3/api/v1/series?match%5B%5D=k6_http_req_duration_count&start=1612777352&end=1612798952"
          },
          "data": {
            "error": "Bad Gateway",
            "message": "Bad Gateway",
            "response": ""
          },
          "message": "Bad Gateway",
          "status": 502,
          "statusText": "Bad Gateway"
        },
        "hide": 0,
        "includeAll": false,
        "label": "K6 Request Name",
        "multi": true,
        "name": "K6RequestName",
        "options": [],
        "query": "label_values(k6_http_req_duration_count, name)",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "allValue": null,
        "current": {
          "selected": false,
          "text": "req_blocked",
          "value": "req_blocked"
        },
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": "Go HTTP Metric Name",
        "multi": false,
        "name": "GoHttpMetricName",
        "options": [
          {
            "selected": true,
            "text": "req_duration",
            "value": "req_duration"
          },
          {
            "selected": false,
            "text": "req_blocked",
            "value": "req_blocked"
          },
          {
            "selected": false,
            "text": "req_connecting",
            "value": "req_connecting"
          },
          {
            "selected": false,
            "text": "req_receiving",
            "value": "req_receiving"
          },
          {
            "selected": false,
            "text": "req_sending",
            "value": "req_sending"
          },
          {
            "selected": false,
            "text": "req_tls_handshaking",
            "value": "req_tls_handshaking"
          },
          {
            "selected": false,
            "text": "req_waiting",
            "value": "req_waiting"
          }
        ],
        "query": "req_duration,req_blocked,req_connecting,req_receiving,req_sending,req_tls_handshaking,req_waiting",
        "queryValue": "",
        "skipUrlSync": false,
        "type": "custom"
      }
    ]
  },
  "time": {
    "from": "now-2m",
    "to": "now-2s"
  },
  "timepicker": {
    "nowDelay": "",
    "refresh_intervals": [
      "1s",
      "5s",
      "10s",
      "30s"
    ]
  },
  "timezone": "",
  "title": "k6.io metrics with statsd_exporter and Prometheus",
  "uid": "zDpLnqaMz",
  "version": 40,
  "description": "k6.io load tests results"
}