Grafana dashboard: Octopus Deploy DeploymentHistory
Description: Octopus Deploy reporting on projects and tasks

A fork of https://grafana.com/grafana/dashboards/11720

GitHub: https://github.com/johnkors/grafana-dashboards/blob/master/octopusdeploy/grafana-octopus-deploy.json

Changes from the original:
- The original is missing stats from deployments removed due to retention policies
- Moved queries to the DeploymentHistory table in Octopus
- Bugfix: the top stat was missing an upper bound

{
  "__inputs": [
    {
      "name": "DS_OCTOPUSDEPLOY",
      "label": "OctopusDeploy",
      "description": "",
      "type": "datasource",
      "pluginId": "mssql",
      "pluginName": "Microsoft SQL Server"
    }
  ],
  "__requires": [
    {
      "type": "panel",
      "id": "bargauge",
      "name": "Bar Gauge",
      "version": ""
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "6.6.1"
    },
    {
      "type": "panel",
      "id": "grafana-piechart-panel",
      "name": "Pie Chart",
      "version": "1.4.0"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "mssql",
      "name": "Microsoft SQL Server",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    },
    {
      "type": "panel",
      "id": "text",
      "name": "Text",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "limit": 100,
        "name": "Annotations & Alerts",
        "showIn": 0,
        "type": "dashboard"
      },
      {
        "datasource": "${DS_OCTOPUSDEPLOY}",
        "enable": false,
        "hide": false,
        "iconColor": "#8AB8FF",
        "limit": 100,
        "name": "📝 Deployments Annotations",
        "rawQuery": "SELECT\n   CompletedTime  as time,\n   ProjectName as text,\n   CONCAT(EnvironmentName, ',' , ReleaseVersion, ',' , DeployedBy) as tags\n FROM\n   DeploymentHistory\n WHERE\n  TaskState = 'Success'  AND ProjectName IN ($project) AND EnvironmentName IN ($environment) AND\n  CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 )\nORDER BY CompletedTime  ASC\n",
        "showIn": 0,
        "tags": [],
        "type": "tags"
      }
    ]
  },
  "description": "Octopus Deploy reporting on projects and tasks",
  "editable": true,
  "gnetId": 11996,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1585481148962,
  "links": [],
  "panels": [
    {
      "content": "<br>\n\n# Octopus Deploy\n<center>\n<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAI0AAACMCAMAAAB23NoyAAAACXBIWXMAAAsSAAALEgHS3X78AAAAM1BMVEX///8vk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+Avk+CYbWlbAAAAEHRSTlMAECAwQFBgcICQoLDA0ODwVOCoyAAAA3ZJREFUeNrtnMl25CAMRcGADRSD/v9rs8jJWMVgJLm08Nt3cgNCeki4lbp169atoTZrrdXvptDWx1TgWzmFw74HxYUML5W8uRolVuiohOuAtC8wVN6vCdkIcyr8PDrAvApzSB8VTunBeO63BGdVrZSF+VTgiZgIa0oMu6UzrCqT45gK6ypGEAxANYJgaDcLDUOJgwjgH0UqmgQUOmhgPNCIJJItEQwUgtDRhYoGPJ4mAJ3Qe2UIYSDJOE9fskJCmGRxaJcGuTjESwPwwNBEahrYED6YHAaTcw56mrJOk+lp1reKYaMQpfzgoFk+VQ8OmrpKUzloVkunYYEBt0az89AsZhzPQxNkVExcHZdFAzfNTXPTkOYbEJWLQVSdYqLZJOXiKslsLXs/nhq+OpixLDTLLSVRJp0lcNYnaAxWFHHV1GLKAtNWIVoU9FuF621VMTFM3Z5FJRuOLgWqz0bewcEOPnYxJ0oppTRlHFeFVRQUNko5Gf1QhpTj8DSE1YHgSYUXReNE0dib5oqd8qKi+CHqhFdR2Q+f/igrA34CTTtLRJ4qYvOXJS0N8pDTj2Ewe0U/2ES8J+Po4Czj8DRwFnEMzyRx7SEr4aMk/MnSGfiUNkEwAPVUyTIFmHWir2QrsGv62fEBV2ju6ah+wDWaqaG2wFUannR9up1VEPSaeGGy7cR81NtzqYtltg/YXJjSiKXYMx5Fvzye5udLhN5WmWbGC1vtwLRM2fG63FWtjzJcm+aCJ9vwFrHfdTcNy5aVUi6W7gWr1eIru1KqDBLGy8Vp/uSwamY+Pzt6SVq3/r9O7Ww6rFKlzdJwpPvgEpjaZr9u5/142ntmPY0uF6EzsR3d854iP5puVPz7845+pn0yKIM0vP3+ri8HN2oaH8O19b3Gcx36LWMP7723duK05fEQ1HddNukrRDu+evm+6V+959VO3usg+/4dZHFxXuSSqidugn5wJVobVvmptpCbcC9bxm/VY8phmxkv9efbvbWxYp5zkHPOzpX/RRX5gKGRKtKcz/x2E4sfVE2WvDDtes3u/bHaqpgcTjqG1vmQJk6/c9hYaPIUzNPZKywwfyp4nG8tRx4aN/sbCvXcsP9bwonheWWC+SpU455Loh3/tPaqABQ/rnK/LFV9+3+W8btKOyVAXz2xoERI+wpQnBIjY9StW7du/dUHI6Ym0KauAw0AAAAASUVORK5CYII=\">\n</center>\n\n",
      "datasource": null,
      "gridPos": {
        "h": 7,
        "w": 3,
        "x": 0,
        "y": 0
      },
      "id": 17,
      "mode": "markdown",
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "transparent": true,
      "type": "text"
    },
    {
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "gridPos": {
        "h": 7,
        "w": 21,
        "x": 3,
        "y": 0
      },
      "id": 7,
      "options": {
        "colorMode": "background",
        "fieldOptions": {
          "calcs": [
            "sum"
          ],
          "defaults": {
            "mappings": [
              {
                "from": "",
                "id": 1,
                "operator": "",
                "text": "",
                "to": "",
                "type": 1,
                "value": ""
              }
            ],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "semi-dark-blue",
                  "value": null
                }
              ]
            },
            "title": "Deployments ${__series.name}",
            "unit": "locale"
          },
          "overrides": [],
          "values": false
        },
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto"
      },
      "pluginVersion": "6.6.1",
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT\n  COUNT(d.TaskId) as Deployment,\n  CASE\n    WHEN d.TaskState = 'Failed' THEN 'Failed'\n    WHEN d.TaskState = 'Success' THEN 'Success'\n    WHEN d.TaskState = 'Canceled' THEN 'Cancelled'\n    WHEN d.TaskState = 'Queued' THEN 'Queued'\n    WHEN d.TaskState = 'Executing' THEN 'Executing'\n    WHEN d.TaskState = 'TimedOut' THEN 'Timed Out'\n    WHEN d.TaskState = 'Cancelling' THEN 'Cancelling'\n  END as metric,\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE \n  d.CompletedTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0),  d.TaskState\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0), COUNT(1) DESC",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "type": "stat"
    },
    {
      "aliasColors": {},
      "bars": true,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "decimals": 0,
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 9,
        "w": 24,
        "x": 0,
        "y": 7
      },
      "hiddenSeries": false,
      "id": 37,
      "interval": "",
      "legend": {
        "alignAsTable": true,
        "avg": false,
        "current": false,
        "hideEmpty": false,
        "hideZero": false,
        "max": false,
        "min": false,
        "rightSide": true,
        "show": true,
        "sort": "total",
        "sortDesc": true,
        "total": true,
        "values": true
      },
      "lines": false,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "alias": "Failed",
          "color": "rgba(245, 54, 54, 0.9)"
        },
        {
          "alias": "Success",
          "color": "rgba(50, 172, 45, 0.97)"
        },
        {
          "alias": "Cancelled",
          "color": "rgba(237, 129, 40, 0.89)"
        },
        {
          "alias": "Duration",
          "bars": false,
          "color": "rgb(255, 255, 255)",
          "fill": 0,
          "fillGradient": 0,
          "lines": true,
          "points": true,
          "yaxis": 2
        },
        {
          "alias": "Queued",
          "color": "#434143"
        },
        {
          "alias": "Executing",
          "color": "#1f60c4"
        },
        {
          "alias": "Timed Out",
          "color": "#8f3bb8"
        },
        {
          "alias": "Canceling",
          "color": "#aa8800"
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  COUNT(d.ReleaseId) AS Deployment,\n    CASE\n    WHEN d.TaskState = 'Failed' THEN (d.ProjectName + ' - Failed')\n    WHEN d.TaskState = 'Success' THEN (d.ProjectName + ' - Success')\n    WHEN d.TaskState = 'Canceled' THEN (d.ProjectName + ' - Cancelled')\n    WHEN d.TaskState = 'Queued' THEN (d.ProjectName + ' - Queued')\n    WHEN d.TaskState = 'Executing' THEN (d.ProjectName + ' - Executing')\n    WHEN d.TaskState = 'TimedOut' THEN (d.ProjectName + ' - Timed Out')\n    WHEN d.TaskState = 'Cancelling' THEN (d.ProjectName + ' - Cancelling')\n  END as metric,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE \n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0), d.TaskState, d.ProjectName\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0)",
          "refId": "B"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Deployment Status by Product",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": 0,
          "format": "none",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": null,
          "format": "s",
          "label": "",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": false
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": true,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 6,
        "w": 24,
        "x": 0,
        "y": 16
      },
      "hiddenSeries": false,
      "id": 30,
      "interval": "",
      "legend": {
        "avg": false,
        "current": false,
        "hideEmpty": false,
        "hideZero": false,
        "max": false,
        "min": false,
        "show": true,
        "total": true,
        "values": true
      },
      "lines": false,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "alias": "Failed",
          "color": "rgba(245, 54, 54, 0.9)"
        },
        {
          "alias": "Success",
          "color": "rgba(50, 172, 45, 0.97)"
        },
        {
          "alias": "Cancelled",
          "color": "rgba(237, 129, 40, 0.89)"
        },
        {
          "alias": "Duration",
          "bars": false,
          "color": "rgb(255, 255, 255)",
          "fill": 0,
          "fillGradient": 0,
          "lines": true,
          "points": true,
          "yaxis": 2
        },
        {
          "alias": "Queued",
          "color": "#434143"
        },
        {
          "alias": "Executing",
          "color": "#1f60c4"
        },
        {
          "alias": "Timed Out",
          "color": "#8f3bb8"
        },
        {
          "alias": "Canceling",
          "color": "#aa8800"
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  AVG(DATEDIFF(ss, d.QueueTime, d.CompletedTime)) AS Duration,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0)\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0)",
          "refId": "A"
        },
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  COUNT(d.ReleaseId) AS Deployment,\n    CASE\n    WHEN d.TaskState = 'Failed' THEN 'Failed'\n    WHEN d.TaskState = 'Success' THEN 'Success'\n    WHEN d.TaskState = 'Canceled' THEN 'Cancelled'\n    WHEN d.TaskState = 'Queued' THEN 'Queued'\n    WHEN d.TaskState = 'Executing' THEN 'Executing'\n    WHEN d.TaskState = 'TimedOut' THEN 'Timed Out'\n    WHEN d.TaskState = 'Cancelling' THEN 'Cancelling'\n  END as metric,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE \n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0), d.TaskState\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0)",
          "refId": "B"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Deployment Status and Duration",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": null,
          "format": "s",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": true,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 6,
        "w": 12,
        "x": 0,
        "y": 22
      },
      "hiddenSeries": false,
      "id": 34,
      "interval": "",
      "legend": {
        "avg": false,
        "current": false,
        "hideEmpty": false,
        "hideZero": false,
        "max": false,
        "min": false,
        "show": true,
        "total": true,
        "values": true
      },
      "lines": false,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "alias": "Failed",
          "color": "rgba(245, 54, 54, 0.9)"
        },
        {
          "alias": "Success",
          "color": "rgba(50, 172, 45, 0.97)"
        },
        {
          "alias": "Cancelled",
          "color": "rgba(237, 129, 40, 0.89)"
        },
        {
          "alias": "Duration",
          "bars": false,
          "color": "rgb(255, 255, 255)",
          "fill": 0,
          "fillGradient": 0,
          "lines": true,
          "points": true,
          "yaxis": 2
        },
        {
          "alias": "Queued",
          "color": "#434143"
        },
        {
          "alias": "Executing",
          "color": "#1f60c4"
        },
        {
          "alias": "Timed Out",
          "color": "#8f3bb8"
        },
        {
          "alias": "Canceling",
          "color": "#aa8800"
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  AVG(DATEDIFF(ss, d.QueueTime, d.CompletedTime)) AS Duration,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(d.CompletedTime, '1h', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '1h', 0)\nORDER BY $__timeGroup(d.CompletedTime, '1h', 0)",
          "refId": "A"
        },
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  COUNT(d.ReleaseId) AS Deployment,\n    CASE\n    WHEN d.TaskState = 'Failed' THEN 'Failed'\n    WHEN d.TaskState = 'Success' THEN 'Success'\n    WHEN d.TaskState = 'Canceled' THEN 'Cancelled'\n    WHEN d.TaskState = 'Queued' THEN 'Queued'\n    WHEN d.TaskState = 'Executing' THEN 'Executing'\n    WHEN d.TaskState = 'TimedOut' THEN 'Timed Out'\n    WHEN d.TaskState = 'Cancelling' THEN 'Cancelling'\n  END as metric,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(d.CompletedTime, '1h', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE \n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '1h', 0), d.TaskState\nORDER BY $__timeGroup(d.CompletedTime, '1h', 0)",
          "refId": "B"
        }
      ],
      "thresholds": [],
      "timeFrom": "now/w",
      "timeRegions": [],
      "timeShift": null,
      "title": "Deployment Status and Duration (Week so far)",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": null,
          "format": "s",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": true,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 6,
        "w": 12,
        "x": 12,
        "y": 22
      },
      "hiddenSeries": false,
      "id": 35,
      "interval": "",
      "legend": {
        "avg": false,
        "current": false,
        "hideEmpty": false,
        "hideZero": false,
        "max": false,
        "min": false,
        "show": true,
        "total": true,
        "values": true
      },
      "lines": false,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "alias": "Failed",
          "color": "rgba(245, 54, 54, 0.9)"
        },
        {
          "alias": "Success",
          "color": "rgba(50, 172, 45, 0.97)"
        },
        {
          "alias": "Cancelled",
          "color": "rgba(237, 129, 40, 0.89)"
        },
        {
          "alias": "Duration",
          "bars": false,
          "color": "rgb(255, 255, 255)",
          "fill": 0,
          "fillGradient": 0,
          "lines": true,
          "points": true,
          "yaxis": 2
        },
        {
          "alias": "Queued",
          "color": "#434143"
        },
        {
          "alias": "Executing",
          "color": "#1f60c4"
        },
        {
          "alias": "Timed Out",
          "color": "#8f3bb8"
        },
        {
          "alias": "Canceling",
          "color": "#aa8800"
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  AVG(DATEDIFF(ss, d.QueueTime, d.CompletedTime)) AS Duration,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(d.CompletedTime, '15m', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '15m', 0)\nORDER BY $__timeGroup(d.CompletedTime, '15m', 0)",
          "refId": "A"
        },
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  COUNT(d.ReleaseId) AS Deployment,\n    CASE\n    WHEN d.TaskState = 'Failed' THEN 'Failed'\n    WHEN d.TaskState = 'Success' THEN 'Success'\n    WHEN d.TaskState = 'Canceled' THEN 'Cancelled'\n    WHEN d.TaskState = 'Queued' THEN 'Queued'\n    WHEN d.TaskState = 'Executing' THEN 'Executing'\n    WHEN d.TaskState = 'TimedOut' THEN 'Timed Out'\n    WHEN d.TaskState = 'Cancelling' THEN 'Cancelling'\n  END as metric,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(d.CompletedTime, '15m'', 0 ) AS [time]\nFROM\n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE \n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '15m', 0), d.TaskState\nORDER BY $__timeGroup(d.CompletedTime, '15m', 0)",
          "refId": "B"
        }
      ],
      "thresholds": [],
      "timeFrom": "now/d",
      "timeRegions": [],
      "timeShift": null,
      "title": "Deployment Status and Duration (Today so far)",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "decimals": null,
          "format": "s",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {
        "Canceling": "#aa8800",
        "Cancelled": "#ef843c",
        "Executing": "#1f60c4",
        "Failed": "#C4162A",
        "Queued": "#434143",
        "Success": "#37872D",
        "Timed Out": "#8f3bb8"
      },
      "breakPoint": "50%",
      "cacheTimeout": null,
      "combine": {
        "label": "Others",
        "threshold": 0
      },
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fontSize": "80%",
      "format": "short",
      "gridPos": {
        "h": 7,
        "w": 12,
        "x": 0,
        "y": 28
      },
      "id": 21,
      "interval": null,
      "legend": {
        "header": "",
        "percentage": true,
        "show": true,
        "values": false
      },
      "legendType": "Right side",
      "links": [],
      "maxDataPoints": 3,
      "nullPointMode": "connected",
      "pieType": "donut",
      "pluginVersion": "6.6.1",
      "strokeWidth": "1",
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT\n  COUNT(d.TaskId) as Deployment,\n  CASE\n    WHEN d.TaskState = 'Failed' THEN 'Failed'\n    WHEN d.TaskState = 'Success' THEN 'Success'\n    WHEN d.TaskState = 'Canceled' THEN 'Cancelled'\n    WHEN d.TaskState = 'Queued' THEN 'Queued'\n    WHEN d.TaskState = 'Executing' THEN 'Executing'\n    WHEN d.TaskState = 'TimedOut' THEN 'Timed Out'\n    WHEN d.TaskState = 'Cancelling' THEN 'Cancelling'\n  END as metric,\n  $__timeGroup(d.QueueTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE \n  d.QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.QueueTime, '$interval', 0),  d.TaskState\nORDER BY $__timeGroup(d.QueueTime, '$interval', 0)",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Deployments",
      "transparent": true,
      "type": "grafana-piechart-panel",
      "valueName": "total"
    },
    {
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "gridPos": {
        "h": 5,
        "w": 12,
        "x": 12,
        "y": 28
      },
      "id": 32,
      "options": {
        "displayMode": "gradient",
        "fieldOptions": {
          "calcs": [
            "sum"
          ],
          "defaults": {
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "rgba(50, 172, 45, 0.97)",
                  "value": null
                }
              ]
            },
            "unit": "short"
          },
          "overrides": [],
          "values": false
        },
        "orientation": "vertical",
        "showUnfilled": true
      },
      "pluginVersion": "6.6.1",
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT\n  d.EnvironmentName as Environment,\n  COUNT(d.TaskId) AS Duration,\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0), d.EnvironmentName\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0)",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Deployments per-environment",
      "type": "bargauge"
    },
    {
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "gridPos": {
        "h": 5,
        "w": 12,
        "x": 12,
        "y": 33
      },
      "id": 27,
      "options": {
        "colorMode": "background",
        "fieldOptions": {
          "calcs": [
            "mean"
          ],
          "defaults": {
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "semi-dark-yellow",
                  "value": null
                }
              ]
            },
            "title": "⏱️ Avg. Duration of Successful Deployments",
            "unit": "s"
          },
          "overrides": [],
          "values": false
        },
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto"
      },
      "pluginVersion": "6.6.1",
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT \n  AVG(DATEDIFF(ss, d.QueueTime, d.CompletedTime)) AS Duration,\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project) AND\n  d.TaskState = 'Success'\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0)\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0)",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "transparent": true,
      "type": "stat"
    },
    {
      "columns": [],
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fontSize": "100%",
      "gridPos": {
        "h": 13,
        "w": 12,
        "x": 0,
        "y": 35
      },
      "id": 33,
      "pageSize": 25,
      "showHeader": true,
      "sort": {
        "col": null,
        "desc": false
      },
      "styles": [
        {
          "alias": "Project 🚧",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "ProjectName",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "Count 🔢",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 0,
          "mappingType": 1,
          "pattern": "Total",
          "thresholds": [],
          "type": "number",
          "unit": "short"
        }
      ],
      "targets": [
        {
          "alias": "",
          "format": "table",
          "hide": false,
          "rawSql": "SELECT TOP 10\n  d.ProjectName AS ProjectName,\n  COUNT(d.ProjectName) AS Total\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY d.ProjectName\nORDER BY count(1) DESC",
          "refId": "B"
        },
        {
          "alias": "",
          "format": "table",
          "hide": true,
          "rawSql": "SELECT \n  COUNT(d.ReleaseId) AS Deployment,\n  s.State AS metric,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(s.CompletedTime, '1d', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\n  INNER JOIN [Octopus].[dbo].[DeploymentEnvironment] e ON e.Id = d.EnvironmentId\n  INNER JOIN [Octopus].[dbo].[Project] p ON p.Id = d.ProjectId\n  INNER JOIN [Octopus].[dbo].[Release] r ON r.Id = d.ReleaseId\n  INNER JOIN [Octopus].[dbo].[ServerTask] s ON s.Id = d.TaskId\nWHERE \n  s.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  s.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  e.Name IN ($environment) AND\n  p.Name IN ($project)\nGROUP BY  $__timeGroup(s.CompletedTime, '1d', 0), s.State\nORDER BY $__timeGroup(s.CompletedTime, '1d', 0)",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Most Deployed Projects",
      "transform": "table",
      "type": "table"
    },
    {
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "gridPos": {
        "h": 5,
        "w": 12,
        "x": 12,
        "y": 38
      },
      "id": 28,
      "options": {
        "displayMode": "gradient",
        "fieldOptions": {
          "calcs": [
            "mean"
          ],
          "defaults": {
            "mappings": [],
            "max": 130,
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "rgba(50, 172, 45, 0.97)",
                  "value": null
                }
              ]
            },
            "unit": "s"
          },
          "overrides": [],
          "values": false
        },
        "orientation": "vertical",
        "showUnfilled": true
      },
      "pluginVersion": "6.6.1",
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT\n  d.EnvironmentName as Environment,\n  AVG(DATEDIFF(ss, d.QueueTime, d.CompletedTime)) AS Duration,\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0), d.EnvironmentName\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0)",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "⏱️ Avg. Duration of Releases",
      "type": "bargauge"
    },
    {
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "gridPos": {
        "h": 5,
        "w": 12,
        "x": 12,
        "y": 43
      },
      "id": 29,
      "options": {
        "displayMode": "gradient",
        "fieldOptions": {
          "calcs": [
            "sum"
          ],
          "defaults": {
            "decimals": 2,
            "links": [],
            "mappings": [],
            "max": 360000,
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "yellow",
                  "value": null
                }
              ]
            },
            "unit": "s"
          },
          "overrides": [],
          "values": false
        },
        "orientation": "vertical",
        "showUnfilled": true
      },
      "pluginVersion": "6.6.1",
      "targets": [
        {
          "alias": "",
          "format": "time_series",
          "hide": false,
          "rawSql": "SELECT\n  d.EnvironmentName as Environment,\n  DATEDIFF(ss, d.QueueTime, d.CompletedTime) AS Duration,\n  $__timeGroup(d.CompletedTime, '$interval', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND   \n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nGROUP BY  $__timeGroup(d.CompletedTime, '$interval', 0), d.EnvironmentName, DATEDIFF(ss, d.QueueTime, d.CompletedTime)\nORDER BY $__timeGroup(d.CompletedTime, '$interval', 0)",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "⏱️ Total Duration of Releases",
      "type": "bargauge"
    },
    {
      "columns": [],
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fontSize": "100%",
      "gridPos": {
        "h": 9,
        "w": 24,
        "x": 0,
        "y": 48
      },
      "id": 14,
      "pageSize": 100,
      "showHeader": true,
      "sort": {
        "col": null,
        "desc": false
      },
      "styles": [
        {
          "alias": "Project 🚧",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "ProjectName",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "State ⭐️",
          "align": "auto",
          "colorMode": "row",
          "colors": [
            "#C4162A",
            "#37872D",
            "#FA6400",
            "#434143",
            "#1F60C4",
            "#8F3BB8",
            "#AA8800"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "TaskStateCode",
          "thresholds": [
            "0.5",
            "1.5",
            "2.5",
            "3.5",
            "4.5",
            "5.5"
          ],
          "type": "string",
          "unit": "short",
          "valueMaps": [
            {
              "text": "Failed",
              "value": "0"
            },
            {
              "text": "Succeeded",
              "value": "1"
            },
            {
              "text": "Cancelled",
              "value": "2"
            },
            {
              "text": "Queued",
              "value": "3"
            },
            {
              "text": "Executing",
              "value": "4"
            },
            {
              "text": "Timed Out",
              "value": "5"
            },
            {
              "text": "Cancelling",
              "value": "6"
            }
          ]
        },
        {
          "alias": "Start Time 🏁",
          "align": "",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "StartTime",
          "thresholds": [],
          "type": "date",
          "unit": "dateTimeFromNow"
        },
        {
          "alias": "Completed Time 🏁",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "CompletedTime",
          "thresholds": [],
          "type": "date",
          "unit": "short"
        },
        {
          "alias": "Duration ⏱️",
          "align": "",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Duration",
          "thresholds": [],
          "type": "number",
          "unit": "s"
        },
        {
          "alias": "Deployed By 👩‍💻",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "DeployedBy",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": " ",
          "align": "",
          "colorMode": "cell",
          "colors": [
            "#2f2f32",
            "#2f2f32",
            "#2f2f32"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Icon",
          "preserveFormat": false,
          "sanitize": false,
          "thresholds": [
            "0"
          ],
          "type": "string",
          "unit": "short",
          "valueMaps": [
            {
              "text": "⛔",
              "value": "0"
            },
            {
              "text": "✔️",
              "value": "1"
            },
            {
              "text": "⚠️",
              "value": "2"
            },
            {
              "text": "🕒",
              "value": "3"
            },
            {
              "text": "⚡",
              "value": "4"
            },
            {
              "text": "☄️",
              "value": "5"
            },
            {
              "text": "🚫",
              "value": "6"
            }
          ]
        },
        {
          "alias": "Environment 🌐",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Environment",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "Version #️⃣",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Version",
          "thresholds": [],
          "type": "number",
          "unit": "short"
        }
      ],
      "targets": [
        {
          "alias": "",
          "format": "table",
          "hide": false,
          "rawSql": "SELECT top 100\n    CASE\n    WHEN d.TaskState = 'Failed' THEN 0\n    WHEN d.TaskState = 'Success' THEN 1\n    WHEN d.TaskState = 'Canceled' THEN 2\n    WHEN d.TaskState = 'Queued' THEN 3\n    WHEN d.TaskState = 'Executing' THEN 4\n    WHEN d.TaskState = 'TimedOut' THEN 5\n    WHEN d.TaskState = 'Cancelling' THEN 6\n  END as Icon,\n  d.EnvironmentName as Environment,\n  d.ProjectName as ProjectName,\n  d.ReleaseVersion,\n  d.QueueTime AS StartTime,\n  d.CompletedTime,\n  DATEDIFF(ss, d.QueueTime, d.CompletedTime) AS Duration,\n  CASE\n    WHEN d.TaskState = 'Failed' THEN 0\n    WHEN d.TaskState = 'Success' THEN 1\n    WHEN d.TaskState = 'Canceled' THEN 2\n    WHEN d.TaskState = 'Queued' THEN 3\n    WHEN d.TaskState = 'Executing' THEN 4\n    WHEN d.TaskState = 'TimedOut' THEN 5\n    WHEN d.TaskState = 'Cancelling' THEN 6\n  END as TaskStateCode,\n  d.DeployedBy\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  CASE    WHEN CONVERT( DATETIMEOFFSET, $__timeTo(), 0 )  BETWEEN  DATEADD(DAY,-1,GETDATE()) AND GETDATE()\n          THEN  isnull(d.CompletedTime,CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ))  \n          ELSE\n            d.CompletedTime\n  END   <= CONVERT( DATETIMEOFFSET, $__timeTo(), 0 )\n  AND--e.completed time will always =e.completed time so else statement will have no constraint\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nORDER BY d.QueueTime DESC",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Deployments",
      "transform": "table",
      "type": "table"
    },
    {
      "columns": [
        {
          "text": "Avg",
          "value": "avg"
        }
      ],
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fontSize": "100%",
      "gridPos": {
        "h": 11,
        "w": 15,
        "x": 0,
        "y": 57
      },
      "id": 19,
      "pageSize": 25,
      "showHeader": true,
      "sort": {
        "col": null,
        "desc": false
      },
      "styles": [
        {
          "alias": "Project 🚧",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "ProjectName",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "State ⭐️",
          "align": "auto",
          "colorMode": "row",
          "colors": [
            "#C4162A",
            "#37872D",
            "#FA6400",
            "#434143",
            "#1F60C4",
            "#8F3BB8",
            "#AA8800"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "TaskStateCode",
          "thresholds": [
            "0.5",
            "1.5",
            "2.5",
            "3.5",
            "4.5",
            "5.5"
          ],
          "type": "string",
          "unit": "short",
          "valueMaps": [
            {
              "text": "Failed",
              "value": "0"
            },
            {
              "text": "Succeeded",
              "value": "1"
            },
            {
              "text": "Cancelled",
              "value": "2"
            },
            {
              "text": "Queued",
              "value": "3"
            },
            {
              "text": "Executing",
              "value": "4"
            },
            {
              "text": "Timed Out",
              "value": "5"
            },
            {
              "text": "Cancelling",
              "value": "6"
            }
          ]
        },
        {
          "alias": "Start Time 🏁",
          "align": "",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "StartTime",
          "thresholds": [],
          "type": "date",
          "unit": "dateTimeFromNow"
        },
        {
          "alias": "Completed Time 🏁",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "CompletedTime",
          "thresholds": [],
          "type": "date",
          "unit": "short"
        },
        {
          "alias": "Duration ⏱️",
          "align": "",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Duration",
          "thresholds": [],
          "type": "number",
          "unit": "s"
        },
        {
          "alias": "Deployed By",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "DeployedBy",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": " ",
          "align": "auto",
          "colorMode": "cell",
          "colors": [
            "#2f2f32",
            "#2f2f32",
            "#2f2f32"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Icon",
          "thresholds": [
            "0"
          ],
          "type": "string",
          "unit": "short",
          "valueMaps": [
            {
              "text": "⛔",
              "value": "0"
            },
            {
              "text": "✔️",
              "value": "1"
            },
            {
              "text": "⚠️",
              "value": "2"
            },
            {
              "text": "🕒",
              "value": "3"
            },
            {
              "text": "⚡",
              "value": "4"
            },
            {
              "text": "☄️",
              "value": "5"
            },
            {
              "text": "🚫",
              "value": "6"
            }
          ]
        },
        {
          "alias": "Environment 🌐",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Environment",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "Version #️⃣",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Version",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        }
      ],
      "targets": [
        {
          "alias": "",
          "format": "table",
          "hide": false,
          "rawSql": "SELECT TOP 10\n    CASE\n    WHEN d.TaskState = 'Failed' THEN 0\n    WHEN d.TaskState = 'Success' THEN 1\n    WHEN d.TaskState = 'Canceled' THEN 2\n    WHEN d.TaskState = 'Queued' THEN 3\n    WHEN d.TaskState = 'Executing' THEN 4\n    WHEN d.TaskState = 'TimedOut' THEN 5\n    WHEN d.TaskState = 'Cancelling' THEN 6\n  END as Icon,\n  d.EnvironmentName as Environment,\n  d.ProjectName as ProjectName,\n  d.ReleaseVersion,\n  DATEDIFF(ss, d.QueueTime, d.CompletedTime) AS Duration,\n  CASE\n    WHEN d.TaskState = 'Failed' THEN 0\n    WHEN d.TaskState = 'Success' THEN 1\n    WHEN d.TaskState = 'Canceled' THEN 2\n    WHEN d.TaskState = 'Queued' THEN 3\n    WHEN d.TaskState = 'Executing' THEN 4\n    WHEN d.TaskState = 'TimedOut' THEN 5\n    WHEN d.TaskState = 'Cancelling' THEN 6\n  END as TaskStateCode\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  CASE    WHEN CONVERT( DATETIMEOFFSET, $__timeTo(), 0 )  BETWEEN  DATEADD(DAY,-1,GETDATE()) AND GETDATE()\n          THEN  isnull(d.CompletedTime,CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ))  \n  ELSE\n    d.CompletedTime\n  END   <= CONVERT( DATETIMEOFFSET, $__timeTo(), 0 )\n  AND--e.completed time will always =e.completed time so else statement will have no constraint\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nORDER BY d.DurationSeconds DESC",
          "refId": "B"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Deployments with Longest Duration",
      "transform": "table",
      "transparent": true,
      "type": "table"
    },
    {
      "columns": [],
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fontSize": "100%",
      "gridPos": {
        "h": 11,
        "w": 9,
        "x": 15,
        "y": 57
      },
      "id": 31,
      "pageSize": 25,
      "showHeader": true,
      "sort": {
        "col": null,
        "desc": false
      },
      "styles": [
        {
          "alias": "Project 🚧",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "ProjectName",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "Total Failures ⛔",
          "align": "",
          "colorMode": "row",
          "colors": [
            "rgb(194, 156, 3)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(245, 54, 54, 0.9)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 0,
          "mappingType": 1,
          "pattern": "Total",
          "thresholds": [
            "2",
            "5"
          ],
          "type": "number",
          "unit": "short"
        },
        {
          "alias": "Environment 🌐",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Environment",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        }
      ],
      "targets": [
        {
          "alias": "",
          "format": "table",
          "hide": false,
          "rawSql": "SELECT TOP 10\n  d.ProjectName AS ProjectName,\n  d.EnvironmentName AS Environment,\n  COUNT(d.ProjectName) AS Total\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  d.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project) AND\n  d.TaskState = 'Failed'\nGROUP BY d.ProjectName, d.EnvironmentName\nORDER BY count(1) DESC",
          "refId": "B"
        },
        {
          "alias": "",
          "format": "table",
          "hide": true,
          "rawSql": "SELECT \n  COUNT(d.ReleaseId) AS Deployment,\n  s.State AS metric,\n  -- $__timeGroup(s.CompletedTime, '$interval', 0 ) AS [time]\n  $__timeGroup(s.CompletedTime, '1d', 0 ) AS [time]\nFROM \n  [Octopus].[dbo].[Deployment] d\n  INNER JOIN [Octopus].[dbo].[DeploymentEnvironment] e ON e.Id = d.EnvironmentId\n  INNER JOIN [Octopus].[dbo].[Project] p ON p.Id = d.ProjectId\n  INNER JOIN [Octopus].[dbo].[Release] r ON r.Id = d.ReleaseId\n  INNER JOIN [Octopus].[dbo].[ServerTask] s ON s.Id = d.TaskId\nWHERE \n  s.CompletedTime >=  CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  s.CompletedTime <   CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ) AND\n  e.Name IN ($environment) AND\n  p.Name IN ($project)\nGROUP BY  $__timeGroup(s.CompletedTime, '1d', 0), s.State\nORDER BY $__timeGroup(s.CompletedTime, '1d', 0)",
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Failed Project Deployment Count",
      "transform": "table",
      "transparent": true,
      "type": "table"
    },
    {
      "columns": [
        {
          "text": "Avg",
          "value": "avg"
        }
      ],
      "datasource": "${DS_OCTOPUSDEPLOY}",
      "fontSize": "100%",
      "gridPos": {
        "h": 10,
        "w": 24,
        "x": 0,
        "y": 68
      },
      "id": 20,
      "pageSize": 25,
      "showHeader": true,
      "sort": {
        "col": null,
        "desc": false
      },
      "styles": [
        {
          "alias": "State ⭐️",
          "align": "auto",
          "colorMode": "row",
          "colors": [
            "#C4162A",
            "#37872D",
            "#FA6400",
            "#434143",
            "#1F60C4",
            "#8F3BB8",
            "#AA8800"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "TaskStateCode",
          "thresholds": [
            "0.5",
            "1.5",
            "2.5",
            "3.5",
            "4.5",
            "5.5"
          ],
          "type": "string",
          "unit": "short",
          "valueMaps": [
            {
              "text": "Failed",
              "value": "0"
            },
            {
              "text": "Succeeded",
              "value": "1"
            },
            {
              "text": "Cancelled",
              "value": "2"
            },
            {
              "text": "Queued",
              "value": "3"
            },
            {
              "text": "Executing",
              "value": "4"
            },
            {
              "text": "Timed Out",
              "value": "5"
            },
            {
              "text": "Cancelling",
              "value": "6"
            }
          ]
        },
        {
          "alias": "Duration ⏱️",
          "align": "",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "link": false,
          "mappingType": 1,
          "pattern": "Duration",
          "thresholds": [],
          "type": "number",
          "unit": "s"
        },
        {
          "alias": " ",
          "align": "left",
          "colorMode": "cell",
          "colors": [
            "#2f2f32",
            "#2f2f32",
            "#2f2f32"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Icon",
          "thresholds": [
            "0"
          ],
          "type": "string",
          "unit": "short",
          "valueMaps": [
            {
              "text": "⛔",
              "value": "0"
            },
            {
              "text": "✔️",
              "value": "1"
            },
            {
              "text": "⚠️",
              "value": "2"
            },
            {
              "text": "🕒",
              "value": "3"
            },
            {
              "text": "⚡",
              "value": "4"
            },
            {
              "text": "☄️",
              "value": "5"
            },
            {
              "text": "🚫",
              "value": "6"
            }
          ]
        },
        {
          "alias": "Task 🛠️",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "TaskName",
          "preserveFormat": false,
          "sanitize": false,
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "Error ⛔",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "ErrorMessage",
          "preserveFormat": false,
          "sanitize": false,
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "Description 📄",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "Description",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        }
      ],
      "targets": [
        {
          "alias": "",
          "format": "table",
          "hide": false,
          "rawSql": "SELECT TOP 10\n    CASE\n    WHEN d.TaskState = 'Failed' THEN 0\n    WHEN d.TaskState = 'Success' THEN 1\n    WHEN d.TaskState = 'Canceled' THEN 2\n    WHEN d.TaskState = 'Queued' THEN 3\n    WHEN d.TaskState = 'Executing' THEN 4\n    WHEN d.TaskState = 'TimedOut' THEN 5\n    WHEN d.TaskState = 'Cancelling' THEN 6\n  END as Icon,\n  d.DeploymentName as TaskName,\n  d.ProjectName as Project,\n  d.TaskState as Description,\n  DATEDIFF(ss, d.QueueTime, d.CompletedTime) AS Duration,\n  CASE\n    WHEN d.TaskState = 'Failed' THEN 0\n    WHEN d.TaskState = 'Success' THEN 1\n    WHEN d.TaskState = 'Canceled' THEN 2\n    WHEN d.TaskState = 'Queued' THEN 3\n    WHEN d.TaskState = 'Executing' THEN 4\n    WHEN d.TaskState = 'TimedOut' THEN 5\n    WHEN d.TaskState = 'Cancelling' THEN 6\n  END as TaskStateCode\nFROM \n  [Octopus].[dbo].[DeploymentHistory] d\nWHERE\n  d.QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND\n  CASE    WHEN CONVERT( DATETIMEOFFSET, $__timeTo(), 0 )  BETWEEN  DATEADD(DAY,-1,GETDATE()) AND GETDATE()\n          THEN  isnull(d.CompletedTime,CONVERT( DATETIMEOFFSET, $__timeTo(), 0 ))  \n          ELSE\n            d.CompletedTime\n  END   <= CONVERT( DATETIMEOFFSET, $__timeTo(), 0 )\n  AND--e.completed time will always =e.completed time so else statement will have no constraint\n  d.EnvironmentName IN ($environment) AND\n  d.ProjectName IN ($project)\nORDER BY d.DurationSeconds DESC",
          "refId": "B"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Tasks with Longest Duration",
      "transform": "table",
      "type": "table"
    }
  ],
  "refresh": "10s",
  "schemaVersion": 22,
  "style": "dark",
  "tags": [
    "OctopusDeploy"
  ],
  "templating": {
    "list": [
      {
        "allValue": null,
        "datasource": "${DS_OCTOPUSDEPLOY}",
        "definition": "SELECT Distinct(EnvironmentName) FROM [DeploymentHistory] WHERE QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 )",
        "hide": 0,
        "includeAll": true,
        "label": "🌐 Environment",
        "multi": true,
        "name": "environment",
        "options": [],
        "query": "SELECT Distinct(EnvironmentName) FROM [DeploymentHistory] WHERE QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 )",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "current": {
          "selected": true,
          "text": "",
          "value": ""
        },
        "hide": 0,
        "label": "🔎 Project Search",
        "name": "projectsearch",
        "options": [
          {
            "selected": true,
            "text": "",
            "value": ""
          }
        ],
        "query": "",
        "skipUrlSync": false,
        "type": "textbox"
      },
      {
        "allValue": null,
        "datasource": "${DS_OCTOPUSDEPLOY}",
        "definition": "SELECT Distinct(ProjectName) FROM [DeploymentHistory] WHERE EnvironmentName IN ($environment)  AND QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND ProjectName LIKE '%$projectsearch%'",
        "hide": 0,
        "includeAll": true,
        "index": -1,
        "label": "🚧 Project",
        "multi": true,
        "name": "project",
        "options": [],
        "query": "SELECT Distinct(ProjectName) FROM [DeploymentHistory] WHERE EnvironmentName IN ($environment)  AND QueueTime >= CONVERT( DATETIMEOFFSET, $__timeFrom(), 0 ) AND ProjectName LIKE '%$projectsearch%'",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      },
      {
        "auto": true,
        "auto_count": 30,
        "auto_min": "15m",
        "current": {
          "selected": false,
          "text": "auto",
          "value": "$__auto_interval_interval"
        },
        "hide": 0,
        "label": "⏳ Time Grain",
        "name": "interval",
        "options": [
          {
            "selected": true,
            "text": "auto",
            "value": "$__auto_interval_interval"
          },
          {
            "selected": false,
            "text": "1m",
            "value": "1m"
          },
          {
            "selected": false,
            "text": "10m",
            "value": "10m"
          },
          {
            "selected": false,
            "text": "15m",
            "value": "15m"
          },
          {
            "selected": false,
            "text": "30m",
            "value": "30m"
          },
          {
            "selected": false,
            "text": "1h",
            "value": "1h"
          },
          {
            "selected": false,
            "text": "6h",
            "value": "6h"
          },
          {
            "selected": false,
            "text": "12h",
            "value": "12h"
          },
          {
            "selected": false,
            "text": "1d",
            "value": "1d"
          },
          {
            "selected": false,
            "text": "7d",
            "value": "7d"
          },
          {
            "selected": false,
            "text": "14d",
            "value": "14d"
          },
          {
            "selected": false,
            "text": "30d",
            "value": "30d"
          }
        ],
        "query": "1m,10m,15m,30m,1h,6h,12h,1d,7d,14d,30d",
        "refresh": 2,
        "skipUrlSync": false,
        "type": "interval"
      }
    ]
  },
  "time": {
    "from": "now-30d",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ]
  },
  "timezone": "",
  "title": "Octopus Deploy DeploymentHistory",
  "uid": "3hW54K8Wz",
  "version": 2
}