Archive for the 'UNIX/Linux' Category

tmux: a replacement for gnu screen (updated)

I have recently discovered tmux, a replacement for the slightly aging gnu screen. The so called “terminal multiplexer” allows to open several terminals inside the same terminal window. Much like gnu screen, you can split the screen, resize the different parts etc. However, tmux allow the usage of 256 color terminals and is based upon a client server infrastructure. And before you ask, like screen, it will stay alive and run your favorite app until you reconnect to the session.

tmux example 5

It is part of the OpenBSD base distribution but will compile and run on a number of OS including Linux. Solaris, AIX, etc.

Update: for Mac OS users, it is available from macports.

Gnuplot : how to plot graphs from any UNIX machine

gnuplot is a plotting tool that I discovered in the 90s while being a student. The binary itself is around 1.2 MB only! People often forget about it and would rather use a spreadsheet program. Granted, a spreadsheet will probably give you prettier graphs but gnuplot is very handy to graph in an automated manner, with a very small footprint.

Let’s say you have a file containing measures like this (first column is the measure point, the second column contains the measured values):

bash-3.2$ more toto
1 4
2 6
3 8
4 7
5 12
6 5
7 9
8 3

Then to draw it, just fire gnuplot and type:

gnuplot> plot ‘./toto’ using 1:2 with lines;

And bang, you get this:

gnuplot simple example

1:2 means columns 1 and 2 and “with lines” means that you will use a line to join the points (there are plenty f options such as boxes, vectors, etc.).

You can also improve things a little by creating a command file containing this for instance:

set xlabel "The title of the X Axis"
set ylabel "The title of the y Axis"
set xrange [1:8]
set yrange [0:14]
plot './toto' using 1:2 with lines 4;

And execute:

gnuplot < commandfile

You will get this:

gnuplot better exampleThese are just tiny examples but by using command files, you can automate the generation of graphs very easily.

gnuplot has tons of options and is capable of much much more, checkout the official page!

For these examples, I have used the version of gnuplot provided my macports.

dstat for Linux: an alternative to sar/vmstat/iostst/etc.:

Written in python, dstat is a neat piece of tooling. It is a monitoring tool akin to sar, iostat, vmstat, etc. It allows you to measure a host of metrics. You can install it on any modern ubuntu box by typing “apt-get install dstat” (and I am sure it is available for any major distro).

By just typing dstat, you’ll get this (refreshed every second):

dstat1 output

There is quite some options:

Dstat options:
-c, --cpu              enable cpu stats
-C 0,3,total           include cpu0, cpu3 and total
-d, --disk             enable disk stats
-D total,hda           include hda and total
-g, --page             enable page stats
-i, --int              enable interrupt stats
-I 5,eth2              include int5 and interrupt used by eth2
-l, --load             enable load stats
-m, --mem              enable memory stats
-n, --net              enable network stats
-N eth1,total          include eth1 and total
-p, --proc             enable process stats
-s, --swap             enable swap stats
-S swap1,total         include swap1 and total
-t, --time             enable time/date output
-T, --epoch            enable time counter (seconds since epoch)
-y, --sys              enable system stats
--ipc                  enable ipc stats
--lock                 enable lock stats
--raw                  enable raw stats
--tcp                  enable tcp stats
--udp                  enable udp stats
--unix                 enable unix stats
-M stat1,stat2         enable external stats
--mods stat1,stat2
-a, --all              equals -cdngy (default)
-f, --full             expand -C, -D, -I, -N and -S discovery lists
-v, --vmstat           equals -pmgdsc -D total
--integer              show integer values
--nocolor              disable colors (implies --noupdate)
--noheaders            disable repetitive headers
--noupdate             disable intermediate updates
--output file          write CSV output to file

For example, “dstat -mp” will show memory and process related metrics with a refresh rate of one second (the delay is tweakable):

dstat example 2

Last but not least, you can export the output to CSV.

What I find especially neat is that you can combine any metrics with any other metrics (a bit more difficult to do with sar for instance).