CrazyTB's blog

prettyping.sh - A better UI for watching ping responses

, , ,

Do you run ping tool very often? Do you find yourself squeezing your eyes to see if a packet has been lost? Do you want to have a better view of the latency and of the lost packets over time?

Then you need prettyping.sh, a wrapper around the standard ping tool with the objective to make the output prettier, by making it colorful, more compact, and easier to read. How? Look at the following animated GIF (being played at 4× the actual speed) (update: less than 24 hours, and the screenshot is already outdated):



Download it from from my small_scripts repository at bitbucket.org (direct link).

Continue reading to learn more about this tool...

A bit of history

prettyping.sh was originally written in January of 2008, while I was working at Vialink. I noticed that, very often, we were looking at the output of the ping tool to measure the quality of network links, by looking at a combination of packet loss ratio and latency. However, the standard ping output is too verbose, making it hard to have a quick glance at latency. Not just that, but missing/lost packets are not reported at all. Finally, the statistics of the run are only printed at the very end, after ping finishes running. This helpful piece of information should be available all the time.

I observed a common use-case, a common pattern in our daily work, and I noticed that our workflow could have been improved by having better tools. And so I built a better tool. (By the way, this paragraph describes something I do ALL the time.)

Thus prettyping.sh was born. And it received essentially no updates after 2008. But recently I discovered the spark shell script in github, which made me want to implement a similar output in prettyping. So, in the last few days, I've been implementing many features I wanted to implement for a long time, in addition to the spark-like output.

Requirements

  • bash (tested on 4.20, should work on versions as old as 2008)
  • awk (either gawk, nawk or busybox awk; should work on gawk versions as old as 2008)
  • ping (from iputils, or any other version that prints essentially the same output, like Mac OS X ping or oping)

Features

  • Detects missing/lost packets and marks them at the output.
  • Shows live statistics, updated after each response is received.
  • Two sets of statistics are calculated: one for the most recent <N> responses, and another for all responses since the start of the script.
  • Correctly handles "unknown" lines, such as error messages, without messing up the output.
  • Detects repeated messages and avoids printing them repeatedly.
  • Fast startup, very few and lightweight dependencies (usually faster than running a Python script).
  • No installation required, just run the script from anywhere (and make sure you have the 3 dependencies, most Linux distros already have them).
  • Sane defaults, auto-detects terminal width (but does not detect when the terminal is resized), auto-detects if the output is a terminal. Basically, just run the script and don't worry about the options until you need to.
  • Options not recognized by prettyping are passed to the ping tool. As a wrapper, you can use the most common ping parameters in prettyping as well.
  • As a wrapper, it can run as normal user. Root access is NOT required.
  • The output can be redirected to a file (using shell redirection or pipeline). In such mode, prettyping will avoid using cursor-control escape codes.
  • Colorful output (can be disabled by command-line option).
  • Graphical output of the latency using unicode characters (can be disabled by command-line option).
  • Intuitive output.
  • It looks pretty!

Screenshots

Old screenshot from 2008. I've removed the network cable for a few seconds to make me lose some packets.


Old screenshot from 2008. This is a real screenshot. This huge packet loss has actually happened.


I've recorded today this "animated screenshot", or screencast, or video, or animated GIF. It was recorded using import (from ImageMagick) in a shell script loop. The animated GIF was built using convert (from ImageMagick) and later edited using Gimp. Here is the 1× actual speed version:

And here is the faster 4× speed version (the same as in the post intro):


In Linux distros (and Mac OS X)...

So far, no Linux distro has a package for this script. If this script is useful for other people, I'd be very happy to see it available directly from within a distro package manager. wink

(update, a few hours after I posted on reddit) It is already available on Arch Linux: AUR - prettyping-hg (thanks to Hyacinthe Cartiaux <hcartiaux>)

(another update) If you are a Mac OS X user, alanpearce user has added prettyping to brew.

FAQ (added on 2013-10-18)

Q: Does it really need gawk (GNU awk)?
A: In fact, after swordgeek user commented on reddit, I tested, and it works on gawk, nawk and busybox awk. I've updated the requirements above. It should work on any awk that implements fflush().

Q: I don't see the block characters, all I see are weird characters such as "â..".
A: That is not a question. And your terminal does not seem to support UTF-8. Configure your terminal correctly, switch to another terminal, or just use the --nounicode option. Also, do not copy-paste the code from the browser, download it instead.

Q: What if I am using PuTTY?
A: Inside Window → Translation, set the remote character set to UTF-8 (as in this screenshot by battery_go user on reddit).

Q: This offers absolutely nothing over "mtr".
A: Also not a question. Anyway, prettyping and mtr have different purposes and different features. My script is a wrapper to ping, can ping only one server, can be run as a normal user, requires no setup. mtr pings servers in the entire path to the destination, requires root permissions, requires compilation, and the output is a bit less intuitive. Both are great tools, but they are very different. Read also my comment comparing prettyping and mtr on reddit.

