Search

gnuplot: a command-line driven interactive plotting program

February 25th, 2007 edited by ana

Entry submitted by Henryk Gerlach. DPOTD needs your help, please contribute !

A picture says more than a thousand words. Sometimes you have just plain data files and want to produce some nice plot out of them. If this does not happen on a regular basis you might use oocalc, but it is not so easy to automatize this using OpenOffice.org.
That’s were gnuplot comes into play.

Here is a real world example: sar is a utility to monitor the performance of your server (it should be covered here some other day!). A typically sar output for a not so busy server looks like this (in fact the data was sexed up as the average reveals):

Linux 2.6.9-023stab039.1-smp (host.domain.tld)     02/17/07

00:05:01          CPU     %user     %nice   %system   %iowait     %idle
01:35:01          all      0.19      0.00      0.03      0.00     99.78
01:45:01          all      0.35      0.00      0.26      0.04     99.35
01:55:01          all      0.41      0.00      0.66      0.00     98.93
02:05:01          all      0.48      0.00      1.19      0.03     98.31
02:15:01          all      0.13      0.00      5.03      0.01     94.83
02:25:01          all     10.34      0.00     20.46      0.00     69.20
02:35:01          all     40.35      0.00     20.79      0.00     38.86
02:45:01          all     15.32      0.00     10.61      0.01     74.06
02:55:01          all      0.08      0.00      0.17      0.00     99.74
03:05:01          all      0.05      0.00      0.01      0.00     99.94
03:15:01          all      0.01      9.39      0.25      9.90     80.45
03:25:01          all      0.00     14.11      0.30      2.79     82.80
03:35:01          all      1.07      0.00      0.04      0.02     98.87
03:45:01          all      0.00      0.00      0.00      0.00    100.00
03:55:01          all      0.05      0.00      0.01      0.00     99.95
04:05:01          all      0.04      0.00      0.00      0.00     99.96
04:15:01          all      0.05      0.00      0.01      0.00     99.95
04:25:01          all      0.01      0.00      0.01      0.02     99.96
04:35:01          all      0.57      0.00      0.25      0.00     99.18
04:45:01          all      0.00      0.00      0.01      0.00     99.99
04:55:01          all      0.01      0.00      0.00      0.00     99.99
Average:          all      0.14      0.18      0.06      0.20     99.43

by piping the above in through tail +4 | head -n -1 > data.txt into a file we clip of the first three and the last line which would confuse gnuplot.

Let’s start an interactive session of gnuplot by typing gnuplot on the command line. Type the following:

gnuplot> set xdata time
gnuplot> set timefmt "%H:%M:%S"
gnuplot> plot [*:*][0:100] “data.txt” using 1:3 with linespoints title “user”, \\
 > “data.txt” using 1:5 with linespoints title “system”, \\
 > “data.txt” using 1:6 with linespoints title “iowait”

In line 1 we tell gnuplot to interpret the x axis as a time axis.

Line 2 defines the time format of the x-axis (the first column of “data.txt”).

Finally line 3 produces the plot. The [*:*] tells gnuplot to chose the scale on the x-axis, as it seems fit, while [0:100] scales the y-axis between 0 and 100. Then “data.txt” using 1:3 with linespoints title “user”, tells gnuplot to take the first and the third column of “data.txt” and plot it with points connected by lines.

The title “user” produces a legend for the line.

You can use the help plot command to learn more about the many options to format your graph.
If we are happy with the output, we can save it to a “png”-file by changing the terminal

gnuplot> set terminal png

and defining an output-filename:

gnuplot> set output “stats.png”

Okay, this all seems still pretty manual, but here is how we can automatically generate the png-file in some bash script, too:

#!/bin/bash
#... generate data.txt with sar, head and tail.
OUTFILE="stat.png"
gnuplot <<END
set terminal png
set output "$OUTFILE"
set xdata time
set timefmt "%H:%M:%S"
plot [*:*][0:100] “data.txt” using 1:3 with linespoints title “user”, \\
 “data.txt” using 1:5 with linespoints title “system”, \\
 “data.txt” using 1:6 with linespoints title “iowait”
END

But gnuplot can do much more! It can print functions and 3d-data. Check out the tutorials.

Target Users:

Everyone who needs to generate graphs of data or functions, especially in an automated manner.

Tutorials:

