#!/bin/bash set -eu USAGE="USAGE: $0 PROM_URL SERVICE DURATION [TIME [LABELS]] > flamegraph.svg Generate a flamegraph for the given service using data from the given prometheus server. Uses DURATION amount of data (in prometheus timespec format, eg '15m'), ending at TIME, which may be unix time or RFC3339, defaults to now. Labels is optional extra prometheus labels to match on, in promql format, eg. 'foo=\"bar\",baz=\"123\"' Note that in the resulting flamegraph, the 'samples' value is actually showing milliseconds of cpu time over the given duration." if [ "$#" -lt 3 ]; then echo "$USAGE" >&2 exit 1 fi PROM=$1 SERVICE=$2 DURATION=$3 TIME=${4:-now} LABELS=${5:-} if [ "$TIME" == "now" ]; then TIME=$(date +%s) fi if [ -n "$LABELS" ]; then LABELS="job=\"$SERVICE\"" else LABELS="job=\"$SERVICE\",$LABELS" fi docker build -t wubloader-flamegraph:latest . -f - 1>&2 < 0' | jq -r '.data.result[]|\"\\(.metric.stack) \\(.value[1])\"' | perl /flamegraph.pl "