ttyplot.1 (6567B)
1 .Dd May 7, 2019 2 .Dt TTYPLOT 1 3 .Os 4 .Sh NAME 5 .Nm ttyplot 6 .Nd realtime terminal plotting utility 7 .Sh SYNOPSIS 8 .Nm 9 .Op Ar options 10 .Sh DESCRIPTION 11 .Nm 12 takes data from standard input, 13 most commonly some tool like 14 .Xr ping 1 , 15 .Xr snmpget 1 , 16 .Xr netstat 8 , 17 .Xr ifconfig 8 , 18 .Xr sar 1 , 19 .Xr vmstat 8 , 20 etc., 21 and plots in text mode on a terminal in real time. 22 .Pp 23 Supports rate calculation for counters and up to two graphs 24 on a single display using reverse video for second line. 25 .Pp 26 The following options are supported: 27 .Bl -tag -width Ds 28 .It Fl 2 29 Read two values and draw two plots, the second in reverse video. 30 .It Fl r 31 Calculate counter rate and divide by measured sample interval. 32 .It Fl c Ar plotchar 33 Use 34 .Ar plotchar 35 for the plot line, e.g. 36 .Ql @ # % \&. 37 etc. 38 .It Fl e Ar errchar 39 Use 40 .Ar errchar 41 for plot error line when value exceeds max. 42 Default: 43 .Ql e . 44 .It Fl s Ar softmax 45 Use 46 .Ar softmax 47 as the initial maximum value but allow it to grow with input. 48 .It Fl m Ar hardmax 49 Use 50 .Ar hardmax 51 as a hard value limit after which an error line will be drawn 52 .Po 53 see 54 .Fl e 55 .Pc . 56 .It Fl t Ar title 57 Use 58 .Ar title 59 as the plot title. 60 .It Fl u Ar unit 61 Label the vertical axis 62 .Ar unit . 63 .El 64 .Sh EXAMPLES 65 CPU usage from 66 .Xr vmstat 8 67 using 68 .Xr awk 1 69 to pick the right column: 70 .Bd -literal -offset indent 71 vmstat -n 1 \\ 72 | gawk '{ print 100-int($(NF-2)); fflush(); }' \\ 73 | ttyplot 74 .Ed 75 .Pp 76 CPU usage from 77 .Xr sar 1 78 with title and fixed scale to 100%: 79 .Bd -literal -offset indent 80 sar 1 \\ 81 | gawk '{ print 100-int($NF); fflush(); }' \\ 82 | ttyplot -s 100 -t "cpu usage" -u "%" 83 .Ed 84 .Pp 85 Memory usage from 86 .Xr sar 1 , 87 using 88 .Xr perl 1 , 89 to pick the right column: 90 .Bd -literal -offset indent 91 sar -r 1 \\ 92 | perl -lane 'BEGIN{$|=1} print "@F[5]"' \\ 93 | ttyplot -s 100 -t "memory used %" -u "%" 94 .Ed 95 .Pp 96 Number of processes in running and io blocked state: 97 .Bd -literal -offset indent 98 vmstat -n 1 \\ 99 | perl -lane 'BEGIN{$|=1} print "@F[0,1]"' \\ 100 | ttyplot -2 -t "procs in R and D state" 101 .Ed 102 .Pp 103 Load average via 104 .Xr uptime 1 and 105 .Xr awk 1 : 106 .Bd -literal -offset indent 107 { while true; do 108 uptime | gawk '{ gsub(/,/, ""); print $(NF-2) }' 109 sleep 1 110 done } | ttyplot -t "load average" -s load 111 .Ed 112 .Pp 113 Ping plot with 114 .Xr sed 1 : 115 .Bd -literal -offset indent 116 ping 8.8.8.8 \\ 117 | sed -u 's/^.*time=//g; s/ ms//g' \\ 118 | ttyplot -t "ping to 8.8.8.8" -u ms 119 .Ed 120 .Pp 121 WiFi signal level in -dBM (higher is worse) using 122 .Xr iwconfig 8 : 123 .Bd -literal -offset indent 124 { while true; do 125 iwconfig 2>/dev/null \\ 126 | grep "Signal level" \\ 127 | sed -u 's/^.*Signal level=-//g; s/dBm//g' 128 sleep 1 129 done } | ttyplot -t "wifi signal" -u "-dBm" -s 90 130 .Ed 131 .Pp 132 CPU temperature from proc; 133 .Bd -literal -offset indent 134 { while true; do 135 awk '{ printf("%.1f\n", $1/1000) }' \\ 136 /sys/class/thermal/thermal_zone0/temp 137 sleep 1 138 done } | ttyplot -t "cpu temp" -u C 139 .Ed 140 .Pp 141 Fan speed from 142 .Xr sensors 1 143 using 144 .Xr grep 1 , 145 .Xr tr 1 146 and 147 .Xr cut 1 : 148 .Bd -literal -offset indent 149 { while true; do 150 sensors | grep fan1: | tr -s " " | cut -d" " -f2 151 sleep 1 152 done } | ttyplot -t "fan speed" -u RPM 153 .Ed 154 .Pp 155 Bitcoin price chart using 156 .Xr curl 1 157 and 158 .Xr jq 1 : 159 .Bd -literal -offset indent 160 { while true; do 161 curl -sL https://api.coindesk.com/v1/bpi/currentprice.json \\ 162 | jq .bpi.USD.rate_float 163 sleep 600 164 done } | ttyplot -t "bitcoin price" -u usd 165 .Ed 166 .Pp 167 Stock quote chart: 168 .Bd -literal -offset indent 169 { while true; do 170 curl -sL https://api.iextrading.com/1.0/stock/googl/price 171 echo 172 sleep 600 173 done } | ttyplot -t "google stock price" -u usd 174 .Ed 175 .Pp 176 Prometheus load average via 177 .Ic node_exporter : 178 .Bd -literal -offset indent 179 { while true; do 180 curl -s http://10.4.7.180:9100/metrics \\ 181 | grep "^node_load1 " \\ 182 | cut -d" " -f2; sleep 1 183 done } | ttyplot 184 .Ed 185 .Ss Network/disk throughput examples 186 .Nm 187 supports two-line plots for in/out or read/write. 188 .Pp 189 Local network throughput for all interfaces combined from 190 .Xr sar 1 : 191 .Bd -literal -offset indent 192 sar -n DEV 1 | gawk '{ 193 if($6 ~ /rxkB/) { 194 print iin/1000; 195 print out/1000; 196 iin=0; 197 out=0; 198 fflush(); 199 } 200 iin=iin+$6; 201 out=out+$7; 202 }' | ttyplot -2 -u "MB/s" 203 .Ed 204 .Pp 205 SNMP network throughput for an interface using 206 .Ql ttg : 207 .Bd -literal -offset indent 208 ttg -i 10 -u Mb 10.23.73.254 public 9 \\ 209 | gawk '{ print $5,$8; fflush(); }' \\ 210 | ttyplot -2 -u Mb/s 211 .Ed 212 .Pp 213 SNMP network throughput for an interface using 214 .Xr snmpdelta 1 : 215 .Bd -literal -offset indent 216 snmpdelta -v 2c -c public -Cp 10 \\ 217 10.23.73.254 1.3.6.1.2.1.2.2.1.{10,16}.9 \\ 218 | gawk '{ print $NF/1000/1000/10; fflush(); }' \\ 219 | ttyplot -2 -t "interface 9 throughput" -u Mb/s 220 .Ed 221 .Pp 222 Disk throughput from 223 .Xr iostat 1 : 224 .Bd -literal -offset indent 225 iostat -xmy 1 nvme0n1 \\ 226 | stdbuf -o0 tr -s " " \\ 227 | stdbuf -o0 cut -d " " -f 4,5 \\ 228 | ttyplot -2 -t "nvme0n1 throughput" -u MB/s 229 .Ed 230 .Ss Rate calculator for counters 231 .Nm 232 also supports counter style metrics, 233 calculating a rate by measuring time difference between samples. 234 .Pp 235 SNMP network throughput for an interface using 236 .Xr snmpget 1 : 237 .Bd -literal -offset indent 238 { while true; do 239 snmpget -v 2c -c public \\ 240 10.23.73.254 1.3.6.1.2.1.2.2.1.{10,16}.9 \\ 241 | awk '{ print $NF/1000/1000; }' 242 sleep 10 243 done } | ttyplot -2 -r -u "MB/s" 244 .Ed 245 .Pp 246 Local interface throughput using 247 .Xr ip 8 248 and 249 .Xr jq 1 : 250 .Bd -literal -offset indent 251 { while true; do 252 ip -s -j link show enp0s31f6 \\ 253 | jq '.[].stats64.rx.bytes/1024/1024, \\ 254 .[].stats64.tx.bytes/1024/1024' 255 sleep 1 256 done } | ttyplot -r -2 -u "MB/s" 257 .Ed 258 .Pp 259 Prometheus node exporter disk throughput for 260 .Pa /dev/sda : 261 .Bd -literal -offset indent 262 { while true; do 263 curl -s http://10.11.0.173:9100/metrics \\ 264 | awk '/^node_disk_.+_bytes_total{device="sda"}/ { 265 printf("%f\n", $2/1024/1024); 266 }' 267 sleep 1 268 done } | ttyplot -r -2 -u MB/s -t "10.11.0.173 sda writes" 269 .Ed 270 .Sh AUTHORS 271 .Nm 272 as written by 273 .An Antoni Sawicki Aq Mt tenox@google.com . 274 .Pp 275 Its readme was converted into this manual page by 276 .An Sijmen J. Mulder Aq Mt ik@sjmulder.nl . 277 .Sh BUGS 278 By default in standard in- and output are is buffered. 279 This can be worked around in various 280 .Lk http://www.perkin.org.uk/posts/how-to-fix-stdio-buffering.html ways . 281 .Pp 282 .Nm 283 quits and erases the screen when there is no more data. 284 This is by design and can be worked around by adding 285 .Xr sleep 1 286 or 287 .Xr read 1 , 288 for example: 289 .Pp 290 .Dl { echo "1 2 3"; sleep 1000; } | ttyplot 291 .Pp 292 When running interactively and non-numeric data is entered 293 .Pq e.g. some key 294 .Nm 295 hangs. 296 Press 297 .Ql Ctrl^J 298 to reset.