ttyplot

Realtime terminal plotter
git clone git://git.sgregoratto.me/ttyplot
Log | Files | Refs | README | LICENSE

README.md (5516B)


      1 ttyplot
      2 =======
      3 a realtime plotting utility for terminal with data input from stdin
      4 
      5 takes data from standard input / unix pipeline, most commonly some tool like *ping, snmpget, netstat, ifconfig, sar, vmstat*, etc. and plots in text mode on a terminal in real time, for example simple **ping**:
      6 
      7 ![ttyplot ping](ttyplot-ping.png)
      8 
      9  
     10  
     11 
     12 
     13 supports rate calculation for counters and up to two graphs on a single display using reverse video for second line, for example **snmpget** or **ip link**:
     14 
     15 ![ttyplot snmp](ttyplot-snmp.png)
     16 
     17 
     18  
     19  
     20 
     21 download
     22 ========
     23 see [releases tab](https://github.com/tenox7/ttyplot/releases)
     24 
     25 usage examples
     26 ==============
     27 
     28 ### cpu usage from vmstat using awk to pick the right column
     29 ```
     30 vmstat -n 1 | gawk '{ print 100-int($(NF-2)); fflush(); }' | ttyplot
     31 ```
     32 
     33 ### cpu usage from sar with title and fixed scale to 100%
     34 ```
     35 sar 1 | gawk '{ print 100-int($NF); fflush(); }' | ttyplot -s 100 -t "cpu usage" -u "%"
     36 ```
     37 
     38 ### memory usage from sar, using perl to pick the right column
     39 ```
     40 sar -r 1 | perl -lane 'BEGIN{$|=1} print "@F[5]"' | ttyplot -s 100 -t "memory used %" -u "%"
     41 ```
     42 
     43 ### number of processes in running and io blocked state
     44 ```
     45 vmstat -n 1 | perl -lane 'BEGIN{$|=1} print "@F[0,1]"' | ttyplot -2 -t "procs in R and D state"
     46 ```
     47 
     48 ### load average via uptime and awk
     49 ```
     50 { while true; do uptime | gawk '{ gsub(/,/, ""); print $(NF-2) }'; sleep 1; done } | ttyplot -t "load average" -s load
     51 ```
     52 
     53 ### ping plot with sed
     54 ```
     55 ping 8.8.8.8 | sed -u 's/^.*time=//g; s/ ms//g' | ttyplot -t "ping to 8.8.8.8" -u ms
     56 ```
     57 
     58 ### wifi signal level in -dBM (higher is worse) using iwconfig
     59 ```
     60 { 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
     61 ```
     62 
     63 ### cpu temperature from proc
     64 ```
     65 { while true; do awk '{ printf("%.1f\n", $1/1000) }' /sys/class/thermal/thermal_zone0/temp; sleep 1; done } | ttyplot -t "cpu temp" -u C
     66 ```
     67 
     68 ### fan speed from lm-sensors using grep, tr and cut
     69 ```
     70 { while true; do sensors | grep fan1: | tr -s " " | cut -d" " -f2; sleep 1; done } | ttyplot -t "fan speed" -u RPM
     71 ```
     72 
     73 ### bitcoin price chart using curl and jq
     74 ```
     75 { 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
     76 ```
     77 
     78 ### stock quote chart
     79 ```
     80 { 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
     81 ```
     82 
     83 ### prometheus load average via node_exporter
     84 ```
     85 { while true; do curl -s  http://10.4.7.180:9100/metrics | grep "^node_load1 " | cut -d" " -f2; sleep 1; done } | ttyplot
     86 ```
     87 
     88 
     89  
     90  
     91 
     92 
     93 
     94 network/disk throughput examples
     95 ================================
     96 ttyplot supports two line plot for in/out or read/write
     97 
     98 ### snmp network throughput for an interface using snmpdelta
     99 ```
    100 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
    101 ```
    102 
    103 ### local network throughput for all interfaces combined from sar
    104 ```
    105 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"
    106 ```
    107 
    108 ### disk throughput from iostat
    109 ```
    110 iostat -xmy 1 nvme0n1 | stdbuf -o0 tr -s " " | stdbuf -o0 cut -d " " -f 4,5 | ttyplot -2 -t "nvme0n1 throughput" -u MB/s
    111 ```
    112 
    113  
    114  
    115 
    116 
    117 
    118 rate calculator for counters
    119 ============================
    120 ttyplot also supports *counter* style metrics, calculating *rate* by measured time difference between samples
    121 
    122 ### snmp network throughput for an interface using snmpget
    123 ```
    124 { 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"
    125 ```
    126 
    127 ### local interface throughput using ip link and jq
    128 ```
    129 { 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"
    130 ```
    131 
    132 ### prometheus node exporter disk throughput for /dev/sda
    133 ```
    134 { 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"
    135 ```
    136 
    137 
    138  
    139  
    140 
    141 
    142 options
    143 =======
    144 
    145 ```
    146   ttyplot [-2] [-r] [-c plotchar] [-s scale] [-m max] [-t title] [-u unit]
    147 
    148   -2 read two values and draw two plots, the second one is in reverse video
    149   -r rate of a counter (divide value by measured sample interval)
    150   -c character to use for plot line, eg @ # % . etc
    151   -e character to use for plot error line when value exceeds hardmax (default: e)
    152   -s minimum/initial scale of the plot (can go above if data input has larger value)
    153   -m maximum value, if exceeded draws error line (see -e), plot scale is fixed
    154   -t title of the plot
    155   -u unit displayed beside vertical bar
    156 ```
    157 
    158  
    159  
    160 
    161 
    162 
    163 issues
    164 ======
    165 ### stdio buffering
    166 by default in unix stdio is buffered, you can work around it in [various ways](http://www.perkin.org.uk/posts/how-to-fix-stdio-buffering.html) 
    167 
    168 ### ttyplot quits and erases screen when there is no more data
    169 it's by design, you can work around by adding sleep or read, for example:
    170 ```
    171 { echo "1 2 3"; sleep 1000; } | ttyplot
    172 ```
    173 
    174 ### when running interactively and non-numeric data is entered (eg some key) ttyplot hangs
    175 press `ctrl^j` to re-set