promql-cli
promql-cli copied to clipboard
fix: ascii graph width for high metric values
For high metric values the graph always goes to the new line, making it hard to read the values.
This commit adds dynamic calculation of the ascii graph width.
Unfortunately, asciigraph library does some approximations while writing the graph. It means the graph can still go over the specified width. To compensate this, the graph is 0-1 chars "thinner" than it supposed to be.
Below some tests with terminal size 55x88
$ stty size
55 88
Labels are redacted.
- Test 1 - small values
./build/bin/darwin/amd64/promql --start 2h 'delta(test_metric{test_label="test_label_value"}[1h])'
########################################################################################
# TIME_RANGE: Apr 9 15:17:12 -> Apr 9 17:17:12 #
# METRIC: {test_label="test_label_value" ... (yes, labels are redacted) #
########################################################################################
1235 ┤ ╭───────────────
1234 ┤ ╭──╮ ╭─────╯
1233 ┤ ╭╮ ╭───────╮ ╭╯ ╰──╯
1232 ┤ ╭──╯╰────╯ ╰───╯
1232 ┤ ╭╯
1231 ┤ ╭─╯
1230 ┤ ╭╯
1229 ┤ │
1228 ┤ ╭╯
1227 ┤ ╭╯
1227 ┼──╮ ╭───────╮ ╭────╮│
1226 ┤ ╰────╯ ╰─╯ ╰╯
- Test 2 - high values
./build/bin/darwin/amd64/promql --start 2h 'delta(node_filesystem_avail_bytes{ ... }[1h])'
########################################################################################
# TIME_RANGE: Apr 9 15:20:23 -> Apr 9 17:20:23 #
# METRIC: {device="/dev/sda1", fstype="ext4", ... #
########################################################################################
-438873354 ┼╮ ╭╮
-2840534289 ┤│ ╭───╮ ││
-5242195224 ┤│ │ ╰─╮ ││ ╭──
-7643856159 ┤│ │ ╰────╮ ╭╯│ ╭───╯
-10045517093 ┤╰╮ ╭╯ ╰──╮ │ ╰╮ ╭──╯
-12447178028 ┤ │ │ ╰──╮ │ │ ╭──╯
-14848838963 ┤ │ │ ╰──╮ │ │ ╭╯
-17250499897 ┤ ╰╮╭╯ ╰──╮ ╭╯ │ ╭╯
-19652160832 ┤ ││ ╰──╮ │ ╰╮ ╭─╯
-22053821767 ┤ ││ ╰───╮│ │ ╭─╯
-24455482702 ┤ ╰╯ ╰╯ │ ╭──────╯
-26857143636 ┼ ╰────╯