Draw a Bounded History Graph with byobu-ugraph
byobu-ugraph turns a stream of numbers into a compact terminal graph you can drop straight into a status line. It reads one numeric reading per line, either from a file or from a command you supply, and this walkthrough uses byobu-ugraph 6.11, installed here as package version 6.11-0ubuntu1.1. Allow about ten minutes: you need a shell and the byobu package, and the examples only write under /tmp with no elevated privileges required.
The route
Jump straight to the step you need, or tick off Done means at the end.
1. Check the installed interface
Start with the binary and its built-in help. This is read-only, and you do not need sudo for it:
$ command -v byobu-ugraph
/usr/bin/byobu-ugraph
$ dpkg-query -W -f='${Package} ${Version}\n' byobu
byobu 6.11-0ubuntu1.1
$ byobu-ugraph -h
Description: Display a graph of historical indicator values using
byobu-ulevel.
- Takes a file or a command. Pass a file with
-f, or a command after the options. - Defaults are narrow. Range 0 to 100, history 5 points, theme
vbars_8. - One value per line. The graph is built from one numeric reading per input line.
Checkpoint
If command -v finds nothing, stop here and install or repair the package through your normal system-management process. Do not use sudo merely because the graph is missing.
2. Create a graph from a short data file
Make a small test file with three readings. It is ordinary text, so you can check it before handing it to byobu:
$ graph_file=/tmp/byobu-ugraph-example.dat
$ printf '%s\n' 1 5 10 > "$graph_file"
$ cat "$graph_file"
1
5
10
Render it with an explicit range so the values stay meaningful: 0 is the bottom of the range, 10 is the top.
$ byobu-ugraph -p 3 -m 0 -x 10 -f "$graph_file"
▁▄█
The exact glyphs depend on your terminal font and theme, but three adjacent characters should appear for three readings. The program writes the graph to standard output; its internal level renderer is byobu-ulevel, so you get a compact sequence, not a chart with axes and labels.
A file with fewer than the requested number of lines will not plot yet. A new file with one or two readings and -p 3 produces blank-width output until enough history exists: that is a normal warm-up state, not evidence the range is wrong.
3. Let the command collect a reading
Put a command after the options and byobu-ugraph appends its output to a data file, then graphs the retained lines. Use a fixed, trusted command string and quote the whole thing so the outer shell does not expand it first:
$ byobu-ugraph -p 2 -m 0 -x 100 "printf '25\n75\n'"
▂▆
No -f was supplied, so the script picks a temporary file under /tmp named from the current user, script name and process ID. Handy for a one-off display, but not a named history you can reliably find again. Use an explicit file when the history matters.
Warning
The command argument is evaluated by the script after it builds the file name. This is a shell-quoting boundary, not a safe parser for untrusted input. Do not insert usernames, filenames or downloaded text into the command string without careful validation and quoting, and keep redirections and substitutions inside a command you have reviewed yourself.
Checkpoint
The command must emit numeric lines only. Test it separately first:
$ printf '25\n75\n'
25
75
If the command prints labels, percentages, warnings or multiple lines per reading, the graph will not represent the values you intended. Adapt it so standard output contains only the numbers byobu-ugraph consumes.
4. Keep the history bounded
By default the script rotates the file on each run and keeps at most -p lines, which is exactly what a status indicator needs: the file never grows without limit. Five readings and a three-point graph show the effect:
$ graph_file=/tmp/byobu-ugraph-example.dat
$ printf '%s\n' 1 5 10 4 8 > "$graph_file"
$ byobu-ugraph -p 3 -m 0 -x 10 -f "$graph_file"
▂▆█
$ wc -l < "$graph_file"
3
Warning
The graph uses the last three readings, and the file is rewritten to keep just those lines. Rotation is a state-changing operation: it replaces the file's contents with the retained tail. Keep a copy first if you need the data for later analysis.
To inspect a file without rotating it, add -r:
$ byobu-ugraph -r -p 3 -m 0 -x 10 -f "$graph_file" > /tmp/byobu-ugraph-display.txt
$ wc -l < "$graph_file"
3
The graph still prints, but the input file is left alone. The option also forbids a command argument, because a command would need to append to the file: try both together and the installed command exits with status 1 and reports cannot write to file if rotate disabled.
5. Choose range, theme and newline behaviour
Use -m and -x when the default 0 to 100 range does not fit the metric. Load averages are a common example, where a maximum of 3 is more useful than 100:
$ awk '{ print $1 }' /proc/loadavg > /tmp/byobu-load.dat
$ byobu-ugraph -p 1 -m 0 -x 3 -f /tmp/byobu-load.dat
▅
The character shown varies with current load. A value above the chosen maximum is not a useful percentage; pick a range that matches the metric, then decide whether an outlier should clip or whether the range needs widening.
-tpicks a theme. The installed default isvbars_8; other names must be supported by the installedbyobu-ulevelrenderer.-ndrops the trailing newline. Useful when embedding the graph in a larger status line; it does not turn off the graph or change the history.
6. Diagnose the common failures
- No file and no command. byobu-ugraph exits with status 1 and says a file must be specified. Add a real file path, or a command that can produce the reading. If the file does not exist, the script can still run, but it has no complete history to display.
- Blank or short graph. Check the line count and the file contents:
$ wc -l /tmp/byobu-load.dat
$ sed -n '1,5p' /tmp/byobu-load.dat
With -p 5, at least five lines are needed before a normal five-point graph appears. Confirm each line is a number and that the command did not emit a diagnostic on standard output.
Do not run the collector as root to paper over a permissions problem. Choose a file in a directory your user can write, such as a controlled path under /tmp or your home directory. Use elevated privileges only when the data source genuinely requires them, and never put sudo inside a command string the script will evaluate.
Recovery
The examples create temporary files. Once you have checked the result, remove those specific files if they are no longer useful; do not use a broad wildcard in a cleanup command. If a file holds readings you want, copy it to a deliberate location first, because the graph command has no undo for a rotation or overwrite.
Done means
- byobu-ugraph is installed and its local defaults are understood.
- Your input produces one numeric reading per line.
- The range passed with
-mand-xmatches the metric. - The history length is deliberately bounded with
-p. - You know whether the invocation rotates the file, and you use
-rwhen the source must stay unchanged. - Any command string is trusted, reviewed and quoted as one shell argument.