Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ascii graph width for high metric values #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

qezz
Copy link

@qezz qezz commented Apr 9, 2023

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 ┼                                         ╰────╯

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant