Giter VIP home page Giter VIP logo

ttyplot's Introduction

ttyplot

a realtime plotting utility for text mode consoles and terminals with data input from stdin / pipe

takes data from standard input / unix pipeline, most commonly some tool like ping, snmpget, netstat, ip link, ifconfig, sar, vmstat, etc. and plots in text mode on a terminal in real time, for example a simple ping:

ttyplot ping

   

supports rate calculation for counters and up to two graphs on a single display using reverse video for second line, for example snmpget, ip link, rrdtool, etc:

ttyplot snmp

   

get

Packaging status

ubuntu

snap install ttyplot

debian

apt install ttyplot

alternatively download | tracker

gentoo

emerge -av app-admin/ttyplot

macOS

brew install ttyplot

termux

pkg install ttyplot

FreeBSD

pkg install ttyplot

misc

for other platforms see releases tab, also older versions

examples

cpu usage from vmstat using awk to pick the right column

fflush() is needed to disable stdio buffering

vmstat -n 1 | gawk '{ print 100-int($(NF-2)); fflush(); }' | ttyplot -s 100 -t "CPU Usage" -u "%"

memory usage on Linux using free, grep, tr and cut

stdbuf is used to disable stdio buffering throughout the pipeline

free -m -s 1 | stdbuf -o0 grep "^Mem:" | stdbuf -o0 tr -s " " | stdbuf -o0 cut -d" " -f3 | ttyplot -t "MEM Usage" -u "MB"

memory usage on macOS

vm_stat 1 | awk '{ print int($2)*4096/1024^3; fflush(); }' | ttyplot -t "MacOS Memory Usage" -u GB

number of processes in running and io blocked state

vmstat -n 1 | perl -lane 'BEGIN{$|=1} print "@F[0,1]"' | ttyplot -2 -t "procs in R and D state"

load average via uptime and awk

{ while true; do uptime | gawk '{ gsub(/,/, ""); print $(NF-2) }'; sleep 1; done } | ttyplot -t "load average" -s load

ping plot with sed

on macOS change -u to -l

ping 8.8.8.8 | sed -u 's/^.*time=//g; s/ ms//g' | ttyplot -t "ping to 8.8.8.8" -u ms

wifi signal level in -dBM (higher is worse) using iwconfig

{ while true; do iwconfig 2>/dev/null | grep "Signal level" | sed -u 's/^.*Signal level=-//g; s/dBm//g'; sleep 1; done } | ttyplot -t "wifi signal" -u "-dBm" -s 90

wifi signal on macOS

{ while true; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --getinfo | awk '/agrCtlRSSI/ {print -$2; fflush();}'; sleep 1; done } | ttyplot -t "wifi signal" -u "-dBm" -s 90

cpu temperature from proc

{ while true; do awk '{ printf("%.1f\n", $1/1000) }' /sys/class/thermal/thermal_zone0/temp; sleep 1; done } | ttyplot -t "cpu temp" -u C

fan speed from lm-sensors using grep, tr and cut

{ while true; do sensors | grep fan1: | tr -s " " | cut -d" " -f2; sleep 1; done } | ttyplot -t "fan speed" -u RPM

memory usage from rrdtool and collectd using awk

{ while true; do rrdtool lastupdate /var/lib/collectd/rrd/$(hostname)/memory/memory-used.rrd | awk 'END { print ($NF)/1024/1024 }'; sleep 1; done } | ttyplot -m $(awk '/MemTotal/ { print ($2)/1024 }' /proc/meminfo) -t "Memoru Used" -u MB

bitcoin price chart using curl and jq

