TheAnotherWise

Kibana / Custom Visualization via Vega - Heatmap

Dec 9th, 2025 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 2.08 KB | None | 0 0
  1. {
  2.   "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  3.   "title": "Heatmap: Avg duration per method and status_code",
  4.   "data": {
  5.     "url": {
  6.       "%context%": true,
  7.       "%timefield%": "@timestamp",
  8.       "index": "logs-*",
  9.       "body": {
  10.         "size": 0,
  11.         "aggs": {
  12.           "combo": {
  13.             "composite": {
  14.               "size": 2000,
  15.               "sources": [
  16.                 { "method": { "terms": { "field": "method" } } },
  17.                 { "status": { "terms": { "field": "status_code" } } }
  18.               ]
  19.             },
  20.             "aggs": {
  21.               "avg_duration": { "avg": { "field": "duration_ms" } },
  22.               "p95": { "percentiles": { "field": "duration_ms", "percents": [95] } }
  23.             }
  24.           }
  25.         }
  26.       }
  27.     },
  28.     "format": { "property": "aggregations.combo.buckets" }
  29.   },
  30.  
  31.   "transform": [
  32.     { "calculate": "datum.key.method", "as": "method" },
  33.     { "calculate": "toNumber(datum.key.status)", "as": "status" },
  34.     { "calculate": "datum.avg_duration.value", "as": "duration" },
  35.     { "calculate": "datum['p95']['values']['95.0']", "as": "p95" },
  36.     { "filter": "isValid(datum.duration)" }
  37.   ],
  38.  
  39.   "mark": {
  40.     "type": "rect",
  41.     "stroke": "#ffffff",
  42.     "strokeWidth": 0.8
  43.   },
  44.  
  45.   "encoding": {
  46.     "x": {
  47.       "field": "method",
  48.       "type": "nominal",
  49.       "title": "Method",
  50.       "sort": ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
  51.     },
  52.  
  53.     "y": {
  54.       "field": "status",
  55.       "type": "ordinal",
  56.       "title": "Status code",
  57.       "sort": "ascending"
  58.     },
  59.  
  60.     "color": {
  61.       "field": "duration",
  62.       "type": "quantitative",
  63.       "title": "Avg duration (ms)",
  64.       "scale": {
  65.         "type": "sqrt",
  66.         "scheme": "redyellowgreen",
  67.         "reverse": true
  68.       }
  69.     },
  70.  
  71.     "tooltip": [
  72.       { "field": "method", "title": "Method" },
  73.       { "field": "status", "title": "Status code" },
  74.       { "field": "duration", "title": "Avg", "format": ".2f" },
  75.       { "field": "p95", "title": "p95 (ms)", "format": ".2f" }
  76.     ]
  77.   }
  78. }
  79.  
Advertisement