Introduction
Every now and then, someone on the Cacti forums or the mailing list has a flash of inspiration, and suggests that Weathermap could make animations of it’s maps in some way. Here’s how to do that with any version of Weathermap.
There are two things users are asking for with this feature, and we’re only going to look at one of those here, because the other one is hard :-)
RRDtool lets you fetch data from a point in the past, and potentially Weathermap could do that to produce a map of how the world looked at that time. If you do this for several different times, then you have an animation. There are a few limitations here:
- RRDtool also averages older data, and typically stores less time-resolution as you go back in time. The averaging makes it hard to compare last week’s data to today’s, unless you resize the RRAs in your .rrd file to store more data at ‘full’ resolution – this week is 5-minutes, and last week may be hourly averages, smoothing out the spikes. This makes the files larger, and rrdtool has to work harder to update them.
- To produce the animation, we’d have to effectively run Weathermap once for each frame. To get a week’s worth of animation, this is a pretty slow process.
- Weathermap allows for many other data sources besides RRD files. Having a feature that only works with one kind of data feels wrong to me.
On the other hand, if you build up a history of the images that Weathermap produces anyway, then you can make animations from any data, and not have to have bigger (slower) RRD files. You don’t need any extra runs of the Weathermap process either. With a little bit of scripting, you even get a (roughly) fixed-size disk usage for the images, just like your RRD files.
The Basic Idea
Collect your images
Before you can animate anything, you need to collect the images that will form the frames of your animation. In Unix, the easiest way to do this, is to use the built-in scheduler cron along with a little shell-scripting. Here’s copy-frames.sh:
#!/bin/sh
SRC_MAP="/usr/local/www/cacti/plugins/weathermap/output/weathermap_1.png"
HISTORY_DIR="/var/tmp/my_weathermap_frames"
DATE=`date '+%y%m%d%H%M'`
cp $SRC_MAP $HISTORY_DIR/map_$DATE.png
find $HISTORY_DIR -name '*.png' -mtime +7 -type f -exec rm {} \;
So by running this script (modified to suit the paths for your maps) every so often from cron, you will build up a collection of PNG files named map_200612251100.png and so on. By using this date format, your files will be in time order when they are sorted alphabetically, which is useful later.
The last line deletes all PNG files older than 7 days from the ‘history’ directory, so that we don’t just fill up the disk with old images. Be sure that the paths are correct, or you will likely delete things you didn’t mean to!
If you use the crontab -e command to edit a user crontab file, then something like
*/5 * * * * /path/to/the/copy-frames.sh
will do the trick.
Make your animation
There are several tools that can help with making an animation from a collection of still images, but Imagemagick is available for most *nix and for Win32, and does a good job. If you don’t mind getting your hands dirty(er), then ffmpeg or mencoder may also help you.
The Imagemagick convert command makes this job very easy. Assuming you have all of your frames of animation stored by themselves, in PNG format, then
convert -delay 20 -loop 0 *.png output.gif
will produce a (probably huge) animated GIF, and
convert *.png output.mpg
produces a (not so huge) MPEG-1 video file.
If your input frames are JPEG or GIF2, then just change *.png to *.gif or *.jpg as appropriate.
Because you used the date format from before, the files are automatically in the right order to make the correct animation, rather than random jumbled frames.
Small Improvements
Use Gradient SCALEs
The SCALE lines in your map config are what decides the colour of links, based on percentage utilisation, which in turn is calculated from the BANDWIDTH for each link.
Using the default SCALE settings in Weathermap, you have percentage bands where the colour remains the same. with contrasting colours in the bands on either side. This is good for a static map, as it makes it easy to highlight problems — the link goes bright red.
When you want to animate the link though, it means that over time the link will flash from one colour to another, even though the actual usage change could be as small as 1%. With gradient SCALEs, a 1% change in usage makes a small change in the colour that is used:
SCALE 0 10 0 0 0 0 0 255
That’s start percentage, end percentage, RGB for the start colour (black), and RGB for the end colour (blue).
With SCALE lines like this, as the percentage utilisation rises from 0 to 10%, the colour gradually changes from black to pure blue. You also need fewer SCALE lines to define a wider range of colour change, as a side-benefit.
If you data flows are bursty, then this will make less difference, but if you have that typical “starts to get busy at 8AM and lasts until 6PM” pattern, then gradients will make a much nicer animation.
The secret “Bulge” mode
A feature that has been hidden inside Weathermap for quite a few versions is the ‘bulge’ mode. This takes the percentage utilisation and uses it to vary the width of the link between a thin line (0%) and it’s normal1 WIDTH (100%). When animated, this gives your network diagram a bit of life as data flows around.
This feature has been available since around version 0.6 in the command-line tool, using the --bulge option.
Since 0.9, it is also available by adding a SET command to your map config file:
SET link_bulge 1
An Example
I’ve attached a some example animations to this article. They are using a week’s worth of live network data, but applied to a fictitious network. The first example is using normal weathermap SCALEs. Note the “flickering”. The second uses gradients, to show the improvement. The last one uses gradients and ‘bulge’, for the full Cinemascope effect.
Is it useful?
Animated Weathermaps sound like a cool idea, and look kind of cool, especially if you are watching something like a network roll-out — one user has made AVI animations of network activity during the weekend of a huge LAN Party, which are actually interesting to watch.
As a diagnostic tool, I’m not sure how useful they really are. See that brief yellow flash? That was a big blob of something-or-other a few days ago.
They probably will score points with your boss though. If you do get that big raise, remember to think of me…
1 Actually, it’s a little bit more than the normal WIDTH.
2 Weathermap 0.9 supports output of JPEG and GIF in addition to the “traditional” PNG.
| Attachment | Size |
|---|---|
| anim1.mpg | 1.6 MB |
| anim2.mpg | 1.6 MB |
| anim3.mpg | 1.6 MB |
April 11, 2007 - 11:28pm
One note on the mpg/gif generation, the "convert" tool can take a lot of memory as its processing, which can hinder system performance... so don't run it too regular.
April 3, 2007 - 5:53pm
Just corrected an error - the bulging parameter is called 'link_bulge' in 0.9, not 'bulge_mode'.