#!/usr/bin/env bash set -e if [ "$1" == "--help" ] || [ -z "$1" ]; then cat <&2 SELECT data from 'system.async_loader' table and render .svg graph of load jobs using 'dot' graphviz tool. USAGE: async_loader_graph CLICKHOUSE_CLIENT CLIENT_OPTIONS EXAMPLES: $ async_loader_graph clickhouse-client > async_loader.svg EOF exit 1 fi CLICKHOUSE_CLIENT="$@" ( echo 'digraph {' echo 'rankdir=LR;' $CLICKHOUSE_CLIENT --query='select job, status, is_blocked, is_ready, is_executing, pool, dependencies from system.async_loader FORMAT JSON' \ | jq -r ' def nodeId: gsub(" "; "_") | gsub("\\."; "__"); .data[] | { "FgLoad": "box", "BgLoad": "hexagon", "BgStartup": "ellipse" } as $shape | { "PENDING": "white", "OK": "lightgreen", "FAILED": "red", "CANCELED": "darkred" } as $fillcolor | [ "black", "blue", "orange", "yellow" ] as $color | (.job | nodeId) as $self | [ # Nodes $self + " [label=\"" + .job + "\", shape=\"" + $shape[.pool] + "\", style=\"filled\", fillcolor=\"" + $fillcolor[.status] + "\", penwidth=\"3.0\", color=\"" + $color[.is_blocked + .is_ready * 2 + .is_executing * 3] + "\"];", # Edges (.dependencies[] | ($self + " -> " + (. | nodeId) + ";")) ] | join("\n") ' cat < PENDING -> is_assigned [style="invis"] } LEGEND echo '}' # digraph ) | dot -Tsvg