System information
System Monitoring Utilities 45
As mentioned above, RRDtool is designed to work with data that change in time. The
ideal case is a sensor which repeatedly reads measured data (like temperature, speed
etc.) in constant periods of time, and then exports them in a given format. Such data
are perfectly ready for RRDtool, and it is easy to process them and create the desired
output.
Sometimes it is not possible to obtain the data automatically and regularly. Their for-
mat needs to be pre-processed before it is supplied to RRDtool, and often you need to
manipulate RRDtool even manually.
The following is a simple example of basic RRDtool usage. It illustrates all three im-
portant phases of the usual RRDtool workflow: creating a database, updating mea-
sured values, and viewing the output.
2.11.2 Simple Real Life Example
Suppose we want to collect and view information about the memory usage in the Lin-
ux system as it changes in time. To make the example more vivid, we measure the
currently free memory for the period of 40 seconds in 4-second intervals. During the
measuring, the three hungry applications that usually consume a lot of system memo-
ry have been started and closed: the Firefox Web browser, the Evolution e-mail client,
and the Eclipse development framework.
2.11.2.1 Collecting Data
RRDtool is very often used to measure and visualize network traffic. In such case,
Simple Network Management Protocol (SNMP) is used. This protocol can query net-
work devices for relevant values of their internal counters. Exactly these values are to
be stored with RRDtool. For more information on SNMP, see http://www.net-
snmp.org/.
Our situation is different - we need to obtain the data manually. A helper script
free_mem.sh repetitively reads the current state of free memory and writes it to
the standard output.
tux@mercury:~> cat free_mem.sh
INTERVAL=4
for steps in {1..10}
do
DATE=`date +%s`
FREEMEM=`free -b | grep "Mem" | awk '{ print $4 }'`