Other packages doing similar things:

  • Grace (xmgr) is possibly as old as gnuplot. It has a bigger emphasize on the GUI and a less convenient console. If you prefer to point and click grace might be better for you.
  • RLPlot(covered earlier in debaday) comes with a fresh KDE-GUI, is easy to use and might be the right thing for you if you just want to produce a few graphs. But scripting seems hard; maybe it is possible to use the DCOP-interface.
  • If gnuplot does not scratch your itch, you might even try to program something yourself using scipy (covered earlier in debaday) or the gnu plotutils (a nice example is piechart)

License:

Although it’s called gnuplot, it is not licensed under the GPL, but some homebrewn License.

You can find gnuplots’s homepage at http://www.gnuplot.info/.

gnuplot is available in both Debian and Ubuntu.

Posted in Debian, Ubuntu | 13 Comments »

gtetrinet: multiplayer Tetris with some twists

February 21st, 2007 edited by ana

Entry submitted by Jan Hülsbergen. DPOTD needs your help, please contribute !

Gtetrinet is a small multiplayer clone of the classic puzzle-game Tetris implementing the tetrinet protocol. It features some original ideas about how multiplayer-Tetris can be handled and it has an active user community.

Multiplayer enhancements

The most unique thing about gtetrinet is the usage of ‘extras’ or ’special blocks’. Every time a player eliminates a line of his own field, one of the remaining blocks turns into an extra. When a line containing one or more extras is eliminated, those extras go to the inventory of the player, from where he/she can use them to harm other players or to aid himself. There are numerous extras which do everything from just eliminating or adding a single line to switching playing fields with an opponent of choice.

Also, the servers offer different ‘channels’, which have slightly different game-modes. For example, the tetrinet.de server has a #maps channel, in which the players do not start with an empty field but with some blocks/extras already there. Also, there is a #pure channel, in which the player can play a more classical multiplayer Tetris, without any extras at all.

User community

You don’t have to search for others to play against you, you can just connect to one of the public servers, for example tetrinet.org or tetrinet.de, which - as far as I can tell - has active players at any given time of day. And I have checked this for years now. ;-)

Servers

I already mentioned the public available tetrinet servers but there are more. You can also run your own server, using for example the package tetrinetx, which provides a nice tetrinet server implementation. There is also a package tetrinet-server, but it’s more primitive.

Also, there is a tetrinet-client package, which features a textmode client for the game.

Screenschots (click to get a larger image)

The Partyline

Ingame

Posted in Debian, Ubuntu | 1 Comment »

signing-party: complete toolkit for efficient key-signing!

February 18th, 2007 edited by lucas

Entry submitted by Thijs Kinkhorst. DPOTD needs your help, please contribute !

signing-party is a package combining a set of tools used in managing OpenPGP / GnuPG cryptographic keys. The most important tools in this package are used in preparing for or processing the results of gatherings to exchange key signatures, hence the name “signing-party”. If you are coming to FOSDEM next week-end, you should definitely have a look at it!

The two tools most interesting for the average user are gpg-key2ps and caff.

gpg-key2ps is used before attending a signing party. The script takes your public key and creates PostScript (PS) output that has your key fingerprint and userid’s nicely formatted on paper slips. The only thing left for you to do is to cut the paper.

When you arrive home after the signing event, you need a way to process all these paper slips. That’s where caff comes in. Give it a list of key-ID’s, and it will cycle through them, present you with the key’s fingerprint and asks you to confirm that it matches the paper you got.

The most important part about the signing process is that you verified the key owner’s real identity. However, caff adds additional security to that: it encrypts your signature on their key with their own key, and then mails it to them. It mails the signature for a specific user ID to the emailaddress on that user ID. This brings additional security: before the recipient can add your signature to their key, they must decrypt it with their private key, proving that they indeed have access to the key they claimed to be theirs. By mailing to the email addresses on the key user ID’s, it is also verified that the key owner can indeed read that address. All this you get for free - caff stands for “CA fire and forget”: you confirm that fingerprints match, and caff handles the rest.

Target Users:

  • Anyone signing OpenPGP keys.

Further reading:

The signing-party package is available in both Debian and Ubuntu. The caff tool is only available in Debian Etch and up, or in the package from backports.org.

Posted in Debian, Ubuntu | 2 Comments »

We need your help now !

February 15th, 2007 edited by lucas

Debian Package of the Day has now been alive again for more than two months. While it has been running quite well until know, we are concerned about the future, since we don’t have any article ready currently, and haven’t received a lot of contributions recently.

