TheAnotherWise

Kibana / Custom Visualization via Vega - Pareto

Dec 9th, 2025 (edited)
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.67 KB | None | 0 0
  1. {
  2.   "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  3.   "title": "Pareto: status_code",
  4.   "data": {
  5.     "url": {
  6.       "%context%": true,
  7.       "%timefield%": "@timestamp",
  8.       "index": "logs-*",
  9.       "body": {
  10.         "size": 0,
  11.         "aggs": {
  12.           "codes": {
  13.             "terms": {
  14.               "field": "status_code",
  15.               "size": 50,
  16.               "order": { "_count": "desc" }
  17.             }
  18.           }
  19.         }
  20.       }
  21.     },
  22.     "format": { "property": "aggregations.codes.buckets" }
  23.   },
  24.  
  25.   "transform": [
  26.     { "calculate": "datum.doc_count", "as": "count" },
  27.  
  28.     {
  29.       "window": [
  30.         { "op": "sum", "field": "count", "as": "cumulative" }
  31.       ],
  32.       "sort": [{ "field": "count", "order": "descending" }]
  33.     },
  34.  
  35.     {
  36.       "joinaggregate": [
  37.         { "op": "sum", "field": "count", "as": "total" }
  38.       ]
  39.     },
  40.  
  41.     {
  42.       "calculate": "datum.cumulative / datum.total * 100",
  43.       "as": "cum_percent"
  44.     }
  45.   ],
  46.  
  47.   "encoding": {
  48.     "x": {
  49.       "field": "key",
  50.       "type": "nominal",
  51.       "title": "Status code",
  52.       "sort": null
  53.     }
  54.   },
  55.  
  56.   "layer": [
  57.     {
  58.       "mark": "bar",
  59.       "encoding": {
  60.         "y": {
  61.           "field": "count",
  62.           "type": "quantitative",
  63.           "title": "Count"
  64.         }
  65.       }
  66.     },
  67.  
  68.     {
  69.       "mark": { "type": "line", "color": "red", "point": true },
  70.       "encoding": {
  71.         "y": {
  72.           "field": "cum_percent",
  73.           "type": "quantitative",
  74.           "title": "Cumulative %",
  75.           "axis": { "grid": false }
  76.         }
  77.       }
  78.     }
  79.   ],
  80.  
  81.   "resolve": { "scale": { "y": "independent" } }
  82. }
  83.  
Advertisement