{ while true; do curl -sL https://api.coindesk.com/v1/bpi/currentprice.json  | jq .bpi.USD.rate_float; sleep 600; done } | ttyplot -t "bitcoin price" -u usd

stock quote chart

{ while true; do curl -sL https://api.iextrading.com/1.0/stock/googl/price; echo; sleep 600; done } | ttyplot -t "google stock price" -u usd

prometheus load average via node_exporter

{ while true; do curl -s  http://10.4.7.180:9100/metrics | grep "^node_load1 " | cut -d" " -f2; sleep 1; done } | ttyplot

   

network/disk throughput examples

ttyplot supports "two line" plot for in/out or read/write

snmp network throughput for an interface using snmpdelta

snmpdelta -v 2c -c public -Cp 10 10.23.73.254 1.3.6.1.2.1.2.2.1.{10,16}.9 | gawk '{ print $NF/1000/1000/10; fflush(); }' | ttyplot -2 -t "interface 9 throughput" -u Mb/s

network throughput for an interface using netstat (OpenBSD, FreeBSD)

netstat -b -w ${1} -I em0 | awk 'NR>3 { print $1/1024; print $2/1024; fflush }' | ttyplot -2 -t "IN/OUT Bandwidth in KB/s (${1}s resolution)" -u "KB/s" -c "#"

local network throughput for all interfaces combined from sar

sar  -n DEV 1 | gawk '{ if($6 ~ /rxkB/) { print iin/1000; print out/1000; iin=0; out=0; fflush(); } iin=iin+$6; out=out+$7; }' | ttyplot -2 -u "MB/s"

disk throughput from iostat

iostat -xmy 1 nvme0n1 | stdbuf -o0 tr -s " " | stdbuf -o0 cut -d " " -f 4,5 | ttyplot -2 -t "nvme0n1 throughput" -u MB/s

   

rate calculator for counters

ttyplot also supports counter style metrics, calculating rate by measured time difference between samples

snmp network throughput for an interface using snmpget

{ while true; do snmpget -v 2c -c public 10.23.73.254 1.3.6.1.2.1.2.2.1.{10,16}.9 | awk '{ print $NF/1000/1000; }'; sleep 10; done } | ttyplot -2 -r -u "MB/s"

local interface throughput using ip link and jq

{ while true; do ip -s -j link show enp0s31f6 | jq .[].stats64.rx.bytes/1024/1024,.[].stats64.tx.bytes/1024/1024; sleep 1; done } | ttyplot -r -2 -u "MB/s"

prometheus node exporter disk throughput for /dev/sda

{ while true; do curl -s http://10.11.0.173:9100/metrics | awk '/^node_disk_.+_bytes_total{device="sda"}/ { printf("%f\n", $2/1024/1024); }'; sleep 1; done } | ttyplot -r -2 -u MB/s -t "10.11.0.173 sda writes"

network throughput from collectd with rrdtool and awk

{ while true; do rrdtool lastupdate /var/lib/collectd/rrd/$(hostname)/interface-enp1s0/if_octets.rrd | awk 'END { print ($2)/1000/1000, ($3)/1000/1000 }'; sleep 10; done } | ttyplot -2 -r -t "enp1s0 throughput" -u MB/s

   

flags

  ttyplot [-2] [-r] [-c plotchar] [-s scale] [-m max] [-M min] [-t title] [-u unit]
  ttyplot -h
  ttyplot -v

  -2 read two values and draw two plots, the second one is in reverse video
  -r rate of a counter (divide value by measured sample interval)
  -c character to use for plot line, eg @ # % . etc
  -e character to use for error line when value exceeds hardmax (default: e)
  -E character to use for error symbol displayed when value is less than hardmin (default: v)
  -s initial scale of the plot (can go above if data input has larger value)
  -m maximum value, if exceeded draws error line (see -e), upper-limit of plot scale is fixed
  -M minimum value, if entered less than this, draws error symbol (see -E), lower-limit of the plot scale is fixed
  -t title of the plot
  -u unit displayed beside vertical bar
  -v print the current version and exit
  -h print this help message and exit

   

key bindings

when reading data from a pipe, ttyplot accepts the following commands typed at the terminal:

  q  quit
  r  toggle rate mode

these commands do not work if the standard input is a terminal: in this case quit with Ctrl-C.

   

frequently questioned answers

ttyplot quits when there is no more data

UPDATE as of version 1.5 ttyplot will print "input stream closed" and wait forever, instead of quititing.

this is by design; your problem is likely that the output is lost (terminal erased) when ttyplot exits; this is explained in the next question below

you can also simply work around it, by adding sleep, read, cat at the end of the stream:

{ echo 1 2 3; cat; } | ttyplot

ttyplot erases screen when exiting

this is because of alternate screen in terminals based on xterm; if you use one of these this will likely work around it:

echo 1 2 3 | TERM=vt100 ttyplot

you can also permanently fix terminfo entry (this will make a copy in $HOME/.terminfo/):

infocmp -I $TERM | sed -e 's/smcup=[^,]*,//g' -e 's/rmcup=[^,]*,//g' | tic -

when running interactively and non-numeric data is entered (eg. some key) ttyplot hangs

press ctrl^j to re-set

stdio buffering

by default in unix stdio is buffered, you can work around it in various ways also this

legal stuff

License: Apache 2.0
Copyright (c) 2013-2018 Antoni Sawicki
Copyright (c) 2019-2024 Google LLC
Copyright (c) 2023 Edgar Bonet
Copyright (c) 2023 Sebastian Pipping

ttyplot's People

Contributors

chenrui333 avatar claunia avatar dadav avatar dependabot[bot] avatar edgar-bonet avatar gromgit avatar hartwork avatar hrshbh avatar johnnynator avatar mivanchev avatar pvonmoradi avatar sjmulder avatar tenox7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ttyplot's Issues

floats not working

float input still renders int lines, scales drawn correctly with decimal points

Possibility of Arm64 build?

Seeing if it would be possible for a Arm64 debian package for support of smaller computers such as the RPI.

Running into:

$ sudo dpkg -i ttyplot_1.4-1.deb 
dpkg: error processing archive ttyplot_1.4-1.deb (--install):
 package architecture (amd64) does not match system (arm64)
Errors were encountered while processing:
 ttyplot_1.4-1.deb

Thanks!

Add colors

add option for coloring charts, eg closer to max = more red

also potentially axes, labels, etc to have different colors

default line and reverse line could also have configurable colors

[master] "make deb" is broken

# make deb
mkdir -p ttyplot_1.4-1/usr/local/bin
cp ttyplot ttyplot_1.4-1/usr/local/bin
dpkg-deb --build ttyplot_1.4-1
dpkg-deb: error: failed to open package info file 'ttyplot_1.4-1/DEBIAN/control' for reading: No such file or directory

feature request: set minimum

Option to set vertical axis minimum.

Currently, the minimum on the vertical axis is 0. If the value plotted fluctuates around a high value, a lot of the resolution of the fluctuations is lost due to most of the graph representing the baseline.

This is a proposal to have a command-line parameter to set the minimum of the vertical scale (similar to the maximum value, I suppose)

[master] Fails to compile with error: cannot find -lcurses: No such file or directory

# make
cc -Wall -Wextra    ttyplot.c  -lcurses -ltinfo -o ttyplot
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lcurses: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [<builtin>: ttyplot] Error 1

# pkg-config --libs ncurses
-lncurses -ltinfo
  ^

Pull request upcoming...

Support for libncurses6

ttyplot needs libncurses5 and libtinfo5 to be installed. I am running Lubuntu 19.04, which already uses libncurses6 and libtinfo6, so ttyplotthrows errors:

ttyplot: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

After trying to fix by running
sudo ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6 /usr/lib/x86_64-linux-gnu/libncurses.so.5
sudo ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6 /usr/lib/x86_64-linux-gnu/libtinfo.so.5,

ttyplot is still not happy:

ttyplot: /lib/x86_64-linux-gnu/libtinfo.so.5: version NCURSES_TINFO_5.0.19991023' not found (required by ttyplot) ttyplot: /lib/x86_64-linux-gnu/libncurses.so.5: version NCURSES_5.0.19991023' not found (required by ttyplot)

Could the binary ttyplot version for linux (ttyplot-amd64-linux) please support the ncurses6 libraries as well? It should be enough to just compile it on a ncurses/tinfo6 system.

It was easy to compile ttyplot after installation of libncurses-dev and libtinfo-dev, but since you supply all these binaries, it would be very comfortable to have out-of-the-box support as well.

Program immediately quits

On macOS 12.5.1, plotting from stdin does not work:

 echo "1 2 3 4 5" | ttyplot

immediately exits. With longer input, one can see the plot flashing by, before the program quits and nothing is left.

Ping example on mac

The ping example does not seem to work on mac terminal. Is it something related to buffered output ? also sed on mac does not have the option of -u .

Thanks in advance..

question

hi, deb packages are not longer hosted here?

Regards,

-e arg isn't working in Homebrew version (but works fine when compiled from source)

Hey, first: amazing work on this tool! I'm using it to visualize memory pressure over time on my Mac.

v1.4 from Homebrew seems to have a problem with the -e option -- e.g. this will fail (just prints the helptext and then pauses for 1 second, then exits):

while [0]; do memory_pressure | awk 'END {print $5/1}'; sleep 1; done | ttyplot -e+ -cx -m100 -t%free_mem -u%

but, cloning master and compiling with make outputs a version where the exact same command works fine (also says 1.4 but obviously something's different).

macOS 10.15.5

Any idea?

Coinbase API Example is deprecated ...

Hi and thanks for this useful tool!

I noticed the the following example is not working anymore
{ while true; do curl -sL https://coinbase.com/api/v1/prices/historical | head -1 | cut -d, -f2 ; sleep 600; done } | ttyplot -t "bitcoin price" -u usd

I had a quick glance over the current API (https://developers.coinbase.com/api/v2) and it seems there are no "historical" prices anymore (actually, i could not find "historical" within the old api (https://developers.coinbase.com/api/v1).

Greetings,

Chris

Feature request: work with limited data

All uses cases where I would like to use ttyplot are with "limited" input. As it stands, ttyplot quits immediately on stdin EOF.

One simple solution that works is to replace the break statement in the if(r<0) codepath with a sleep(10); continue;.

I can open a PR, if this is desirable.

non gawk examples

give examples with cut, (paste?), perl, python, etc in addition to bash

better SIGWINCH handler

on modern systems resizeterm() should be called in sigwinch handler instead of endwin() && refresh()

on some systems getmaxyx doesn't work correctly, use TIOCGWINSZ instead see how old svr4 vi does it (ex_v.c)

[1.5.1] Minimum window size assumptions can be violated?

Hi!

From a user point of view, resizing ttyplot's window to small sizes and back can get ttyplot into a broken state, e.g. see video below.

From a code point of view, there are multiple places where a certain minimum size is assumed…

  • plotheight=height-4;
  • (width/2)-14
  • (width/2)-(strlen(title)/2)

…but not checked for. So the assumptions can be violated in practice, e.g. during a resize.

python-prompt-toolkit addresses this problem by displaying something like "window too small" whenever that's the case (and the window is big enough for that text still). I think that would be great to have here for robustness, too.

What do you think?

PS: This may or may not be related to #77.

recording-2023-03-14_04.42.01.mp4

option -e and -s/-m

It seems the options does not work properly. please correct me if i am wrong.

  • If the option -e is used there is only the Usage output so the preferred exceed character doesn't work.
  • If the option -m is used the -s option seems to be ignored. The graph limit at start is the given -m input. From my understanding the -s should be the first limit for the graph. If this is exceeded the last limit is the -m limit and the -e character is used to visualise this exception.

The tested version is compiled from today's source. 1.4

PS: despite that a cool piece of software ;)

poor man line drawin

for these old systems have define to compile with poor's man line drawing -|<>^L etc

Release 1.0 has no Makefile

I see the repo has a Makefile, but you may need to update with a new release, like 1.1, to include the Makefile.

License and Makefile

I so love this project and already pointed half a dozen friends to it. (I own a command-line tool for R called littler which can work as a filter; I also pointed John Kerl of mlr fame to it.)

Two things are missing, both pretty trivial:

  • you should a license; I am personally happy with GPL (>= 2), other like MIT/BSD style or Apache but not having anything is actually prohibiting use
  • maybe add a two-line Makefile? I know about -lcurses but then I am also one of those guys

Please add options softmin and hardmin

During real-life use, it turns out that having minimum options would be convenient. Could they be added?

For something exceeding the max and min values, I propose to have a full bar with some marker for max and not drawing anything at all for min, to distinguish them.

Support negative values

This would be great to plot temperature, or other values that typically sometimes go negative.

ttyplot does not read data

So while the examples work, the command output I want to plot doesn't. I have a line such as

find  minicrane-scans/mrs/2020/11/02/ -name "*.pcd" | sort | xargs ./bin/pcl_icp | grep Yaw --line-buffered | cut -d" " -f 2

which runs and continuously outputs to stdout

-0
-0.000116325
-0.000274716
-0.000444506
-0.000536768
-0.000640014
-0.000762741
-0.000762741
-0.000997292
-0.00122629
-0.00153955
-0.00172964
-0.00172996
-0.00172996
-0.00180447
-0.00180986
...

However, piping this to ttyplot only shows waiting for data from stdin .

Plans for a post-1.4 release off Git master?

Hi @tenox7,

thanks for sharing ttyplot as Software Libre! 👍 I noticed that there are 90+ commits on master since release 1.4 and that Debian-based distros have packaged post-1.4 Git snapshots:

XXXX

To my understanding both indicate, that there is lack for a more recent release.
Are there any plans to cut a release 1.5+ off master? I'm considering packaging ttyplot for Gentoo, and that would be a great match.

Thanks and best, Sebastian

static ttyplot-amd64-linux aborts with error "Error opening terminal: xterm-256color."

ttyplot-amd64-linux aborts with "Error opening terminal: xterm-256color."

The system has xterm-256color only at /usr/lib/terminfo/x/xterm-256color (Lubuntu install).

A strings /usr/local/bin/ttyplot | grep terminfo shows that the static binary expects it to be at /etc/terminfo:/lib/terminfo:/usr/share/terminfo or ~/.terminfo.

Workaround is to copy it to one of these locations.

Proposed fix: Please add usr/lib/terminfo to the path where ncurses looks for the terminal definition.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.