TheAnotherWise

Kibana / Custom Visualization via Vega - StreamGraph

Dec 9th, 2025 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.82 KB | None | 0 0
  1. {
  2.   "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  3.  
  4.   "title": "StreamGraph: Traffic Flow by Method",
  5.  
  6.   "view": {
  7.     "continuousWidth": 1000,
  8.     "continuousHeight": 450
  9.   },
  10.  
  11.   "data": {
  12.     "url": {
  13.       "%context%": true,
  14.       "%timefield%": "@timestamp",
  15.       "index": "logs-*",
  16.       "body": {
  17.         "size": 0,
  18.         "aggs": {
  19.           "time": {
  20.             "date_histogram": {
  21.               "field": "@timestamp",
  22.               "fixed_interval": "1m",
  23.               "min_doc_count": 0
  24.             },
  25.             "aggs": {
  26.               "methods": {
  27.                 "terms": {
  28.                   "field": "method",
  29.                   "size": 20
  30.                 }
  31.               }
  32.             }
  33.           }
  34.         }
  35.       }
  36.     },
  37.     "format": { "property": "aggregations.time.buckets" }
  38.   },
  39.  
  40.   "transform": [
  41.     { "flatten": ["methods.buckets"] },
  42.     { "calculate": "datum['methods.buckets'].key", "as": "method" },
  43.     { "calculate": "datum['methods.buckets'].doc_count", "as": "count" },
  44.     { "calculate": "toDate(datum.key_as_string)", "as": "timestamp" },
  45.     { "filter": "isValid(datum.method) && isValid(datum.count)" }
  46.   ],
  47.  
  48.   "mark": {
  49.     "type": "area",
  50.     "interpolate": "monotone"
  51.   },
  52.  
  53.   "encoding": {
  54.     "x": {
  55.       "field": "timestamp",
  56.       "type": "temporal",
  57.       "title": "Time"
  58.     },
  59.     "y": {
  60.       "field": "count",
  61.       "type": "quantitative",
  62.       "stack": "center",
  63.       "title": "Traffic volume"
  64.     },
  65.     "color": {
  66.       "field": "method",
  67.       "type": "nominal",
  68.       "title": "Method",
  69.       "scale": { "scheme": "category20" }
  70.     },
  71.     "tooltip": [
  72.       { "field": "timestamp", "title": "Time" },
  73.       { "field": "method", "title": "Method" },
  74.       { "field": "count", "title": "Count" }
  75.     ]
  76.   }
  77. }
  78.  
Advertisement