We really need *you* to submit articles about the packages you use. If you read Debaday, and haven’t submitted an article yet, you should really feel guilty now. :-) There are still tons of packages one could write about ! You can write about everything: games, sysadmin tools, cool end-user stuff, etc. Please read the Contribute page for more info. We are considering a switch from “two packages per week” to “one package per week” if we don’t receive more submissions soon.

Also, it would be great if we could recruit one or two other “editors”. The job is interesting (the goal is to answer submissions, providing ideas for improvements, and to adjust the last details), and you get to read all the articles in advance. You don’t need to be a native english speaker. Contact us if you are interested.

Posted in Debian, Ubuntu | 5 Comments »

screen: a console-base window manager on steroids

February 14th, 2007 edited by lucas

Entry submitted by Ico Doornekamp. DPOTD needs your help, please contribute !

GNU Screen is one of my all-time favorite Unix tools. According to the official documentation, Screen is a full-screen window manager that multiplexes a physical terminal between several processes.

So, what does that mean ? GNU Screen allows you to run multiple console based applications like editors, shells, IRC clients, newsreaders, etc, all through a single terminal. Screen allows you to switch between applications or layout multiple windows in a single terminal. One of the most nifty features is that the programs running under Screen’s control can be detached - this means they are still running, even though the actual terminal is closed. Later a new terminal can be reattached to a running screen session, even from another host!

Here’s a small demo of a typical Screen session, the true story of Bob the system administrator:

Bob connects to the server and starts a new screen session.

bob@desktop$ ssh bob@server
bob@server$ screen 

Screen displays its welcome message, and after hitting the Return key, a new shell is started.

Screen version 4.00.03 (FAU) 23-Oct-06

Copyright (c) 1993-2002 Juergen Weigert, Michael
Copyright (c) 1987 Oliver Laumann

This program is free software; you can redistribute
it and/or modify it under the terms of the GNU
General Public License as published by the Free
Software Foundation; either version 2, or
(at your option) any later version.

[Press Space for next page; Return to end.]

This shell is now running inside the Screen session. Bob starts his favorite editor…

bob@server:~$ su -
Password:
server:~# vi /etc/apache/httpd.conf 

… and does some heavy editing.

ProxyRequests On


Order deny,allow
Deny from all
Allow from 10.0.0. 

/etc/apache/httpd.conf 993,25 94%
– INSERT —

But then disaster strikes: The CEO comes in and trips over the uplink network cable, breaking the SSH session!

Disconnected;
connection lost. (Connection closed)

bob@desktop$  

Screen to the rescue! Bob starts a new SSH session to the server, and now runs Screen with the -x parameter.

bob@desktop$ ssh bob@server
bob@server$ screen -x 

Instead of starting a new session, screen now reattaches to the running screen session, and Bob finds his editor just the way he left it!

ProxyRequests On


Order deny,allow
Deny from all
Allow from 10.0.0. 

/etc/apache/httpd.conf 993,25 94%
– INSERT —

While editing, Bob decides he needs to check his mail. Instead of opening another SSH session to the server, he hits C-a C - that is, he types Ctrl-a and then ‘c’.

Screen now creates a new window, opening a new shell…

bob@server$ mutt  

…and Bob starts ‘mutt’, his mail user agent.

q:Quit d:Del u:Undel s:Save m:Mail r:Reply g:Gro
2 + Dec 22 Daniel Hirschi (0.6K) Implementing s
3 + Jan 06 Ricki Silversto (3.0K) Paycheck
4 + Jan 26 Roberto (1.0K) Read this!
5 C Jan 26 Michel Wraith (9.0K) RE: finished

—Mutt: ~/Maildir [Msgs:5 19K]—(threads/date)—(a)

With the keystrokes C-a 1 and C-a 2, Bob is now able to switch between vi and mutt, from the same console.

Time to go home. Bob hits C-a D, which will detach the current screen session from his terminal, and takes the bus home.

bob@server$ screen -x
[detached]
bob@desktop:$ logout 

After dinner, Bob decides to finish the job. From his home computer, he opens a new SSH session to the server, and reattaches to the running screen session:

bob@home$ ssh bob@server.company.com
bob@sever$ screen -x

The editor and mutt are still running, and Bob can now continue his work from home from the point he left.

ProxyRequests On


Order deny,allow
Deny from all
Allow from 10.0.0. 

/etc/apache/httpd.conf 993,25 94%
– INSERT —

Screen has been available for ages in both Debian and Ubuntu.

Posted in Debian, Ubuntu | 16 Comments »

« Previous Entries Next Entries »