Update (2013-10-18)

So I posted this on reddit, and in 8 10 hours it got 270 354 upvotes (and rising!) and 58 83 comments! Great! Woohoo! bigsmile

And also a AUR - prettyping-hg PKGBUILD for Arch Linux, 6 comments in this blog post, and 1 issue at bitbucket. And I've also pushed some commits to the repository, making the animated screenshot in this post already obsolete.

Android Portuguese speech synthesisValidade dos créditos de operadoras de celular

Comments

Unregistered user Friday, October 18, 2013 10:19:00 AM

Anonyme writes: You, sir, deserve a PKGBUILD: https://aur.archlinux.org/packages/prettyping-mercurial/

Unregistered user Friday, October 18, 2013 11:34:36 AM

Anonymous writes: Amazing. Thank you!

Unregistered user Friday, October 18, 2013 1:26:02 PM

Anonymous writes: Finished reading. Curious when this will land in Arch Linux. Was not disappointed. Awesome tool, congrats and thanks for sharing!

Unregistered user Friday, October 18, 2013 1:43:34 PM

Anonymous writes: He wasn't kidding. That is some ugly code. Can't wait to make this an alias to ping :) Why did you need to put it all through gawk though?

Unregistered user Friday, October 18, 2013 2:24:44 PM

Anonimo writes: looks awful with italian charset... ~$ ./prettyping.sh google.it â. 0 â.. 10 â.. 20 â.. 30 â.. 40 â.. 50 â.. 60 â.. 70 â. 80 â.. 90 â.. 100 â.. 110 â.. 120 â.. 130 â.. 140 â.. 150 â. 160 â.. 170 â.. 180 â.. 190 â.. 200 â.. 210 â.. 220 â.. 230 PING google.it (173.194.35.56) 56(84) bytes of data. â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â.â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..â..^C

Unregistered user Friday, October 18, 2013 3:06:44 PM

Anonym writes: There already is a package in the AUR: https://aur.archlinux.org/packages/prettyping-mercurial

Unregistered user Friday, October 18, 2013 5:32:40 PM

Konstantine Rybnikov writes: I want the same progress-bar for CPU load!

Unregistered user Friday, October 18, 2013 6:08:20 PM

Anonymous writes: This offers absolutely nothing over mtr

Denilson Figueiredo de SáCrazyTerabyte Friday, October 18, 2013 6:16:18 PM

Konstantine Rybnikov: you want https://github.com/creaktive/rainbarf

Unregistered user Saturday, October 19, 2013 8:13:25 AM

HL writes: Really like prettyping. :) Just 1 suggestion. Noticed that there will be no output if the ping results kept failing, for example hp.com: $ ping hp.com PING hp.com (15.201.225.10) 56(84) bytes of data. ^C --- hp.com ping statistics --- 5 packets transmitted, 0 received, 100% packet loss, time 4000ms If prettyping can show that ping has failed for each ping instead of hanging there, it will be more intuitive. liboping (http://verplant.org/liboping/) is able to indicate timeout, unlike the regular ping which simply kept quiet. For example: $ oping hp.com PING hpcomllb6.atlanta.hp.com (15.193.176.227) 56 bytes of data. echo reply from hpcomllb6.atlanta.hp.com (15.193.176.227): icmp_seq=1 timeout echo reply from hpcomllb6.atlanta.hp.com (15.193.176.227): icmp_seq=2 timeout echo reply from hpcomllb6.atlanta.hp.com (15.193.176.227): icmp_seq=3 timeout ^Cecho reply from hpcomllb6.atlanta.hp.com (15.193.176.227): icmp_seq=4 timeout --- hpcomllb6.atlanta.hp.com ping statistics --- 4 packets transmitted, 0 received, 100.00% packet loss, time 0.0ms

Unregistered user Saturday, October 19, 2013 11:19:10 AM

Anonyme writes: Fyi, I renamed the aur package 'prettyping-hg' in order to follow the naming guidelines: https://aur.archlinux.org/packages/prettyping-hg/

Denilson Figueiredo de SáCrazyTerabyte Saturday, October 19, 2013 1:37:29 PM

Originally posted by anonymous:

HL writes:

Really like prettyping. smile

Just 1 suggestion. Noticed that there will be no output if the ping results kept failing
[…]
liboping (http://verplant.org/liboping/) is able to indicate timeout
[…]



You can use liboping with prettyping! Just run it like this:

prettyping.sh --pingbin oping hp.com

Unregistered user Wednesday, October 30, 2013 12:44:16 AM

Anonymous writes: excellent work.

Unregistered user Wednesday, October 30, 2013 1:12:01 PM

JaXX writes: Works just a good with Mac OS X as well (if you ever wondered) Muito obrigado da França !

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies