{
  "__inputs": [
    {
      "name": "DS_CLICKHOUSE",
      "label": "ClickHouse",
      "description": "",
      "type": "datasource",
      "pluginId": "grafana-clickhouse-datasource",
      "pluginName": "ClickHouse"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "10.0.0"
    },
    {
      "type": "datasource",
      "id": "grafana-clickhouse-datasource",
      "name": "ClickHouse",
      "version": "4.0.0"
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    },
    {
      "type": "panel",
      "id": "barchart",
      "name": "Bar chart",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "Which stage the delay is in: before the page, between the page and the acknowledgement, or after it. Stage percentiles do not add up to the end-to-end percentile — the intervals combine per episode, and not every episode goes through them in that order.",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "id": null,
  "links": [
    {
      "asDropdown": true,
      "icon": "external link",
      "includeVars": true,
      "keepTime": true,
      "tags": [
        "nxs-anomaly",
        "incident-analytics"
      ],
      "targetBlank": false,
      "title": "Incident analytics",
      "tooltip": "The other dashboards in this set",
      "type": "dashboards",
      "url": ""
    }
  ],
  "refresh": "5m",
  "schemaVersion": 39,
  "style": "dark",
  "tags": [
    "nxs-anomaly",
    "analytics",
    "clickhouse",
    "incident-analytics"
  ],
  "templating": {
    "list": [
      {
        "current": {},
        "hide": 0,
        "includeAll": false,
        "label": "Data source",
        "multi": false,
        "name": "DS_CLICKHOUSE",
        "options": [],
        "query": "grafana-clickhouse-datasource",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      },
      {
        "current": {
          "text": "nxs_anomaly",
          "value": "nxs_anomaly"
        },
        "hide": 0,
        "label": "Database",
        "name": "db",
        "query": "nxs_anomaly",
        "skipUrlSync": false,
        "type": "constant",
        "description": "The analytics database — clickhouse.auth.database in the chart."
      },
      {
        "current": {
          "text": "All",
          "value": "All"
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${DS_CLICKHOUSE}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "Team",
        "multi": false,
        "name": "team",
        "options": [],
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query",
        "query": {
          "refId": "team",
          "rawSql": "SELECT 'All' AS team UNION ALL SELECT DISTINCT team_id FROM $db.nxs_episode_fact WHERE team_id != ''",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        },
        "description": "Team scoping is off by default in the service, and events from before it was turned on carry no team. Those episodes sit under the empty team, not under All."
      },
      {
        "current": {
          "text": "All",
          "value": "All"
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${DS_CLICKHOUSE}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "Service",
        "multi": false,
        "name": "service",
        "options": [],
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query",
        "query": {
          "refId": "service",
          "rawSql": "SELECT 'All' AS service UNION ALL SELECT DISTINCT service FROM $db.nxs_episode_fact WHERE service != ''",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        },
        "description": "Taken from the `service` label of the group's first firing alert. Groups whose alerts carried no such label are under 'unknown' — they are not spread across the real services."
      },
      {
        "current": {
          "text": "All",
          "value": "All"
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${DS_CLICKHOUSE}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "Severity",
        "multi": false,
        "name": "severity",
        "options": [],
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query",
        "query": {
          "refId": "severity",
          "rawSql": "SELECT 'All' AS severity UNION ALL SELECT DISTINCT severity FROM $db.nxs_episode_fact WHERE severity != ''",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        },
        "description": "The severity of the opening event, falling back to the first firing alert. severity_origin on the episode says which was used."
      }
    ]
  },
  "time": {
    "from": "now-30d",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "utc",
  "title": "02 · Response latency and objectives",
  "uid": "nxs-anomaly-02-response-latency",
  "version": 1,
  "weekStart": "",
  "panels": [
    {
      "id": 1,
      "type": "row",
      "title": "Stages of one response",
      "collapsed": false,
      "panels": [],
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      }
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Source → open (p95)",
      "description": "The lag between the time the source says the problem started and the group opening. Only over episodes whose source reported a start time; it is not a detection time for the incident, because the source's start is not when users were affected.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 0,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "s"
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT round(quantile(0.95)(detection_seconds)) AS p95, count(detection_seconds) AS n FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Open → first page (p95)",
      "description": "Until the first delivered page. Resolution notices, shift handovers, test messages and log-channel lines are excluded — counting them is how this number improves for reasons nobody was woken by.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 6,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "s"
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT round(quantile(0.95)(time_to_page_seconds)) AS p95, count(time_to_page_seconds) AS n FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Page → ACK (p95)",
      "description": "Only over episodes that went open → page → acknowledgement in that order. It does not prove the message was read.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 12,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "s"
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT round(quantile(0.95)(page_to_ack_seconds)) AS p95, count(page_to_ack_seconds) AS n FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 5,
      "type": "stat",
      "title": "ACK → close (p95)",
      "description": "The interval after the acknowledgement. Not the time an engineer spent working: nothing in this data observes that.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 18,
        "y": 1
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "s"
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto",
        "colorMode": "value",
        "graphMode": "none"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT round(quantile(0.95)(ack_to_close_seconds)) AS p95, count(ack_to_close_seconds) AS n FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity)",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 6,
      "type": "timeseries",
      "title": "Every stage, by day",
      "description": "The four stages side by side. Do not add their p95s together: the intervals combine per episode, and an episode that was never paged contributes to some of these lines and not to others.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 5
      },
      "fieldConfig": {
        "defaults": {
          "custom": {},
          "unit": "s"
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "multi"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT toDateTime(toDate(opened_at)) AS time, quantile(0.95)(detection_seconds) AS \"source → open p95\", quantile(0.95)(time_to_page_seconds) AS \"open → page p95\", quantile(0.95)(page_to_ack_seconds) AS \"page → ACK p95\", quantile(0.95)(ack_to_close_seconds) AS \"ACK → close p95\" FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) GROUP BY time ORDER BY time",
          "format": 0,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 7,
      "type": "table",
      "title": "Objective outcome, per day and team",
      "description": "The full breakdown behind the attainment share: matured, on time, late, still pending, and the episodes with no objective at all. 'closed by source' is shown apart from late — whether an episode the source closed before anybody answered counts against a team is a policy decision to make before reading the number.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 9,
        "w": 24,
        "x": 0,
        "y": 13
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT day, team_id, service, severity, ack_target_seconds AS ack_target_s, ack_eligible, ack_matured, ack_on_time, ack_late, ack_pending, ack_closed_by_source, close_matured, close_on_time, close_late, defective_intervals, without_objective FROM $db.nxs_response_attainment WHERE $__dateFilter(day) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) ORDER BY day DESC, ack_late DESC LIMIT 200",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 8,
      "type": "table",
      "title": "The slowest episodes to be acknowledged",
      "description": "The cases behind the tail. A percentile is a starting point; these rows are what a review actually reads.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 22
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT alert_group_id, episode_id, alertname, service, severity, opened_at, round(time_to_page_seconds) AS page_s, round(mtta_seconds) AS ack_s, round(mttr_seconds) AS close_s, max_escalation_step AS steps, outcome FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) AND mtta_seconds IS NOT NULL ORDER BY mtta_seconds DESC LIMIT 25",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    },
    {
      "id": 9,
      "type": "table",
      "title": "Who and what closed the episode",
      "description": "Acknowledgement and closure by actor kind. An automated client and a person both appear as an acknowledgement in the envelope; only the kind distinguishes them, and there is no actor id at all.",
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${DS_CLICKHOUSE}"
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 22
      },
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "options": {},
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${DS_CLICKHOUSE}"
          },
          "rawSql": "SELECT acknowledged_by_kind AS ack_actor_kind, acknowledged_by_role AS ack_actor_role, resolution, resolved_by_kind AS close_actor_kind, count() AS episodes, round(quantile(0.95)(mtta_seconds)) AS p95_ack_s FROM $db.nxs_episode_fact WHERE $__timeFilter(opened_at) AND ($team = 'All' OR team_id = $team) AND ($service = 'All' OR service = $service) AND ($severity = 'All' OR severity = $severity) GROUP BY ack_actor_kind, ack_actor_role, resolution, close_actor_kind ORDER BY episodes DESC LIMIT 25",
          "format": 1,
          "queryType": "sql",
          "editorType": "sql"
        }
      ]
    }
  ]
}
