Grafana dashboard: SLO Dashboard
Description: Tracks service's SLO and error budget consumption.

The dashboard is based on the following example: [https://github.com/google/prometheus-slo-burn-example](https://github.com/google/prometheus-slo-burn-example)

The dashboard assumes that there is a *probe*, which probes service's *availability* and exports the data using metrics, which are then used by this dashboard. There are supposed to be two metrics exposed, which can have any name (it is configurable in the parameters):
- requests_error_count - the number of requests to the service returned an error;
- requests_total_count - the total number of requests to the service.

Settings for color switching are needed to be adjusted:

1. After `error_budget` parameter is adjusted for the required level, it is necessary to adjust the thresholds for color switching at `Error Budget Left` singlestat panel. It can be done via `Vizualization` tab.

2. After `service_slo_target` parameter is adjusted for the required level, it is necessary to adjust the thresholds for color switching at `Current SLO` singlestat panel. It can be done via `Vizualization` tab.

The highest panel has two states:
- *Status is OK* - there are no alerts firing for the last 5 minutes.
- *Alerts are firing* - there are alerts firing for the last 5 minutes, pay attention.

The titles for both states can be changed via `Vizualization` tab, in `Value mappings` section.

Welcome [to contribute](https://github.com/ilyavy/grafana-dashboards)!

{
  "__inputs": [
    {
      "name": "VAR_SERVICE_REQUESTS_ERROR_COUNT",
      "type": "constant",
      "label": "service_requests_error_count",
      "value": "requests_error_count{service=\"my-service\"}",
      "description": "The counter for requests to the service, which returned an error"
    },
    {
      "name": "VAR_SERVICE_REQUESTS_TOTAL_COUNT",
      "type": "constant",
      "label": "service_requests_total_count",
      "value": "requests_total_count{service=\"my-service\"}",
      "description": "The counter for total number of requests to the service"
    },
    {
      "name": "VAR_ALERTS_FILTER_CRITERIA",
      "type": "constant",
      "label": "alerts_filter_criteria",
      "value": "service=\"my-service\"",
      "description": "The criteria, which is used to filter alerts, can have several parameters separated by comma"
    },
    {
      "name": "VAR_SERVICE_SLO_TARGET",
      "type": "constant",
      "label": "service_slo_target",
      "value": "95",
      "description": "SLO target in percents"
    },
    {
      "name": "VAR_ERROR_BUDGET",
      "type": "constant",
      "label": "error_budget",
      "value": "0.05",
      "description": "Target Error Budget (should be a fractional number)"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "6.1.6"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "panel",
      "id": "singlestat",
      "name": "Singlestat",
      "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": 11222,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1574165162116,
  "links": [],
  "panels": [
    {
      "cacheTimeout": null,
      "colorBackground": false,
      "colorValue": false,
      "colors": [
        "#299c46",
        "rgba(237, 129, 40, 0.89)",
        "#d44a3a"
      ],
      "format": "none",
      "gauge": {
        "maxValue": 100,
        "minValue": 0,
        "show": false,
        "thresholdLabels": false,
        "thresholdMarkers": true
      },
      "gridPos": {
        "h": 2,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 26,
      "interval": null,
      "links": [],
      "mappingType": 2,
      "mappingTypes": [
        {
          "name": "value to text",
          "value": 1
        },
        {
          "name": "range to text",
          "value": 2
        }
      ],
      "maxDataPoints": 100,
      "nullPointMode": "connected",
      "nullText": null,
      "options": {},
      "postfix": "",
      "postfixFontSize": "50%",
      "prefix": "",
      "prefixFontSize": "50%",
      "rangeMaps": [
        {
          "from": "null",
          "text": "Status is OK",
          "to": "null"
        },
        {
          "from": "1",
          "text": "Alerts are firing!",
          "to": "999999999999999"
        }
      ],
      "sparkline": {
        "fillColor": "rgba(31, 118, 189, 0.18)",
        "full": false,
        "lineColor": "rgb(31, 120, 193)",
        "show": false
      },
      "tableColumn": "",
      "targets": [
        {
          "expr": "sum_over_time(ALERTS{alertstate=\"firing\",$alerts_filter_criteria}[5m])",
          "format": "time_series",
          "intervalFactor": 1,
          "refId": "A"
        }
      ],
      "thresholds": "0,1",
      "timeFrom": null,
      "timeShift": null,
      "title": "SLO Dashboard",
      "transparent": true,
      "type": "singlestat",
      "valueFontSize": "80%",
      "valueMaps": [
        {
          "op": "=",
          "text": "Status is OK",
          "value": "null"
        },
        {
          "op": "=",
          "text": "",
          "value": ""
        }
      ],
      "valueName": "current"
    },
    {
      "cacheTimeout": null,
      "colorBackground": false,
      "colorPostfix": true,
      "colorValue": true,
      "colors": [
        "#d44a3a",
        "rgba(237, 129, 40, 0.89)",
        "#299c46"
      ],
      "decimals": 2,
      "format": "short",
      "gauge": {
        "maxValue": 100,
        "minValue": 0,
        "show": false,
        "thresholdLabels": false,
        "thresholdMarkers": true
      },
      "gridPos": {
        "h": 2,
        "w": 12,
        "x": 0,
        "y": 2
      },
      "id": 28,
      "interval": null,
      "links": [],
      "mappingType": 1,
      "mappingTypes": [
        {
          "name": "value to text",
          "value": 1
        },
        {
          "name": "range to text",
          "value": 2
        }
      ],
      "maxDataPoints": 100,
      "nullPointMode": "connected",
      "nullText": null,
      "options": {},
      "postfix": " hours",
      "postfixFontSize": "50%",
      "prefix": "",
      "prefixFontSize": "50%",
      "rangeMaps": [
        {
          "from": "null",
          "text": "N/A",
          "to": "null"
        }
      ],
      "sparkline": {
        "fillColor": "rgba(31, 118, 189, 0.18)",
        "full": false,
        "lineColor": "rgb(31, 120, 193)",
        "show": false
      },
      "tableColumn": "",
      "targets": [
        {
          "expr": "28 * 24 * ($error_budget - sum(rate($service_requests_error_count[28d])) by (job) / sum(rate($service_requests_total_count[28d])) by (job))",
          "format": "time_series",
          "intervalFactor": 1,
          "refId": "A"
        }
      ],
      "thresholds": "6,20",
      "timeFrom": null,
      "timeShift": null,
      "title": "Error Budget Left",
      "transparent": true,
      "type": "singlestat",
      "valueFontSize": "80%",
      "valueMaps": [
        {
          "op": "=",
          "text": "N/A",
          "value": "null"
        }
      ],
      "valueName": "current"
    },
    {
      "cacheTimeout": null,
      "colorBackground": false,
      "colorValue": true,
      "colors": [
        "#d44a3a",
        "rgba(237, 129, 40, 0.89)",
        "#299c46"
      ],
      "decimals": 3,
      "format": "percentunit",
      "gauge": {
        "maxValue": 100,
        "minValue": 0,
        "show": false,
        "thresholdLabels": false,
        "thresholdMarkers": true
      },
      "gridPos": {
        "h": 2,
        "w": 12,
        "x": 12,
        "y": 2
      },
      "id": 30,
      "interval": null,
      "links": [],
      "mappingType": 1,
      "mappingTypes": [
        {
          "name": "value to text",
          "value": 1
        },
        {
          "name": "range to text",
          "value": 2
        }
      ],
      "maxDataPoints": 100,
      "nullPointMode": "connected",
      "nullText": null,
      "options": {},
      "postfix": "",
      "postfixFontSize": "50%",
      "prefix": "",
      "prefixFontSize": "50%",
      "rangeMaps": [
        {
          "from": "null",
          "text": "N/A",
          "to": "null"
        }
      ],
      "sparkline": {
        "fillColor": "rgba(31, 118, 189, 0.18)",
        "full": false,
        "lineColor": "rgb(31, 120, 193)",
        "show": false
      },
      "tableColumn": "",
      "targets": [
        {
          "expr": "1 - sum(rate($service_requests_error_count[28d])) by (job) / sum(rate($service_requests_total_count[28d])) by (job)",
          "format": "time_series",
          "intervalFactor": 1,
          "refId": "A"
        }
      ],
      "thresholds": "0.95,0.97",
      "timeFrom": null,
      "timeShift": null,
      "title": "Current SLO",
      "transparent": true,
      "type": "singlestat",
      "valueFontSize": "80%",
      "valueMaps": [
        {
          "op": "=",
          "text": "N/A",
          "value": "null"
        }
      ],
      "valueName": "current"
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "fill": 0,
      "gridPos": {
        "h": 11,
        "w": 24,
        "x": 0,
        "y": 4
      },
      "id": 22,
      "legend": {
        "alignAsTable": true,
        "avg": false,
        "current": true,
        "max": false,
        "min": false,
        "rightSide": false,
        "show": true,
        "total": false,
        "values": true
      },
      "lines": true,
      "linewidth": 3,
      "links": [],
      "nullPointMode": "null",
      "options": {},
      "paceLength": 10,
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "$service_slo_target",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "target",
          "refId": "B"
        },
        {
          "expr": "(1 - sum(rate($service_requests_error_count[28d])) by (job) / sum(rate($service_requests_total_count[28d])) by (job)) * 100",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "real",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "28 Day Window SLO",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "percent",
          "label": null,
          "logBase": 1,
          "max": "100",
          "min": null,
          "show": true
        },
        {
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": false
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "description": "",
      "fill": 1,
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 15
      },
      "id": 16,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "options": {},
      "paceLength": 10,
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "sum(rate($service_requests_error_count[1m])) by (job) / sum(rate($service_requests_total_count[1m])) by (job)",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "error ratio",
          "refId": "A"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Probe Error Ratio",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "percentunit",
          "label": null,
          "logBase": 1,
          "max": "1.1",
          "min": "0",
          "show": true
        },
        {
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "fill": 1,
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 15
      },
      "id": 24,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "links": [],
      "nullPointMode": "null",
      "options": {},
      "paceLength": 10,
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "sum(rate($service_requests_total_count[1m])) by (job)",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "total requests rate",
          "refId": "A"
        },
        {
          "expr": "sum(rate($service_requests_error_count[1m])) by (job)",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "error responses rate",
          "refId": "B"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Requests Rate",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "reqps",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": 0,
          "show": true
        },
        {
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    }
  ],
  "refresh": "5m",
  "schemaVersion": 18,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {
          "value": "${VAR_SERVICE_REQUESTS_ERROR_COUNT}",
          "text": "${VAR_SERVICE_REQUESTS_ERROR_COUNT}"
        },
        "hide": 2,
        "label": "",
        "name": "service_requests_error_count",
        "options": [
          {
            "value": "${VAR_SERVICE_REQUESTS_ERROR_COUNT}",
            "text": "${VAR_SERVICE_REQUESTS_ERROR_COUNT}"
          }
        ],
        "query": "${VAR_SERVICE_REQUESTS_ERROR_COUNT}",
        "skipUrlSync": false,
        "type": "constant"
      },
      {
        "current": {
          "value": "${VAR_SERVICE_REQUESTS_TOTAL_COUNT}",
          "text": "${VAR_SERVICE_REQUESTS_TOTAL_COUNT}"
        },
        "hide": 2,
        "label": null,
        "name": "service_requests_total_count",
        "options": [
          {
            "value": "${VAR_SERVICE_REQUESTS_TOTAL_COUNT}",
            "text": "${VAR_SERVICE_REQUESTS_TOTAL_COUNT}"
          }
        ],
        "query": "${VAR_SERVICE_REQUESTS_TOTAL_COUNT}",
        "skipUrlSync": false,
        "type": "constant"
      },
      {
        "current": {
          "value": "${VAR_ALERTS_FILTER_CRITERIA}",
          "text": "${VAR_ALERTS_FILTER_CRITERIA}"
        },
        "hide": 2,
        "label": null,
        "name": "alerts_filter_criteria",
        "options": [
          {
            "value": "${VAR_ALERTS_FILTER_CRITERIA}",
            "text": "${VAR_ALERTS_FILTER_CRITERIA}"
          }
        ],
        "query": "${VAR_ALERTS_FILTER_CRITERIA}",
        "skipUrlSync": false,
        "type": "constant"
      },
      {
        "current": {
          "value": "${VAR_SERVICE_SLO_TARGET}",
          "text": "${VAR_SERVICE_SLO_TARGET}"
        },
        "hide": 2,
        "label": null,
        "name": "service_slo_target",
        "options": [
          {
            "value": "${VAR_SERVICE_SLO_TARGET}",
            "text": "${VAR_SERVICE_SLO_TARGET}"
          }
        ],
        "query": "${VAR_SERVICE_SLO_TARGET}",
        "skipUrlSync": false,
        "type": "constant"
      },
      {
        "current": {
          "value": "${VAR_ERROR_BUDGET}",
          "text": "${VAR_ERROR_BUDGET}"
        },
        "hide": 2,
        "label": null,
        "name": "error_budget",
        "options": [
          {
            "value": "${VAR_ERROR_BUDGET}",
            "text": "${VAR_ERROR_BUDGET}"
          }
        ],
        "query": "${VAR_ERROR_BUDGET}",
        "skipUrlSync": false,
        "type": "constant"
      }
    ]
  },
  "time": {
    "from": "now-28d",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "28d"
    ]
  },
  "timezone": "",
  "title": "SLO Dashboard",
  "version": 1,
  "description": "Tracks service's SLO and error budget consumption."
}