prettyping.sh - A better UI for watching ping responses
Friday, October 18, 2013 1:03:10 AM
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.
- 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)
- 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!
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)...
(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.
So I posted this on reddit, and in
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.